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 = sorted(item['strs']) |
| 70 i2 = t.strs |
| 71 i2.sort() |
| 72 assert(i1 == i2) |
| 73 |
| 74 def test_query_equals(self): |
| 75 """We noticed a slight problem with querying, since the query uses the s
ame encoder, |
| 76 it was asserting that the value was at the same position in the list, no
t just "in" the list""" |
| 77 t = SimpleListModel() |
| 78 t.strs = ["Bizzle", "Bar"] |
| 79 t.put() |
| 80 self.objs.append(t) |
| 81 time.sleep(3) |
| 82 assert(SimpleListModel.find(strs="Bizzle").count() == 1) |
| 83 assert(SimpleListModel.find(strs="Bar").count() == 1) |
| 84 assert(SimpleListModel.find(strs=["Bar", "Bizzle"]).count() == 1) |
| 85 |
| 86 def test_query_not_equals(self): |
| 87 """Test a not equal filter""" |
| 88 t = SimpleListModel() |
| 89 t.strs = ["Fizzle"] |
| 90 t.put() |
| 91 self.objs.append(t) |
| 92 time.sleep(3) |
| 93 print SimpleListModel.all().filter("strs !=", "Fizzle").get_query() |
| 94 for tt in SimpleListModel.all().filter("strs !=", "Fizzle"): |
| 95 print tt.strs |
| 96 assert("Fizzle" not in tt.strs) |
OLD | NEW |