mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-14 13:34:10 +02:00
tests running locally for session
This commit is contained in:
parent
9c63383db7
commit
8c34c919cc
2 changed files with 49 additions and 3 deletions
|
@ -130,6 +130,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
As we add additional form pages, we need to include them here to make
|
As we add additional form pages, we need to include them here to make
|
||||||
this test work.
|
this test work.
|
||||||
"""
|
"""
|
||||||
|
print("in form submission")
|
||||||
num_pages_tested = 0
|
num_pages_tested = 0
|
||||||
# elections, type_of_work, tribal_government, no_other_contacts
|
# elections, type_of_work, tribal_government, no_other_contacts
|
||||||
SKIPPED_PAGES = 4
|
SKIPPED_PAGES = 4
|
||||||
|
@ -141,38 +142,55 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# of a "session". We are going to do it manually, saving the session ID here
|
# of a "session". We are going to do it manually, saving the session ID here
|
||||||
# and then setting the cookie on each request.
|
# and then setting the cookie on each request.
|
||||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
session_wizard=self.app.session['wizard_application']
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(self.app.session)
|
||||||
|
print(self.app.session.items())
|
||||||
|
except:
|
||||||
|
print("cant print session")
|
||||||
|
print(self.app)
|
||||||
|
|
||||||
# ---- TYPE PAGE ----
|
# ---- TYPE PAGE ----
|
||||||
type_form = type_page.form
|
type_form = type_page.form
|
||||||
type_form["organization_type-organization_type"] = "federal"
|
type_form["organization_type-organization_type"] = "federal"
|
||||||
|
print("submitting form with federal")
|
||||||
# test next button and validate data
|
# test next button and validate data
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
type_result = type_page.form.submit()
|
type_result = type_page.form.submit()
|
||||||
# should see results in db
|
# should see results in db
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
print("domain application is %s", str(application))
|
||||||
self.assertEqual(application.organization_type, "federal")
|
self.assertEqual(application.organization_type, "federal")
|
||||||
# the post request should return a redirect to the next form in
|
# the post request should return a redirect to the next form in
|
||||||
# the application
|
# the application
|
||||||
|
print("going to organization federal")
|
||||||
self.assertEqual(type_result.status_code, 302)
|
self.assertEqual(type_result.status_code, 302)
|
||||||
self.assertEqual(type_result["Location"], "/register/organization_federal/")
|
self.assertEqual(type_result["Location"], "/register/organization_federal/")
|
||||||
num_pages_tested += 1
|
num_pages_tested += 1
|
||||||
|
|
||||||
# ---- FEDERAL BRANCH PAGE ----
|
# ---- FEDERAL BRANCH PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
|
print("clicking exective")
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
|
|
||||||
federal_page = type_result.follow()
|
federal_page = type_result.follow()
|
||||||
federal_form = federal_page.form
|
federal_form = federal_page.form
|
||||||
federal_form["organization_federal-federal_type"] = "executive"
|
federal_form["organization_federal-federal_type"] = "executive"
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
|
|
||||||
federal_result = federal_form.submit()
|
federal_result = federal_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
self.assertEqual(application.federal_type, "executive")
|
self.assertEqual(application.federal_type, "executive")
|
||||||
# the post request should return a redirect to the next form in
|
# the post request should return a redirect to the next form in
|
||||||
# the application
|
# the application
|
||||||
|
print("clicking contact")
|
||||||
self.assertEqual(federal_result.status_code, 302)
|
self.assertEqual(federal_result.status_code, 302)
|
||||||
self.assertEqual(federal_result["Location"], "/register/organization_contact/")
|
self.assertEqual(federal_result["Location"], "/register/organization_contact/")
|
||||||
num_pages_tested += 1
|
num_pages_tested += 1
|
||||||
|
@ -180,6 +198,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- ORG CONTACT PAGE ----
|
# ---- ORG CONTACT PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
|
|
||||||
org_contact_page = federal_result.follow()
|
org_contact_page = federal_result.follow()
|
||||||
org_contact_form = org_contact_page.form
|
org_contact_form = org_contact_page.form
|
||||||
# federal agency so we have to fill in federal_agency
|
# federal agency so we have to fill in federal_agency
|
||||||
|
@ -196,6 +216,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
|
|
||||||
org_contact_result = org_contact_form.submit()
|
org_contact_result = org_contact_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -217,6 +239,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- AUTHORIZING OFFICIAL PAGE ----
|
# ---- AUTHORIZING OFFICIAL PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
|
|
||||||
ao_page = org_contact_result.follow()
|
ao_page = org_contact_result.follow()
|
||||||
ao_form = ao_page.form
|
ao_form = ao_page.form
|
||||||
ao_form["authorizing_official-first_name"] = "Testy ATO"
|
ao_form["authorizing_official-first_name"] = "Testy ATO"
|
||||||
|
@ -227,6 +251,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
ao_result = ao_form.submit()
|
ao_result = ao_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -244,12 +269,14 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- CURRENT SITES PAGE ----
|
# ---- CURRENT SITES PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
current_sites_page = ao_result.follow()
|
current_sites_page = ao_result.follow()
|
||||||
current_sites_form = current_sites_page.form
|
current_sites_form = current_sites_page.form
|
||||||
current_sites_form["current_sites-0-website"] = "www.city.com"
|
current_sites_form["current_sites-0-website"] = "www.city.com"
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
current_sites_result = current_sites_form.submit()
|
current_sites_result = current_sites_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -266,12 +293,14 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- DOTGOV DOMAIN PAGE ----
|
# ---- DOTGOV DOMAIN PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
dotgov_page = current_sites_result.follow()
|
dotgov_page = current_sites_result.follow()
|
||||||
dotgov_form = dotgov_page.form
|
dotgov_form = dotgov_page.form
|
||||||
dotgov_form["dotgov_domain-requested_domain"] = "city"
|
dotgov_form["dotgov_domain-requested_domain"] = "city"
|
||||||
dotgov_form["dotgov_domain-0-alternative_domain"] = "city1"
|
dotgov_form["dotgov_domain-0-alternative_domain"] = "city1"
|
||||||
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
dotgov_result = dotgov_form.submit()
|
dotgov_result = dotgov_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -288,12 +317,14 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- PURPOSE PAGE ----
|
# ---- PURPOSE PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
purpose_page = dotgov_result.follow()
|
purpose_page = dotgov_result.follow()
|
||||||
purpose_form = purpose_page.form
|
purpose_form = purpose_page.form
|
||||||
purpose_form["purpose-purpose"] = "For all kinds of things."
|
purpose_form["purpose-purpose"] = "For all kinds of things."
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
purpose_result = purpose_form.submit()
|
purpose_result = purpose_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -307,6 +338,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- YOUR CONTACT INFO PAGE ----
|
# ---- YOUR CONTACT INFO PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
your_contact_page = purpose_result.follow()
|
your_contact_page = purpose_result.follow()
|
||||||
your_contact_form = your_contact_page.form
|
your_contact_form = your_contact_page.form
|
||||||
|
|
||||||
|
@ -318,6 +350,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
your_contact_result = your_contact_form.submit()
|
your_contact_result = your_contact_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -335,6 +368,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- OTHER CONTACTS PAGE ----
|
# ---- OTHER CONTACTS PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
other_contacts_page = your_contact_result.follow()
|
other_contacts_page = your_contact_result.follow()
|
||||||
other_contacts_form = other_contacts_page.form
|
other_contacts_form = other_contacts_page.form
|
||||||
|
|
||||||
|
@ -346,6 +380,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
other_contacts_result = other_contacts_form.submit()
|
other_contacts_result = other_contacts_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -375,6 +410,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
# test next button
|
# test next button
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
anything_else_result = anything_else_form.submit()
|
anything_else_result = anything_else_form.submit()
|
||||||
# validate that data from this step are being saved
|
# validate that data from this step are being saved
|
||||||
application = DomainApplication.objects.get() # there's only one
|
application = DomainApplication.objects.get() # there's only one
|
||||||
|
@ -388,6 +424,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- REQUIREMENTS PAGE ----
|
# ---- REQUIREMENTS PAGE ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
requirements_page = anything_else_result.follow()
|
requirements_page = anything_else_result.follow()
|
||||||
requirements_form = requirements_page.form
|
requirements_form = requirements_page.form
|
||||||
|
|
||||||
|
@ -408,6 +445,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# ---- REVIEW AND FINSIHED PAGES ----
|
# ---- REVIEW AND FINSIHED PAGES ----
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
review_page = requirements_result.follow()
|
review_page = requirements_result.follow()
|
||||||
review_form = review_page.form
|
review_form = review_page.form
|
||||||
|
|
||||||
|
@ -444,6 +482,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
# final submission results in a redirect to the "finished" URL
|
# final submission results in a redirect to the "finished" URL
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
review_result = review_form.submit()
|
review_result = review_form.submit()
|
||||||
|
|
||||||
|
@ -454,6 +493,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# following this redirect is a GET request, so include the cookie
|
# following this redirect is a GET request, so include the cookie
|
||||||
# here too.
|
# here too.
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
final_result = review_result.follow()
|
final_result = review_result.follow()
|
||||||
self.assertContains(final_result, "Thanks for your domain request!")
|
self.assertContains(final_result, "Thanks for your domain request!")
|
||||||
|
@ -485,13 +525,16 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# type_page = home_page.click("Edit")
|
# type_page = home_page.click("Edit")
|
||||||
|
|
||||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
session_wizard=self.app.session['wizard_application']
|
||||||
url = reverse("edit-application", kwargs={"id": application.pk})
|
url = reverse("edit-application", kwargs={"id": application.pk})
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
|
|
||||||
# TODO: The following line results in a django error on middleware
|
# TODO: The following line results in a django error on middleware
|
||||||
response = self.client.get(url, follow=True)
|
response = self.client.get(url, follow=True)
|
||||||
self.assertContains(response, "Type of organization")
|
self.assertContains(response, "Type of organization")
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
self.app.session["wizard_application"]=session_wizard
|
||||||
# TODO: Step through the remaining pages
|
# TODO: Step through the remaining pages
|
||||||
|
|
||||||
self.assertEqual(num_pages, num_pages_tested)
|
self.assertEqual(num_pages, num_pages_tested)
|
||||||
|
|
|
@ -133,19 +133,22 @@ class ApplicationWizard(TemplateView):
|
||||||
if self.has_pk():
|
if self.has_pk():
|
||||||
id = self.storage["application_id"]
|
id = self.storage["application_id"]
|
||||||
try:
|
try:
|
||||||
|
logger.debug("Trying to get the application")
|
||||||
self._application = DomainApplication.objects.get(
|
self._application = DomainApplication.objects.get(
|
||||||
creator=self.request.user, # type: ignore
|
creator=self.request.user, # type: ignore
|
||||||
pk=id,
|
pk=id,
|
||||||
)
|
)
|
||||||
|
logger.debug("applicaiton is %s",self._application)
|
||||||
return self._application
|
return self._application
|
||||||
except DomainApplication.DoesNotExist:
|
except DomainApplication.DoesNotExist:
|
||||||
logger.debug("Application id %s did not have a DomainApplication" % id)
|
logger.debug("Application id %s did not have a DomainApplication" % id)
|
||||||
|
logger.debug("creating application with next id")
|
||||||
self._application = DomainApplication.objects.create(
|
self._application = DomainApplication.objects.create(
|
||||||
creator=self.request.user, # type: ignore
|
creator=self.request.user, # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
self.storage["application_id"] = self._application.id
|
self.storage["application_id"] = self._application.id
|
||||||
|
logger.debug("setting id to %s",self._application.id)
|
||||||
return self._application
|
return self._application
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -216,7 +219,7 @@ class ApplicationWizard(TemplateView):
|
||||||
#if starting a new application, clear the storage
|
#if starting a new application, clear the storage
|
||||||
if request.path_info == self.NEW_URL_NAME:
|
if request.path_info == self.NEW_URL_NAME:
|
||||||
del self.storage
|
del self.storage
|
||||||
self.storage["application_id"] = None #reset the app
|
# self.storage["application_id"] = None #reset the app
|
||||||
|
|
||||||
return self.goto(self.steps.first)
|
return self.goto(self.steps.first)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue