コード例 #1
0
    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)
コード例 #2
0
    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})
コード例 #3
0
    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()