Skip to content

Commit

Permalink
💚 Add font files in playwright tests
Browse files Browse the repository at this point in the history
to avoid flaky tests
  • Loading branch information
stevenbal committed Feb 16, 2024
1 parent 4b4e5df commit 4a17636
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit 4a17636

Please sign in to comment.