~jk0/nova/xs-ipv6

« back to all changes in this revision

Viewing changes to vendor/boto/boto/tests/test_sdbconnection.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
 
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
 
 
35
    def test_1_basic(self):
 
36
        print '--- running SDBConnection tests ---'
 
37
        c = SDBConnection()
 
38
        rs = c.get_all_domains()
 
39
        num_domains = len(rs)
 
40
    
 
41
        # try illegal name
 
42
        try:
 
43
            domain = c.create_domain('bad:domain:name')
 
44
        except SDBResponseError:
 
45
            pass
 
46
        
 
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
 
52
 
 
53
        # now let's a couple of items and attributes
 
54
        item_1 = 'item1'
 
55
        same_value = 'same_value'
 
56
        attrs_1 = {'name1' : same_value, 'name2' : 'diff_value_1'}
 
57
        domain.put_attributes(item_1, attrs_1)
 
58
        item_2 = 'item2'
 
59
        attrs_2 = {'name1' : same_value, 'name2' : 'diff_value_2'}
 
60
        domain.put_attributes(item_2, attrs_2)
 
61
        time.sleep(10)
 
62
 
 
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']
 
68
 
 
69
        # try a search or two
 
70
        rs = domain.query("['name1'='%s']" % same_value)
 
71
        n = 0
 
72
        for item in rs:
 
73
            n += 1
 
74
        assert n == 2
 
75
        rs = domain.query("['name2'='diff_value_2']")
 
76
        n = 0
 
77
        for item in rs:
 
78
            n += 1
 
79
        assert n == 1
 
80
 
 
81
        # delete all attributes associated with item_1
 
82
        stat = domain.delete_attributes(item_1)
 
83
        assert stat
 
84
 
 
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']}
 
89
 
 
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)
 
95
        time.sleep(10)
 
96
        item = domain.get_attributes('item3')
 
97
        assert item['name3_2'] == 'value3_2'
 
98
        
 
99
        # now delete the domain
 
100
        stat = c.delete_domain(domain)
 
101
        assert stat
 
102
 
 
103
        print '--- tests completed ---'
 
104