Skip to content

Commit

Permalink
Fixed lingering problem in tests after merges of conflicting branches (
Browse files Browse the repository at this point in the history
…#701)

Co-authored-by: Bart van der Schoor <[email protected]>
  • Loading branch information
Bartvaderkin and Bart van der Schoor authored Jun 26, 2023
1 parent 525e5f9 commit 892ae8e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/open_inwoner/cms/cases/tests/test_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@
DisableRequestLogMixin,
paginated_response,
)
from open_inwoner.utils.tests.helpers import AssertMockMatchersMixin
from open_inwoner.utils.tests.playwright import PlaywrightSyncLiveServerTestCase


@tag("e2e")
@requests_mock.Mocker()
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
class CasesPlaywrightTests(
ClearCachesMixin, DisableRequestLogMixin, PlaywrightSyncLiveServerTestCase
AssertMockMatchersMixin,
ClearCachesMixin,
DisableRequestLogMixin,
PlaywrightSyncLiveServerTestCase,
):
def setUp(self) -> None:
super().setUp()
Expand Down Expand Up @@ -432,9 +436,6 @@ def test_cases(self, m):
with open(download.path(), "rb") as f:
self.assertEqual(f.read(), self.uploaded_zaak_informatie_object_content)

# finally check if our mock matchers are accurate
self.assertMockMatchersCalledAll(self.matchers)

# contact form
contact_form = page.locator("#contact-form")
expect(contact_form).to_be_visible()
Expand All @@ -455,15 +456,4 @@ def test_cases(self, m):
expect(notification.get_by_text(_("Vraag verstuurd!"))).to_be_visible()

# finally check if our mock matchers are accurate
self.assertMockMatchersCalledAll(self.contact_moment_matchers)

def assertMockMatchersCalledAll(self, matchers):
def _match_str(m):
return f" {m._method.ljust(5, ' ')} {m._url}"

missed = [m for m in matchers if not m.called]
if not missed:
return

out = "\n".join(_match_str(m) for m in missed)
self.fail(f"request mock matchers not called:\n{out}")
self.assertMockMatchersCalled(self.matchers)
25 changes: 25 additions & 0 deletions src/open_inwoner/utils/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ def resetTimelineLogs(self):
TimelineLog.objects.all().delete()


class AssertMockMatchersMixin:
def assertMockMatchersCalled(self, matchers):
"""
check if all matchers are called
matchers = [
m.get(url1, res1),
m.get(url2, res2),
m.post(url3, res3),
]
// do tests
self.assertMockMatchersCalled(matchers)
"""

def _match_str(m):
return f" {m._method.ljust(5, ' ')} {m._url}"

missed = [m for m in matchers if not m.called]
if not missed:
return

out = "\n".join(_match_str(m) for m in missed)
self.fail(f"request mock matchers not called:\n{out}")


class AssertFormMixin:
def assertFormExactFields(
self, form, field_names, *, with_csrf=True, drop_no_name=True
Expand Down

0 comments on commit 892ae8e

Please sign in to comment.