OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
| 3 # All rights reserved. |
| 4 # |
| 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- |
| 11 # lowing conditions: |
| 12 # |
| 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. |
| 15 # |
| 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 |
| 22 # IN THE SOFTWARE. |
| 23 |
| 24 """ |
| 25 Some unit tests for the SDBConnection |
| 26 """ |
| 27 |
| 28 import unittest |
| 29 import time |
| 30 from boto.sdb.connection import SDBConnection |
| 31 from boto.exception import SDBResponseError |
| 32 |
| 33 class SDBConnectionTest (unittest.TestCase): |
| 34 sdb = True |
| 35 |
| 36 def test_1_basic(self): |
| 37 print '--- running SDBConnection tests ---' |
| 38 c = SDBConnection() |
| 39 rs = c.get_all_domains() |
| 40 num_domains = len(rs) |
| 41 |
| 42 # try illegal name |
| 43 try: |
| 44 domain = c.create_domain('bad:domain:name') |
| 45 except SDBResponseError: |
| 46 pass |
| 47 |
| 48 # now create one that should work and should be unique (i.e. a new one) |
| 49 domain_name = 'test%d' % int(time.time()) |
| 50 domain = c.create_domain(domain_name) |
| 51 rs = c.get_all_domains() |
| 52 assert len(rs) == num_domains + 1 |
| 53 |
| 54 # now let's a couple of items and attributes |
| 55 item_1 = 'item1' |
| 56 same_value = 'same_value' |
| 57 attrs_1 = {'name1' : same_value, 'name2' : 'diff_value_1'} |
| 58 domain.put_attributes(item_1, attrs_1) |
| 59 item_2 = 'item2' |
| 60 attrs_2 = {'name1' : same_value, 'name2' : 'diff_value_2'} |
| 61 domain.put_attributes(item_2, attrs_2) |
| 62 |
| 63 # try to get the attributes and see if they match |
| 64 item = domain.get_attributes(item_1, consistent_read=True) |
| 65 assert len(item.keys()) == len(attrs_1.keys()) |
| 66 assert item['name1'] == attrs_1['name1'] |
| 67 assert item['name2'] == attrs_1['name2'] |
| 68 |
| 69 # try a search or two |
| 70 query = 'select * from %s where name1="%s"' % (domain_name, same_value) |
| 71 rs = domain.select(query, consistent_read=True) |
| 72 n = 0 |
| 73 for item in rs: |
| 74 n += 1 |
| 75 assert n == 2 |
| 76 query = 'select * from %s where name2="diff_value_2"' % domain_name |
| 77 rs = domain.select(query, consistent_read=True) |
| 78 n = 0 |
| 79 for item in rs: |
| 80 n += 1 |
| 81 assert n == 1 |
| 82 |
| 83 # delete all attributes associated with item_1 |
| 84 stat = domain.delete_attributes(item_1) |
| 85 assert stat |
| 86 |
| 87 # now try a batch put operation on the domain |
| 88 item3 = {'name3_1' : 'value3_1', |
| 89 'name3_2' : 'value3_2', |
| 90 'name3_3' : ['value3_3_1', 'value3_3_2']} |
| 91 |
| 92 item4 = {'name4_1' : 'value4_1', |
| 93 'name4_2' : ['value4_2_1', 'value4_2_2'], |
| 94 'name4_3' : 'value4_3'} |
| 95 items = {'item3' : item3, 'item4' : item4} |
| 96 domain.batch_put_attributes(items) |
| 97 |
| 98 item = domain.get_attributes('item3', consistent_read=True) |
| 99 assert item['name3_2'] == 'value3_2' |
| 100 |
| 101 # now try a batch delete operation (variation #1) |
| 102 items = {'item3' : item3} |
| 103 stat = domain.batch_delete_attributes(items) |
| 104 |
| 105 item = domain.get_attributes('item3', consistent_read=True) |
| 106 assert not item |
| 107 |
| 108 # now try a batch delete operation (variation #2) |
| 109 stat = domain.batch_delete_attributes({'item4' : None}) |
| 110 |
| 111 item = domain.get_attributes('item4', consistent_read=True) |
| 112 assert not item |
| 113 |
| 114 # now delete the domain |
| 115 stat = c.delete_domain(domain) |
| 116 assert stat |
| 117 |
| 118 print '--- tests completed ---' |
| 119 |
OLD | NEW |