Skip to content

Commit

Permalink
[#9] Add test for caching forms retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Jun 18, 2024
1 parent d4aec32 commit 105d753
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tests_require =
isort
black
flake8
time-machine

[options.packages.find]
include =
Expand All @@ -56,6 +57,7 @@ tests =
isort
black
flake8
time-machine
pep8 = flake8
coverage = pytest-cov
docs =
Expand Down
20 changes: 20 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime
from uuid import UUID

from django.forms import modelform_factory
from django.test import TestCase

import requests_mock
import time_machine

from openformsclient.models import Configuration
from testapp.models import Page
Expand Down Expand Up @@ -129,3 +131,21 @@ def test_slug_form_field_blank(self, m):

self.assertEqual(Page.objects.count(), 1)
self.assertEqual(Page.objects.get().form_slug, "")

def test_form_retrieval_cache(self, m):
self._prepare_mock(m)

PageForm = modelform_factory(Page, fields=["form_slug"])
page_form = PageForm()

with time_machine.travel(0) as traveller:
list(page_form.fields["form_slug"].choices)
list(page_form.fields["form_slug"].choices)

self.assertEqual(m.call_count, 1)

traveller.shift(datetime.timedelta(seconds=60))

list(page_form.fields["form_slug"].choices)

self.assertEqual(m.call_count, 2)

0 comments on commit 105d753

Please sign in to comment.