| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2010 Chris Moyer http://coredumped.org/ | |
| 2 # | |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | |
| 4 # copy of this software and associated documentation files (the | |
| 5 # "Software"), to deal in the Software without restriction, including | |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | |
| 9 # lowing conditions: | |
| 10 # | |
| 11 # The above copyright notice and this permission notice shall be included | |
| 12 # in all copies or substantial portions of the Software. | |
| 13 # | |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
| 20 # IN THE SOFTWARE. | |
| 21 # | |
| 22 from boto.sdb.db.property import ListProperty | |
| 23 from boto.sdb.db.model import Model | |
| 24 import time | |
| 25 | |
| 26 class SimpleListModel(Model): | |
| 27 """Test the List Property""" | |
| 28 nums = ListProperty(int) | |
| 29 strs = ListProperty(str) | |
| 30 | |
| 31 class TestLists(object): | |
| 32 """Test the List property""" | |
| 33 | |
| 34 def setup_class(cls): | |
| 35 """Setup this class""" | |
| 36 cls.objs = [] | |
| 37 | |
| 38 def teardown_class(cls): | |
| 39 """Remove our objects""" | |
| 40 for o in cls.objs: | |
| 41 try: | |
| 42 o.delete() | |
| 43 except: | |
| 44 pass | |
| 45 | |
| 46 def test_list_order(self): | |
| 47 """Testing the order of lists""" | |
| 48 t = SimpleListModel() | |
| 49 t.nums = [5,4,1,3,2] | |
| 50 t.strs = ["B", "C", "A", "D", "Foo"] | |
| 51 t.put() | |
| 52 self.objs.append(t) | |
| 53 time.sleep(3) | |
| 54 t = SimpleListModel.get_by_id(t.id) | |
| 55 assert(t.nums == [5,4,1,3,2]) | |
| 56 assert(t.strs == ["B", "C", "A", "D", "Foo"]) | |
| 57 | |
| 58 def test_old_compat(self): | |
| 59 """Testing to make sure the old method of encoding lists will still retu
rn results""" | |
| 60 t = SimpleListModel() | |
| 61 t.put() | |
| 62 self.objs.append(t) | |
| 63 time.sleep(3) | |
| 64 item = t._get_raw_item() | |
| 65 item['strs'] = ["A", "B", "C"] | |
| 66 item.save() | |
| 67 time.sleep(3) | |
| 68 t = SimpleListModel.get_by_id(t.id) | |
| 69 i1 = item['strs'] | |
| 70 i1.sort() | |
| 71 i2 = t.strs | |
| 72 i2.sort() | |
| 73 assert(i1 == i2) | |
| 74 | |
| 75 def test_query_equals(self): | |
| 76 """We noticed a slight problem with querying, since the query uses the s
ame encoder, | |
| 77 it was asserting that the value was at the same position in the list, no
t just "in" the list""" | |
| 78 t = SimpleListModel() | |
| 79 t.strs = ["Bizzle", "Bar"] | |
| 80 t.put() | |
| 81 self.objs.append(t) | |
| 82 time.sleep(3) | |
| 83 assert(SimpleListModel.find(strs="Bizzle").count() == 1) | |
| 84 assert(SimpleListModel.find(strs="Bar").count() == 1) | |
| 85 assert(SimpleListModel.find(strs=["Bar","Bizzle"]).count() == 1) | |
| 86 | |
| 87 def test_query_not_equals(self): | |
| 88 """Test a not equal filter""" | |
| 89 t = SimpleListModel() | |
| 90 t.strs = ["Fizzle"] | |
| 91 t.put() | |
| 92 self.objs.append(t) | |
| 93 time.sleep(3) | |
| 94 print SimpleListModel.all().filter("strs !=", "Fizzle").get_query() | |
| 95 for tt in SimpleListModel.all().filter("strs !=", "Fizzle"): | |
| 96 print tt.strs | |
| 97 assert("Fizzle" not in tt.strs) | |
| OLD | NEW |