Exemple #1
0
 def test_model_with_additional_data(self):
     related_model = SimpleModel.objects.create(text="Log my reference")
     obj_with_additional_data = AdditionalDataIncludedModel(
         label="Additional data to log entries", related=related_model)
     obj_with_additional_data.save()
     self.assertEqual(obj_with_additional_data.history.count(),
                      1,
                      msg="There is 1 log entry")
     log_entry = obj_with_additional_data.history.get()
     # FIXME: Work-around for the fact that additional_data isn't working
     # on Django 3.1 correctly (see https://github.com/jazzband/django-auditlog/issues/266)
     if django.VERSION >= (3, 1):
         extra_data = json.loads(log_entry.additional_data)
     else:
         extra_data = log_entry.additional_data
     self.assertIsNotNone(extra_data)
     self.assertEqual(
         extra_data["related_model_text"],
         related_model.text,
         msg="Related model's text is logged",
     )
     self.assertEqual(
         extra_data["related_model_id"],
         related_model.id,
         msg="Related model's id is logged",
     )
Exemple #2
0
 def test_model_with_additional_data(self):
     related_model = SimpleModel.objects.create(text="Log my reference")
     obj_with_additional_data = AdditionalDataIncludedModel(
         label="Additional data to log entries", related=related_model
     )
     obj_with_additional_data.save()
     self.assertTrue(obj_with_additional_data.history.count() == 1, msg="There is 1 log entry")
     log_entry = obj_with_additional_data.history.get()
     self.assertIsNotNone(log_entry.additional_data)
     extra_data = log_entry.additional_data
     self.assertTrue(extra_data["related_model_text"] == related_model.text, msg="Related model's text is logged")
     self.assertTrue(extra_data["related_model_id"] == related_model.id, msg="Related model's id is logged")
Exemple #3
0
 def test_model_with_additional_data(self):
     related_model = SimpleModel.objects.create(text='Log my reference')
     obj_with_additional_data = AdditionalDataIncludedModel(
         label='Additional data to log entries', related=related_model)
     obj_with_additional_data.save()
     self.assertTrue(obj_with_additional_data.history.count() == 1,
                     msg="There is 1 log entry")
     log_entry = obj_with_additional_data.history.get()
     self.assertIsNotNone(log_entry.additional_data)
     extra_data = log_entry.additional_data
     self.assertTrue(extra_data['related_model_text'] == related_model.text,
                     msg="Related model's text is logged")
     self.assertTrue(extra_data['related_model_id'] == related_model.id,
                     msg="Related model's id is logged")