def test_load_returns_none_if_no_item_is_found(self): self.manager.get.return_value = () field = ReferenceTargetField(target_cls=lambda: self.modelMockCls, ) val = random.randint(0, 1000) saved = field._load(val) self.assertIsNone(saved.value) self.manager.get.assert_called_once_with({'_id': val})
def test_load_creates_a_cached_obj(self): self.manager.get.return_value = () field = ReferenceTargetField(target_cls=lambda: self.modelMockCls, ) val = random.randint(0, 1000) saved = field._load(val) self.assertTrue(isinstance(saved, CachedObj))
def test_load_returns_found_item(self): result = random.randint(0, 1000) target_field = "target" self.manager.get.return_value = [result] field = ReferenceTargetField(target_cls=lambda: self.modelMockCls, target_field=target_field) val = random.randint(0, 1000) saved = field._load(val) self.assertEqual(saved.value, result) self.manager.get.assert_called_once_with({target_field: val})