Пример #1
0
    def test_pre_save_update(self, serialize_model_instance):
        model = TestModel(
            string_field='Test',
            integer_field=1,
            float_field=1.0,
            id=1
        )
        sender = MagicMock()
        sender.objects.get.return_value = model
        serialize_model_instance.return_value = model

        signals._pre_save(sender, instance=model)
        self.assertEqual(signals._CACHE, {id(model): model})
Пример #2
0
    def test_pre_save_new(self):
        model = TestModel(
            string_field='Test',
            integer_field=1,
            float_field=1.0,
            id=1
        )
        sender = MagicMock()
        sender.objects.get.side_effect = Exception('Test Exception')

        signals._pre_save(sender, instance=model)

        self.assertEqual(signals._CACHE, {})
Пример #3
0
    def test_pre_save_fail(self, logger):
        sender = MagicMock()

        signals._pre_save(sender)
        self.assertEqual(logger.exception.call_count, 1)