def test_match__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.match({'arg1': 1})
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_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_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)