From 4b4e5dfb007c6a0ca312ebe62d5c575903fb6f80 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Fri, 16 Feb 2024 10:30:44 +0100 Subject: [PATCH 1/2] :green_heart: Use AssertTimelineLogMixin to fix KVK logging test --- src/open_inwoner/kvk/tests/test_signals.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/open_inwoner/kvk/tests/test_signals.py b/src/open_inwoner/kvk/tests/test_signals.py index 16f27790b6..74f48f9c77 100644 --- a/src/open_inwoner/kvk/tests/test_signals.py +++ b/src/open_inwoner/kvk/tests/test_signals.py @@ -12,6 +12,7 @@ from open_inwoner.accounts.tests.factories import UserFactory from open_inwoner.utils.logentry import LOG_ACTIONS from open_inwoner.utils.test import ClearCachesMixin +from open_inwoner.utils.tests.helpers import AssertTimelineLogMixin from ..client import KvKClient from ..models import KvKConfig @@ -104,7 +105,7 @@ def test_user_is_not_updated_when_http_500(self, m): self.assertFalse(user.is_prepopulated) -class TestLogging(TestCase): +class TestLogging(AssertTimelineLogMixin, TestCase): @classmethod def setUpTestData(cls): config = KvKConfig( @@ -132,20 +133,11 @@ def test_signal_updates_logging(self, m): self.client.force_login(user=user) - log_entry = TimelineLog.objects.filter(object_id=user.id)[2] - - self.assertEquals( - log_entry.timestamp.strftime("%m/%d/%Y, %H:%M:%S"), "10/18/2021, 13:00:00" - ) - self.assertEquals(log_entry.object_id, str(user.id)) - self.assertEquals( - log_entry.extra_data, - { - "message": _("data was retrieved from KvK API"), - "log_level": logging.INFO, - "action_flag": list(LOG_ACTIONS[5]), - "content_object_repr": str(user), - }, + self.assertTimelineLog( + _("data was retrieved from KvK API"), + level=logging.INFO, + action_flag=list(LOG_ACTIONS[5]), + content_object_repr=str(user), ) @requests_mock.Mocker() From 4a17636ee4461f387e8d8fa9581f1eb325874960 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Fri, 16 Feb 2024 12:24:33 +0100 Subject: [PATCH 2/2] :green_heart: Add font files in playwright tests to avoid flaky tests --- src/open_inwoner/utils/tests/playwright.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/open_inwoner/utils/tests/playwright.py b/src/open_inwoner/utils/tests/playwright.py index d627661826..e83eae7008 100644 --- a/src/open_inwoner/utils/tests/playwright.py +++ b/src/open_inwoner/utils/tests/playwright.py @@ -2,12 +2,16 @@ from typing import Callable from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from django.core.files.base import ContentFile from django.urls import reverse from furl import furl from playwright.sync_api import Browser, Playwright, sync_playwright from open_inwoner.accounts.models import User +from open_inwoner.configurations.choices import CustomFontName +from open_inwoner.utils.files import OverwriteStorage +from open_inwoner.utils.test import temp_media_root BROWSER_DRIVERS = { # keys for the E2E_DRIVER environment variable (likely from test matrix) @@ -24,6 +28,7 @@ def get_driver_name() -> str: return os.environ.get("E2E_DRIVER", BROWSER_DEFAULT) +@temp_media_root() class PlaywrightSyncLiveServerTestCase(StaticLiveServerTestCase): """ base class for convenient synchronous Playwright in Django @@ -94,6 +99,14 @@ def setUpClass(cls): cls.playwright = sync_playwright().start() cls.browser = cls.launch_browser(cls.playwright) + # Add custom fonts to media folder to avoid test failures + storage = OverwriteStorage() + for font_name, _ in CustomFontName.choices: + storage.save( + f"custom_fonts/{font_name}.ttf", + ContentFile(b"", name=f"{font_name}.ttf"), + ) + @classmethod def tearDownClass(cls): if cls._old_async_unsafe is None: