mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 10:29:23 +02:00
solidify unit test
This commit is contained in:
parent
2586f10342
commit
7809ab5978
2 changed files with 34 additions and 12 deletions
|
@ -109,21 +109,45 @@ 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:"))
|
||||
|
||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||
|
||||
# Select the form
|
||||
intro_form = intro_page.forms[0]
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
intro_result = intro_form.submit()
|
||||
|
||||
# follow first redirect
|
||||
# Submit the form, this creates 1 Request
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
intro_result.follow()
|
||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||
response = intro_form.submit(name="submit_button", value="intro_acknowledge")
|
||||
|
||||
# should see results in db
|
||||
# Landing on the next page used to create another 1 request
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
response.follow()
|
||||
|
||||
# Check if a new DomainRequest object has been created
|
||||
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.
|
||||
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")
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
response.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
|
||||
intro_form = intro_page.forms[0]
|
||||
response = intro_form.submit(name="submit_button", value="intro_acknowledge")
|
||||
response.follow()
|
||||
domain_request_count = DomainRequest.objects.count()
|
||||
self.assertEqual(domain_request_count, 2)
|
||||
|
||||
@boto3_mocking.patching
|
||||
def test_domain_request_form_submission(self):
|
||||
"""
|
||||
|
|
|
@ -220,7 +220,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
|
|||
self.storage["domain_request_id"] = kwargs["id"]
|
||||
self.storage["step_history"] = self.db_check_for_unlocking_steps()
|
||||
|
||||
# if accessing this class directly, redirect to either to an acknowledgement
|
||||
# if accessing this class directly, redirect to either to an acknowledgement
|
||||
# page or to the first step in the processes (if an edit rather than a new request);
|
||||
# subclasseswill NOT be redirected. The purpose of this is to allow code to
|
||||
# send users "to the domain request wizard" without needing to know which view
|
||||
|
@ -234,7 +234,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
|
|||
return render(request, "domain_request_intro.html", context={})
|
||||
else:
|
||||
return self.goto(self.steps.first)
|
||||
|
||||
|
||||
context = self.get_context_data()
|
||||
self.steps.current = current_url
|
||||
context["forms"] = self.get_forms()
|
||||
|
@ -462,10 +462,8 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
|
|||
|
||||
# if user has acknowledged the intro message
|
||||
if button == "intro_acknowledge":
|
||||
print("intro_acknowledge")
|
||||
if request.path_info == self.NEW_URL_NAME:
|
||||
print("Creating DomainRequest...")
|
||||
last_submit_time = request.session.get('last_submit_time', 0)
|
||||
last_submit_time = request.session.get("last_submit_time", 0)
|
||||
|
||||
# Check if the last submit was very recent, indicating a back button -> submit sequence
|
||||
if current_time - last_submit_time > 5: # 5 seconds threshold
|
||||
|
@ -474,7 +472,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
|
|||
del self.storage
|
||||
|
||||
# Update the last submit time
|
||||
request.session['last_submit_time'] = current_time
|
||||
request.session["last_submit_time"] = current_time
|
||||
|
||||
return self.goto(self.steps.first)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue