3
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
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 SDBConnection
30
from boto.sdb.connection import SDBConnection
31
from boto.exception import SDBResponseError
33
class SDBConnectionTest (unittest.TestCase):
35
def test_1_basic(self):
36
print '--- running SDBConnection tests ---'
38
rs = c.get_all_domains()
43
domain = c.create_domain('bad:domain:name')
44
except SDBResponseError:
47
# now create one that should work and should be unique (i.e. a new one)
48
domain_name = 'test%d' % int(time.time())
49
domain = c.create_domain(domain_name)
50
rs = c.get_all_domains()
51
assert len(rs) == num_domains+1
53
# now let's a couple of items and attributes
55
same_value = 'same_value'
56
attrs_1 = {'name1' : same_value, 'name2' : 'diff_value_1'}
57
domain.put_attributes(item_1, attrs_1)
59
attrs_2 = {'name1' : same_value, 'name2' : 'diff_value_2'}
60
domain.put_attributes(item_2, attrs_2)
63
# try to get the attributes and see if they match
64
item = domain.get_attributes(item_1)
65
assert len(item.keys()) == len(attrs_1.keys())
66
assert item['name1'] == attrs_1['name1']
67
assert item['name2'] == attrs_1['name2']
70
rs = domain.query("['name1'='%s']" % same_value)
75
rs = domain.query("['name2'='diff_value_2']")
81
# delete all attributes associated with item_1
82
stat = domain.delete_attributes(item_1)
85
# now try a batch put operation on the domain
86
item3 = {'name3_1' : 'value3_1',
87
'name3_2' : 'value3_2',
88
'name3_3' : ['value3_3_1', 'value3_3_2']}
90
item4 = {'name4_1' : 'value4_1',
91
'name4_2' : ['value4_2_1', 'value4_2_2'],
92
'name4_3' : 'value4_3'}
93
items = {'item3' : item3, 'item4' : item4}
94
domain.batch_put_attributes(items)
96
item = domain.get_attributes('item3')
97
assert item['name3_2'] == 'value3_2'
99
# now delete the domain
100
stat = c.delete_domain(domain)
103
print '--- tests completed ---'