Skip to content

Commit 105d753

Browse files
committed
[#9] Add test for caching forms retrieval
1 parent d4aec32 commit 105d753

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ tests_require =
4141
isort
4242
black
4343
flake8
44+
time-machine
4445

4546
[options.packages.find]
4647
include =
@@ -56,6 +57,7 @@ tests =
5657
isort
5758
black
5859
flake8
60+
time-machine
5961
pep8 = flake8
6062
coverage = pytest-cov
6163
docs =

tests/test_integration.py

+20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import datetime
12
from uuid import UUID
23

34
from django.forms import modelform_factory
45
from django.test import TestCase
56

67
import requests_mock
8+
import time_machine
79

810
from openformsclient.models import Configuration
911
from testapp.models import Page
@@ -129,3 +131,21 @@ def test_slug_form_field_blank(self, m):
129131

130132
self.assertEqual(Page.objects.count(), 1)
131133
self.assertEqual(Page.objects.get().form_slug, "")
134+
135+
def test_form_retrieval_cache(self, m):
136+
self._prepare_mock(m)
137+
138+
PageForm = modelform_factory(Page, fields=["form_slug"])
139+
page_form = PageForm()
140+
141+
with time_machine.travel(0) as traveller:
142+
list(page_form.fields["form_slug"].choices)
143+
list(page_form.fields["form_slug"].choices)
144+
145+
self.assertEqual(m.call_count, 1)
146+
147+
traveller.shift(datetime.timedelta(seconds=60))
148+
149+
list(page_form.fields["form_slug"].choices)
150+
151+
self.assertEqual(m.call_count, 2)

0 commit comments

Comments
 (0)