revise to use session instead of a timer

This commit is contained in:
Rachid Mrad 2024-06-11 15:58:11 -04:00
parent 7809ab5978
commit f8f1ec447c
No known key found for this signature in database
3 changed files with 41 additions and 21 deletions

View file

@ -110,10 +110,12 @@ class DomainRequestTests(TestWithUser, WebTest):
This tests that the domain requests get created only when they should.
"""
# Get the intro page
intro_page = self.app.get(reverse("domain-request:"))
self.app.get(reverse("home"))
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
intro_page = self.app.get(reverse("domain-request:"))
# Select the form
intro_form = intro_page.forms[0]
@ -129,22 +131,26 @@ class DomainRequestTests(TestWithUser, WebTest):
domain_request_count = DomainRequest.objects.count()
self.assertEqual(domain_request_count, 1)
# AGAIN right away, this should NOT cause a new request to be created
# as a small threshold between 'Continue' submits indicate a use of the
# browser back button.
# Let's go back to intro and submit again, this should not create a new request
# This is the equivalent of a back button nav from step 1 to intro -> continue
intro_form = intro_page.forms[0]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
response = intro_form.submit(name="submit_button", value="intro_acknowledge")
type_form = intro_form.submit(name="submit_button", value="intro_acknowledge")
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
response.follow()
type_form.follow()
domain_request_count = DomainRequest.objects.count()
self.assertEqual(domain_request_count, 1)
# One more time, dropping session which will set the last_submit_time to 0,
# therefore increasing the threshold and having us expect the creation of a new request
# Go home, which will reset the session flag for new request
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
self.app.get(reverse("home"))
# This time, clicking continue will create a new request
intro_form = intro_page.forms[0]
response = intro_form.submit(name="submit_button", value="intro_acknowledge")
response.follow()
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
intro_result = intro_form.submit(name="submit_button", value="intro_acknowledge")
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
intro_result.follow()
domain_request_count = DomainRequest.objects.count()
self.assertEqual(domain_request_count, 2)