Skip to content

Commit 0cf6569

Browse files
author
Drew Blas
committed
Added information & stats tests
1 parent 37471d6 commit 0cf6569

File tree

4 files changed

+134
-1
lines changed

4 files changed

+134
-1
lines changed

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
* Use a better XML parser (and be consistent)
2+
* Rename Base to something else (probably Mailer): Nothing else actually inherits from Base, so that is a very poor naming convention. I intend to change it in the future
3+
* Integer responses should probably be cast to ints instead of left as strings

lib/aws/ses/addresses.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def result
5353
[]
5454
end
5555
end
56+
memoized :result
5657
end
5758

5859
class VerifyEmailAddressResponse < AWS::SES::Response

lib/aws/ses/info.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,33 @@ class GetSendQuotaResponse < AWS::SES::Response
2121
def result
2222
parsed['GetSendQuotaResult']
2323
end
24+
25+
def sent_last_24_hours
26+
result['SentLast24Hours']
27+
end
28+
29+
def max_24_hour_send
30+
result['Max24HourSend']
31+
end
32+
33+
def max_send_rate
34+
result['MaxSendRate']
35+
end
2436
end
2537

2638
class GetSendStatisticsResponse < AWS::SES::Response
2739
def result
28-
parsed['GetSendStatisticsResponse']
40+
if members = parsed['GetSendStatisticsResult']['SendDataPoints']
41+
[members['member']].flatten
42+
else
43+
[]
44+
end
45+
end
46+
47+
memoized :result
48+
49+
def data_points
50+
result
2951
end
3052
end
3153
end

test/info_test.rb

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
require File.dirname(__FILE__) + '/helper'
2+
3+
class InfoTest < Test::Unit::TestCase
4+
context 'getting send quota' do
5+
setup do
6+
@base = generate_base
7+
end
8+
9+
should 'return the correct response on success' do
10+
mock_connection(@base, :body => %{
11+
<GetSendQuotaResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
12+
<GetSendQuotaResult>
13+
<SentLast24Hours>0.0</SentLast24Hours>
14+
<Max24HourSend>1000.0</Max24HourSend>
15+
<MaxSendRate>1.0</MaxSendRate>
16+
</GetSendQuotaResult>
17+
<ResponseMetadata>
18+
<RequestId>abc-123</RequestId>
19+
</ResponseMetadata>
20+
</GetSendQuotaResponse>
21+
})
22+
23+
result = @base.quota
24+
assert result.success?
25+
assert_equal 'abc-123', result.request_id
26+
assert_equal '0.0', result.sent_last_24_hours
27+
assert_equal '1000.0', result.max_24_hour_send
28+
assert_equal '1.0', result.max_send_rate
29+
end
30+
end
31+
32+
context 'getting send statistics' do
33+
setup do
34+
@base = generate_base
35+
end
36+
37+
should 'return the correct response on success' do
38+
mock_connection(@base, :body => %{
39+
<GetSendStatisticsResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
40+
<GetSendStatisticsResult>
41+
<SendDataPoints>
42+
<member>
43+
<DeliveryAttempts>3</DeliveryAttempts>
44+
<Timestamp>2011-01-31T15:31:00Z</Timestamp>
45+
<Rejects>2</Rejects>
46+
<Bounces>4</Bounces>
47+
<Complaints>1</Complaints>
48+
</member>
49+
<member>
50+
<DeliveryAttempts>3</DeliveryAttempts>
51+
<Timestamp>2011-01-31T16:01:00Z</Timestamp>
52+
<Rejects>0</Rejects>
53+
<Bounces>0</Bounces>
54+
<Complaints>0</Complaints>
55+
</member>
56+
<member>
57+
<DeliveryAttempts>1</DeliveryAttempts>
58+
<Timestamp>2011-01-26T16:31:00Z</Timestamp>
59+
<Rejects>0</Rejects>
60+
<Bounces>0</Bounces>
61+
<Complaints>0</Complaints>
62+
</member>
63+
</SendDataPoints>
64+
</GetSendStatisticsResult>
65+
<ResponseMetadata>
66+
<RequestId>abc-123</RequestId>
67+
</ResponseMetadata>
68+
</GetSendStatisticsResponse>
69+
})
70+
71+
result = @base.statistics
72+
73+
assert result.success?
74+
assert_equal 'abc-123', result.request_id
75+
76+
assert_equal 3, result.data_points.size
77+
78+
d = result.data_points.first
79+
80+
assert_equal '2', d['Rejects']
81+
assert_equal '3', d['DeliveryAttempts']
82+
assert_equal '4', d['Bounces']
83+
assert_equal '1', d['Complaints']
84+
end
85+
end
86+
87+
88+
context 'deleting a verified addressess' do
89+
setup do
90+
@base = generate_base
91+
end
92+
93+
should 'return the correct response on success' do
94+
mock_connection(@base, :body => %{
95+
<DeleteVerifiedEmailAddressResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
96+
<ResponseMetadata>
97+
<RequestId>abc-123</RequestId>
98+
</ResponseMetadata>
99+
</DeleteVerifiedEmailAddressResponse>
100+
})
101+
102+
result = @base.addresses.delete('[email protected]')
103+
104+
assert result.success?
105+
assert_equal 'abc-123', result.request_id
106+
end
107+
end
108+
end

0 commit comments

Comments
 (0)