1
# Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/
2
# Copyright (c) 2010, Eucalyptus Systems, Inc.
5
# Permission is hereby granted, free of charge, to any person obtaining a
6
# copy of this software and associated documentation files (the
7
# "Software"), to deal in the Software without restriction, including
8
# without limitation the rights to use, copy, modify, merge, publish, dis-
9
# tribute, sublicense, and/or sell copies of the Software, and to permit
10
# persons to whom the Software is furnished to do so, subject to the fol-
13
# The above copyright notice and this permission notice shall be included
14
# in all copies or substantial portions of the Software.
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
18
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
Some unit tests for the SQSConnection
30
from boto.sqs.connection import SQSConnection
31
from boto.sqs.message import MHMessage
32
from boto.exception import SQSError
34
class SQSConnectionTest (unittest.TestCase):
36
def test_1_basic(self):
37
print '--- running SQSConnection tests ---'
39
rs = c.get_all_queues()
46
queue = c.create_queue('bad*queue*name')
47
self.fail('queue name should have been bad')
51
# now create one that should work and should be unique (i.e. a new one)
52
queue_name = 'test%d' % int(time.time())
54
queue = c.create_queue(queue_name, timeout)
56
rs = c.get_all_queues()
60
assert i == num_queues+1
61
assert queue.count_slow() == 0
63
# check the visibility timeout
64
t = queue.get_timeout()
65
assert t == timeout, '%d != %d' % (t, timeout)
67
# now try to get queue attributes
68
a = q.get_attributes()
69
assert a.has_key('ApproximateNumberOfMessages')
70
assert a.has_key('VisibilityTimeout')
71
a = q.get_attributes('ApproximateNumberOfMessages')
72
assert a.has_key('ApproximateNumberOfMessages')
73
assert not a.has_key('VisibilityTimeout')
74
a = q.get_attributes('VisibilityTimeout')
75
assert not a.has_key('ApproximateNumberOfMessages')
76
assert a.has_key('VisibilityTimeout')
78
# now change the visibility timeout
80
queue.set_timeout(timeout)
82
t = queue.get_timeout()
83
assert t == timeout, '%d != %d' % (t, timeout)
86
message_body = 'This is a test\n'
87
message = queue.new_message(message_body)
90
assert queue.count_slow() == 1
93
# now read the message from the queue with a 10 second timeout
94
message = queue.read(visibility_timeout=10)
96
assert message.get_body() == message_body
98
# now immediately try another read, shouldn't find anything
99
message = queue.read()
100
assert message == None
102
# now wait 30 seconds and try again
104
message = queue.read()
107
# now delete the message
108
queue.delete_message(message)
110
assert queue.count_slow() == 0
112
# create another queue so we can test force deletion
113
# we will also test MHMessage with this queue
114
queue_name = 'test%d' % int(time.time())
116
queue = c.create_queue(queue_name, timeout)
117
queue.set_message_class(MHMessage)
120
# now add a couple of messages
121
message = queue.new_message()
122
message['foo'] = 'bar'
124
message_body = {'fie' : 'baz', 'foo' : 'bar'}
125
message = queue.new_message(body=message_body)
130
assert m['foo'] == 'bar'
132
# now delete that queue and messages
133
c.delete_queue(queue, True)
135
print '--- tests completed ---'