def test_serialize_no_value_transformer_item_does_notexists(self): field = ReferenceTargetField(target_cls=lambda: self.modelMockCls, ) self.manager.exists.return_value = False val = random.randint(0, 1000) with self.assertRaises(NotFoundError): field._serialize(val)
def test_serialize_no_value_transformer_item_exists(self): field = ReferenceTargetField(target_cls=self.modelMockCls, ) self.manager.exists.return_value = True val = random.randint(0, 1000) serialized = field._serialize(val) self.assertEqual(val, serialized) self.manager.exists.assert_called_once_with({'_id': val})
def test_serialize_no_value_transformer_no_exists(self): field = ReferenceTargetField(target_cls=self.modelMockCls, validate_exists=False) val = random.randint(0, 1000) serialized = field._serialize(val) self.assertEqual(val, serialized) self.manager.exists.assert_not_called()