1
from boto.sdb.persist.object import SDBObject
2
from boto.sdb.persist.property import StringProperty, PositiveIntegerProperty, IntegerProperty
3
from boto.sdb.persist.property import BooleanProperty, DateTimeProperty, S3KeyProperty
4
from boto.sdb.persist.property import ObjectProperty, StringListProperty
5
from boto.sdb.persist.property import PositiveIntegerListProperty, BooleanListProperty, ObjectListProperty
6
from boto.sdb.persist import Manager
7
from datetime import datetime
11
# This will eventually be moved to the boto.tests module and become a real unit test
12
# but for now it will live here. It shows examples of each of the Property types in
13
# use and tests the basic operations.
15
class TestScalar(SDBObject):
17
name = StringProperty()
18
description = StringProperty()
19
size = PositiveIntegerProperty()
20
offset = IntegerProperty()
21
foo = BooleanProperty()
22
date = DateTimeProperty()
23
file = S3KeyProperty()
25
class TestRef(SDBObject):
27
name = StringProperty()
28
ref = ObjectProperty(ref_class=TestScalar)
30
class TestSubClass1(TestRef):
32
answer = PositiveIntegerProperty()
34
class TestSubClass2(TestScalar):
36
flag = BooleanProperty()
38
class TestList(SDBObject):
40
names = StringListProperty()
41
numbers = PositiveIntegerListProperty()
42
bools = BooleanListProperty()
43
objects = ObjectListProperty(ref_class=TestScalar)
48
s.description = 'This is foo'
52
s.date = datetime.now()
59
rs = TestScalar.find(name=ref_name)
67
s.description = 'This is bar'
70
s.date = datetime.now()
74
def test4(ref1, ref2):
76
s.names.append(ref1.name)
77
s.names.append(ref2.name)
78
s.numbers.append(ref1.size)
79
s.numbers.append(ref2.size)
80
s.bools.append(ref1.foo)
81
s.bools.append(ref2.foo)
82
s.objects.append(ref1)
83
s.objects.append(ref2)
92
# test out free form attribute
93
s.fiddlefaddle = 'this is fiddlefaddle'
94
s._fiddlefaddle = 'this is not fiddlefaddle'
100
s.description = 'This is fie'
104
s.date = datetime.now()
109
def test(domain_name):
110
print 'Initialize the Persistance system'
111
Manager.DefaultDomainName = domain_name
114
# now create a new instance and read the saved data from SDB
115
print 'Now sleep to wait for things to converge'
117
print 'Now lookup the object and compare the fields'
118
s2 = TestScalar(s1.id)
119
assert s1.name == s2.name
120
assert s1.description == s2.description
121
assert s1.size == s2.size
122
assert s1.offset == s2.offset
123
assert s1.foo == s2.foo
124
#assert s1.date == s2.date
134
domain = s5._manager.domain
135
item1 = domain.get_item(s1.id)
136
item2 = domain.get_item(s2.id)
137
item3 = domain.get_item(s3.id)
138
item4 = domain.get_item(s4.id)
139
item5 = domain.get_item(s5.id)
140
item6 = domain.get_item(s6.id)
141
return [(s1, item1), (s2, item2), (s3, item3), (s4, item4), (s5, item5), (s6, item6)]