def test_len(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) for i in range(1, 10): obj = MyClass(i) cache.add(obj) self.assertEqual(len(cache), i)
def test_match(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj = MyClass(1, 2) cache.add(obj) result = cache.match({'arg1': 1}) self.assertEqual(obj, result)
def test_find__not_found(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj = MyClass(1, 2) cache.add(obj) result = cache.find(2) self.assertIsNone(result)
def test_find(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj = MyClass(1, 2) cache.add(obj) result = cache.find(1) self.assertEqual(obj, result)
def test_match__not_match(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj = MyClass(1, 2) cache.add(obj) result = cache.match({'arg1': 2}) self.assertIsNone(result)
def test_get__returns_default_for_no_match(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj = MyClass() default = MyClass(1, 2) cache.add(obj) result = cache.get('arg1', None, default) self.assertEqual(default, result)
def test_get(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj = MyClass(1, 2) default = MyClass() cache.add(obj) result = cache.get('arg1', 1, default) self.assertEqual(obj, result)
def test_find__multiple_results(self): lookup_fields = ('arg1',) cache = ObjectCache(lookup_fields) obj1 = MyClass(1, 2) obj2 = MyClass(1, 3) cache.add(obj1) cache.add(obj2) with self.assertRaises(cache.multiple_objects_error): cache.find(1)
def test_match__value_pair(self): lookup_fields = ('arg1', ('arg2', 'arg3')) cache = ObjectCache(lookup_fields) obj1 = MyClass(1, 2, 3) obj2 = MyClass(1, 2, 4) obj3 = MyClass(1, 4, 3) cache.add(obj1) cache.add(obj2) cache.add(obj3) result = cache.match({'arg1': 2, 'arg2': 2, 'arg3': 3}) self.assertEqual(obj1, result)