|
| 1 | +from unittest.mock import Mock |
| 2 | + |
| 3 | +from tests.integration.integration_test_case import IntegrationTestCase |
| 4 | +from tests.integration.questionnaire import HUB_URL_PATH, THANK_YOU_URL_PATH |
| 5 | + |
| 6 | +FINAL_SUMMARY_PATH = "/questionnaire/summary/" |
| 7 | +FINAL_CONFIRMATION_PATH = "/questionnaire/confirmation/" |
| 8 | + |
| 9 | + |
| 10 | +class SubmissionTestCase(IntegrationTestCase): |
| 11 | + @property |
| 12 | + def retry_url(self): |
| 13 | + return ( |
| 14 | + self.getHtmlSoup().find("p", {"data-qa": "retry"}).find("a").attrs["href"] |
| 15 | + ) |
| 16 | + |
| 17 | + def _mock_submission_failure(self): |
| 18 | + submitter = self._application.eq["submitter"] |
| 19 | + submitter.send_message = Mock(return_value=False) |
| 20 | + |
| 21 | + |
| 22 | +class TestQuestionnaireSubmissionFinalConfirmation(SubmissionTestCase): |
| 23 | + def _launch_and_submit_questionnaire(self): |
| 24 | + # Launch questionnaire |
| 25 | + self.launchSurvey("test_final_confirmation") |
| 26 | + |
| 27 | + # Answer questions and submit survey |
| 28 | + self.post(action="start_questionnaire") |
| 29 | + self.post() |
| 30 | + self.post() |
| 31 | + |
| 32 | + def test_successful_submission(self): |
| 33 | + # Given I launch and answer a questionnaire, When I submit and the submissions succeeds |
| 34 | + self._launch_and_submit_questionnaire() |
| 35 | + |
| 36 | + # Then I should see the thank you page |
| 37 | + self.assertInBody( |
| 38 | + "Your answers were submitted for <span>Integration Testing</span>" |
| 39 | + ) |
| 40 | + self.assertInUrl(THANK_YOU_URL_PATH) |
| 41 | + |
| 42 | + def test_unsuccessful_submission(self): |
| 43 | + self._mock_submission_failure() |
| 44 | + |
| 45 | + # Given I launch and answer a questionnaire, When I submit but the submissions fails |
| 46 | + self._launch_and_submit_questionnaire() |
| 47 | + |
| 48 | + # Then I should see an error page |
| 49 | + self.assertStatusCode(500) |
| 50 | + self.assertEqualPageTitle("Sorry, there is a problem - Census 2021") |
| 51 | + |
| 52 | + self.get(self.retry_url) |
| 53 | + self.assertInUrl(FINAL_CONFIRMATION_PATH) |
| 54 | + |
| 55 | + |
| 56 | +class TestQuestionnaireSubmissionHub(SubmissionTestCase): |
| 57 | + def _launch_and_submit_questionnaire(self): |
| 58 | + # Launch questionnaire |
| 59 | + self.launchSurvey("test_hub_and_spoke") |
| 60 | + |
| 61 | + # Answer questions and submit questionnaire |
| 62 | + self.post() |
| 63 | + self.post({"employment-status-answer": "Working as an employee"}) |
| 64 | + self.post() |
| 65 | + self.post() |
| 66 | + self.post() |
| 67 | + self.post() |
| 68 | + self.post({"does-anyone-live-here-answer": "No"}) |
| 69 | + self.post() |
| 70 | + self.post() |
| 71 | + self.post({"relationships-answer": "No"}) |
| 72 | + self.post() |
| 73 | + self.post() |
| 74 | + |
| 75 | + def test_successful_submission(self): |
| 76 | + # Given I launch and answer a questionnaire, When I submit and the submissions succeeds |
| 77 | + self._launch_and_submit_questionnaire() |
| 78 | + |
| 79 | + # Then I should see the thank you page |
| 80 | + self.assertInBody( |
| 81 | + "Your answers were submitted for <span>Integration Testing</span>" |
| 82 | + ) |
| 83 | + self.assertEqualUrl(THANK_YOU_URL_PATH) |
| 84 | + |
| 85 | + def test_unsuccessful_submission(self): |
| 86 | + self._mock_submission_failure() |
| 87 | + |
| 88 | + # Given I launch and answer a questionnaire, When I submit but the submissions fails |
| 89 | + self._launch_and_submit_questionnaire() |
| 90 | + |
| 91 | + # Then I should see an error page |
| 92 | + self.assertStatusCode(500) |
| 93 | + self.assertEqualPageTitle("Sorry, there is a problem - Census 2021") |
| 94 | + |
| 95 | + self.get(self.retry_url) |
| 96 | + self.assertInUrl(HUB_URL_PATH) |
| 97 | + |
| 98 | + |
| 99 | +class TestQuestionnaireSubmissionFinalSummary(SubmissionTestCase): |
| 100 | + def _launch_and_submit_questionnaire(self): |
| 101 | + # Launch questionnaire |
| 102 | + self.launchSurvey("test_summary") |
| 103 | + |
| 104 | + # Answer questions and submit survey |
| 105 | + self.post() |
| 106 | + self.post() |
| 107 | + self.post() |
| 108 | + self.post() |
| 109 | + |
| 110 | + def test_successful_submission(self): |
| 111 | + # Given I launch and answer a questionnaire, When I submit and the submissions succeeds |
| 112 | + self._launch_and_submit_questionnaire() |
| 113 | + |
| 114 | + # Then I should see the thank you page |
| 115 | + self.assertInBody( |
| 116 | + "Your answers were submitted for <span>Integration Testing</span>" |
| 117 | + ) |
| 118 | + self.assertInUrl(THANK_YOU_URL_PATH) |
| 119 | + |
| 120 | + def test_unsuccessful_submission(self): |
| 121 | + self._mock_submission_failure() |
| 122 | + |
| 123 | + # Given I launch and answer a questionnaire, When I submit but the submissions fails |
| 124 | + self.launchSurvey("test_summary") |
| 125 | + self.post() |
| 126 | + self.post() |
| 127 | + self.post() |
| 128 | + self.post() |
| 129 | + |
| 130 | + # Then I should see an error page |
| 131 | + self.assertStatusCode(500) |
| 132 | + self.assertEqualPageTitle("Sorry, there is a problem - Census 2021") |
| 133 | + |
| 134 | + self.get(self.retry_url) |
| 135 | + self.assertInUrl(FINAL_SUMMARY_PATH) |
0 commit comments