Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💚 Add font files in playwright tests #1035

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/open_inwoner/kvk/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions src/open_inwoner/utils/tests/playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Loading