Beispiel #1
0
    def test_post_save_fail_save_model_action(self, settings, save_model_action, extract_content_data, cache,
                                              extract_process_data, logger):
        settings.RUN_ASYNC = False
        save_model_action.side_effect = Exception
        model = TestModel(
            string_field='Test',
            integer_field=1,
            float_field=1.0,
        )
        old_object = serialize_model_instance(model)
        model.string_field = 'Modified'
        model.integer_field = 2
        model.float_field = 2.0
        new_object = serialize_model_instance(model)
        content = signals._extract_content_data(old_object, new_object)
        extract_content_data.return_value = content

        signals._post_save(model, instance=model)

        # Check that extract process and access was done successfully
        self.assertEqual(cache.get_last_access.call_count, 1)
        self.assertEqual(cache.get_process.call_count, 1)
        self.assertEqual(extract_process_data.call_count, 1)

        # Check that save process wasn't done successfully
        self.assertEqual(logger.exception.call_count, 1)
Beispiel #2
0
    def test_post_save_not_old_data(self, settings, save_model_action, extract_content_data, cache,
                                    extract_process_data):
        settings.RUN_ASYNC = False
        model = TestModel(
            string_field='Test',
            integer_field=1,
            float_field=1.0,
        )
        old_object = serialize_model_instance(model)
        model.string_field = 'Modified'
        model.integer_field = 2
        model.float_field = 2.0
        new_object = serialize_model_instance(model)
        content = signals._extract_content_data(old_object, new_object)
        extract_content_data.return_value = content

        signals._post_save(model, instance=model)

        # Check that extract process and access was done successfully
        self.assertEqual(cache.get_last_access.call_count, 1)
        self.assertEqual(cache.get_process.call_count, 1)
        self.assertEqual(extract_process_data.call_count, 1)

        # Check that was called synchronously
        self.assertEqual(save_model_action.call_count, 1)
        self.assertEqual(save_model_action.apply_async.call_count, 0)
Beispiel #3
0
    def test_post_save_fail(self, logger, serialize_model_instance_mock):
        model = TestModel(
                string_field='Test',
                integer_field=1,
                float_field=1.0,
        )
        signals._post_save(model, instance=model)

        # Check that save process wasn't done successfully
        self.assertEqual(logger.exception.call_count, 1)