From dd176565646c2a1ec65b4a5d2029d9e5104405b8 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 18 Jul 2024 17:31:19 +0200 Subject: [PATCH] Edge case testing --- projects/test_views.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/projects/test_views.py b/projects/test_views.py index f1040c4..aaa6f2c 100644 --- a/projects/test_views.py +++ b/projects/test_views.py @@ -6,7 +6,7 @@ from django.test.utils import override_settings from accounts.models import User -from projects.models import Catalog, Project +from projects.models import Catalog, Event, Project from projects.translators import TranslationError, fix_nls @@ -444,3 +444,43 @@ def test_fix_nls(self): ]: with self.subTest(test=test): self.assertEqual(fix_nls(test[0], test[1]), test[2]) + + def test_event_save(self): + user = User.objects.create_superuser("admin@example.com", "admin") + p = Project.objects.create(name="test", slug="test") + c = p.catalogs.create( + language_code="fr", + domain="djangojs", + pofile="", + ) + + p2 = Project.objects.create(name="test2", slug="test2") + + e = Event.objects.create( + user=user, + action=Event.Action.CATALOG_CREATED, + catalog=c, + ) + self.assertEqual(str(e), "created catalog") + self.assertEqual(e.project, p) + + e = Event.objects.create( + user=user, + action=Event.Action.CATALOG_CREATED, + catalog=c, + project=p2, # Makes no sense but is allowed + ) + self.assertEqual(str(e), "created catalog") + self.assertEqual(e.project, p2) + + e = Event.objects.create( + action=Event.Action.CATALOG_CREATED, + ) + self.assertEqual(str(e), "created catalog") + + e = Event.objects.create( + user=user, + action=Event.Action.CATALOG_CREATED, + project=p2, + ) + self.assertEqual(str(e), "created catalog")