def test_different_metadata_store_to_url(self): # Get a token for the first questionnaire token = create_token("0205", "1") response1 = self.client.get("/session?token=" + token.decode(), follow_redirects=True) self.assertEquals(response1.status_code, 200) content1 = response1.get_data(True) self.assertRegexpMatches(content1, "<title>Introduction</title>") self.assertRegexpMatches(content1, ">Start survey<") self.assertRegexpMatches(content1, "Monthly Business Survey - Retail Sales Index") # Open up a second questionnaire token = create_token("star_wars", "0") response2 = self.client.get("/session?token=" + token.decode(), follow_redirects=True) self.assertEquals(response2.status_code, 200) content2 = response2.get_data(True) self.assertRegexpMatches(content2, "<title>Introduction</title>") self.assertRegexpMatches(content2, ">Start survey<") self.assertRegexpMatches(content2, "Star Wars") # We try to post to the wrong questionnaire post_data = {"action[start_questionnaire]": "Start Questionnaire"} response = self.client.post(mci_test_urls.MCI_0205_INTRODUCTION, data=post_data, follow_redirects=True) content = response.get_data(True) self.assertRegexpMatches(content, "Information") self.assertRegexpMatches(content, "Unfortunately you can only complete one survey at a time.") self.assertRegexpMatches(content, "Close this window to continue with your current survey.")
def test_different_metadata_store_to_url(self): # Get a token for the first questionnaire token = create_token('0205', '1') response1 = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(response1.status_code, 200) content1 = response1.get_data(True) self.assertRegex(content1, '<title>Introduction</title>') self.assertRegex(content1, '>Start survey<') self.assertRegex(content1, 'Monthly Business Survey - Retail Sales Index') # Open up a second questionnaire token = create_token('star_wars', '0') response2 = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(response2.status_code, 200) content2 = response2.get_data(True) self.assertRegex(content2, '<title>Introduction</title>') self.assertRegex(content2, '>Start survey<') self.assertRegex(content2, 'Star Wars') # We try to post to the wrong questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } response = self.client.post(mci_test_urls.MCI_0205_INTRODUCTION, data=post_data, follow_redirects=True) content = response.get_data(True) self.assertRegex(content, 'Information') self.assertRegex(content, 'Unfortunately you can only complete one survey at a time.') self.assertRegex(content, 'Close this window to continue with your current survey.')
def test_save_sign_out_with_mandatory_question_not_answered(self): # We can save and go to the sign-out page without having to fill in mandatory answer base_url = '/questionnaire/1/0205/789/' # Given token = create_token('0205', '1') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When post_data = {'action[start_questionnaire]': 'Start Questionnaire'} resp = self.client.post(base_url + 'introduction', data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] post_data = { "total-retail-turnover": "1000", "action[save_sign_out]": "Save and sign out" } resp = self.client.post(block_one_url, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # Then # we are presented with the sign out page self.assertTrue("signed-out" in resp.headers['Location']) resp = self.client.get(resp.headers['Location'], follow_redirects=False) self.assertEquals(resp.status_code, 200)
def try_another_date(self, form_type_id, eq_id): # Try another date # Get a token token = create_token(form_type_id, eq_id, "2017-08-01", "2017-08-31") resp = self.client.get("/session?token=" + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, "<title>Introduction</title>") # We proceed to the questionnaire post_data = {"action[start_questionnaire]": "Start Questionnaire"} resp = self.client.post( "/questionnaire/" + eq_id + "/" + form_type_id + "/201604/789/introduction", data=post_data, follow_redirects=False, ) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers["Location"] resp = self.client.get(block_one_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are in the Questionnaire content = resp.get_data(True) self.assertRegexpMatches(content, "<title>Survey</title>") self.assertRegexpMatches(content, ">Monthly Business Survey - Retail Sales Index</") self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") self.assertRegexpMatches(content, "1 August 2017") self.assertRegexpMatches(content, "31 August 2017")
def test_invalid_integer(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(resp.status_code, 200) form_data = { # Start Date "period-from-day": "01", "period-from-month": "1", "period-from-year": "2016", # End Date "period-to-day": "01", "period-to-month": "1", "period-to-year": "2017", # Total Turnover "total-retail-turnover": "rubbish", # User action "action[save_continue]": "Save & Continue" } # We submit the form without a valid turnover value resp = self.client.post(mci_test_urls.MCI_0205_BLOCK1, data=form_data, follow_redirects=True) self.assertEqual(resp.status_code, 200) content = resp.get_data(True) self.assertRegex(content, "Please only enter whole numbers into the field.")
def test_invalid_date_number(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(resp.status_code, 200) form_data = { # Start Date "period-from-day": "01", "period-from-month": "1", "period-from-year": "", # End Date "period-to-day": "01", "period-to-month": "1", "period-to-year": "", # Total Turnover "total-retail-turnover": "100000", # User action "action[save_continue]": "Save & Continue" } # We submit the form with an invalid date resp = self.client.post(mci_test_urls.MCI_0205_BLOCK1, data=form_data, follow_redirects=True) self.assertEqual(resp.status_code, 200) content = resp.get_data(True) self.assertRegex( content, "The date entered is not valid. Please correct your answer.")
def test_save_sign_out_with_non_mandatory_validation_error(self): # We can't save if a validation error is caused, this doesn't include missing a mandatory question base_url = '/questionnaire/1/0205/789/' # Given token = create_token('0205', '1') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When post_data = {'action[start_questionnaire]': 'Start Questionnaire'} resp = self.client.post(base_url + 'introduction', data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] post_data = { "total-retail-turnover": "error", "action[save_sign_out]": "Save and sign out" } resp = self.client.post(block_one_url, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 200) # Then # we are presented with an error message content = resp.get_data(True) self.assertRegexpMatches( content, 'Please only enter whole numbers into the field.')
def test_previous_link_appears_on_page_following_introduction(self): base_url = '/questionnaire/test/final_confirmation/789/' # Given token = create_token('final_confirmation', 'test') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When # We proceed through the questionnaire post_data = {'action[start_questionnaire]': 'Start Questionnaire'} block_one_url, resp = self.postRedirectGet(base_url + 'introduction', post_data) content = resp.get_data(True) self.assertNotRegex(content, 'Previous') post_data = { "ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c": " Bacon", "action[save_continue]": "Save & Continue" } resp_url, resp = self.postRedirectGet(block_one_url, post_data) content = resp.get_data(True) self.assertFalse(resp_url.endswith('thank-you')) self.assertIn('Previous', content)
def test_previous_link_doesnt_appear_on_thank_you(self): base_url = '/questionnaire/test/final_confirmation/789/' # Given token = create_token('final_confirmation', 'test') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When # We proceed through the questionnaire post_data = {'action[start_questionnaire]': 'Start Questionnaire'} block_one_url, resp = self.postRedirectGet(base_url + 'introduction', post_data) post_data = { "ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c": " Bacon", "action[save_continue]": "Save and continue" } self.postRedirectGet(block_one_url, post_data) post_data = {"action[save_continue]": "Submit answers"} final_url, resp = self.postRedirectGet(base_url + 'submit-answers', post_data) content = resp.get_data(True) self.assertTrue(final_url.endswith('thank-you')) self.assertNotIn('Previous', content)
def test_invalid_same_date(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(resp.status_code, 200) form_data = { # Start Date "period-from-day": "01", "period-from-month": "1", "period-from-year": "2016", # End Date "period-to-day": "01", "period-to-month": "1", "period-to-year": "2016", # Total Turnover "total-retail-turnover": "10000", # User action "action[save_continue]": "Save & Continue" } # We submit the form with the dates the same resp = self.client.post(mci_test_urls.MCI_0205_BLOCK1, data=form_data, follow_redirects=True) self.assertEqual(resp.status_code, 200) content = resp.get_data(True) self.assertRegex( content, "The 'period to' date must be different to the 'period from' date." )
def test_final_confirmation_asked_at_end_of_questionnaire(self): base_url = '/questionnaire/test/final_confirmation/789/' # Given token = create_token('final_confirmation', 'test') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When # We proceed through the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(base_url + 'introduction', data=post_data, follow_redirects=False) self.assertEqual(resp.status_code, 302) block_one_url = resp.location post_data = { "ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c": " Bacon", "action[save_continue]": "Save & Continue" } resp = self.client.post(block_one_url, data=post_data, follow_redirects=False) self.assertEqual(resp.status_code, 302) # Then # we are presented with a confirmation page self.assertTrue("confirmation" in resp.location) self.assertEqual(resp.status_code, 302) resp = self.client.get(resp.location, follow_redirects=False) self.assertEqual(resp.status_code, 200)
def test_skip_question_errors(self): # Given on the page with skip question with skip condition token = create_token('skip_condition', 'test') self.client.get('/session?token=' + token.decode(), follow_redirects=True) post_data = {'action[start_questionnaire]': 'Start Questionnaire'} self.client.post( '/questionnaire/test/skip_condition/201604/789/introduction', data=post_data, follow_redirects=True) post_data = { 'food-answer': 'Bacon', 'action[save_continue]': 'Save & Continue' } self.client.post( '/questionnaire/test/skip_condition/201604/789/breakfast/0/food-block', data=post_data, follow_redirects=True) # When submit no answers which is invalid post_data = {'action[save_continue]': 'Save & Continue'} resp = self.client.post( '/questionnaire/test/skip_condition/789/breakfast/0/drink-block', data=post_data) # Then errors exists on page self.assertEqual(resp.status_code, 200) self.assertRegex(resp.get_data(True), 'This page has 1 errors')
def test_submission_with_errors(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Introduction</title>') self.assertRegexpMatches(content, '>Start survey<') self.assertRegexpMatches(content, 'Monthly Business Survey - Retail Sales Index') # We proceed to the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(mci_test_urls.MCI_0205_INTRODUCTION, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] resp = self.client.get(block_one_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are in the Questionnaire content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Survey</title>') self.assertRegexpMatches(content, '>Monthly Business Survey - Retail Sales Index</') self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") self.assertRegexpMatches(content, ">Save and continue<") form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "01", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "4", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "30", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "abc", # User Action "action[save_continue]": "Save & Continue" } resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We submit our answers post_data = { "action[submit_answers]": "Submit answers" } resp = self.client.post(mci_test_urls.MCI_0205_SUBMIT, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) self.assertRegexpMatches(resp.headers['Location'],block_one_url) resp = self.client.get(resp.headers['Location'], follow_redirects=True) self.assertEquals(resp.status_code, 200)
def start_questionnaire(self): self.token = create_token('star_wars', '0') self.client.get('/session?token=' + self.token.decode(), follow_redirects=True) post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(star_wars_test_urls.STAR_WARS_INTRODUCTION, data=post_data, follow_redirects=False) return resp
def test_login_with_valid_token_no_eq_id_and_form_type(self): # Given token = create_token('', '') # When self.get('/session?token=' + token.decode()) # Then self.assertStatusNotFound()
def setUp(self): super().setUp() self.token = create_token('percentage', 'test') self.client.get('/session?token=' + self.token.decode(), follow_redirects=True) resp = self.client.post('/questionnaire/test/percentage/789/introduction', data={'action[start_questionnaire]': 'Start Questionnaire'}, follow_redirects=False) self.first_page = resp.location
def start_questionnaire(self): token = create_token('star_wars', '0') self.client.get('/session?token=' + token.decode(), follow_redirects=True) post_data = {'action[start_questionnaire]': 'Start Questionnaire'} resp = self.client.post(star_wars_test_urls.STAR_WARS_INTRODUCTION, data=post_data, follow_redirects=False) return resp
def test_flask_toolbar_is_displayed(self): token = create_token('star_wars', '0') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(resp.status_code, 200) content = resp.get_data(True) self.assertTrue("flDebugToolbarHandle" in content, "The page does not contain the Flask toolbar")
def test_login_with_valid_token_should_redirect_to_survey(self): # Given token = create_token('0205', '1') # When resp = self.client.get('/session?token=' + token.decode(), follow_redirects=False) # Then self.assertEquals(resp.status_code, 302) self.assertRegex(resp.location, '/questionnaire/1/0205')
def test_google_analytics_code_is_present(self): token = create_token('star_wars', '0') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEqual(resp.status_code, 200) content = resp.get_data(True) self.assertTrue("GoogleAnalyticsObject" in content, "The page does not contain the GoogleAnalyticsObject")
def test_login_with_valid_token_should_redirect_to_survey(self): # Given token = create_token('0205', '1') # When resp = self.client.get('/session?token=' + token.decode(), follow_redirects=False) # Then self.assertEqual(resp.status_code, 302) self.assertRegex(resp.location, '/questionnaire/1/0205')
def test_login_with_valid_token_should_redirect_to_survey(self): # Given token = create_token('0205', '1') # When self.get('/session?token=' + token.decode()) # Then self.assertStatusOK() self.assertInUrl('/questionnaire/1/0205')
def test_get_invalid_questionnaire_location_shows_error_page(self): # Given token = create_token('0205', '1') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When resp = self.client.get(mci_test_urls.MCI_0205_BASE + 'test', follow_redirects=False) # Then self.assertEquals(resp.status_code, 500) self.assertRegex(resp.get_data(as_text=True), 'Error 500')
def test_previous_link_doesnt_appear_on_introduction(self): # Given token = create_token('final_confirmation', 'test') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When we open the introduction content = resp.get_data(True) # Then previous link does not appear self.assertNotIn('Previous', content)
def test_login_with_token_twice_is_authorised_when_no_jti(self): # Given token = create_token('0205', '1', jti=None) self.get('/session?token=' + token.decode()) # When self.get('/session?token=' + token.decode()) # Then self.assertStatusOK() self.assertInUrl('/questionnaire/1/0205')
def setUp(self): super(TestRepeatingHousehold, self).setUp() self.token = create_token('repeating_household', 'test') self.client.get('/session?token=' + self.token.decode(), follow_redirects=True) resp = self.client.post( self.INTRODUCTION_PAGE, data={'action[start_questionnaire]': 'Start Questionnaire'}, follow_redirects=False) self.first_page = resp.location
def test_login_with_token_twice_is_unauthorised_when_same_jti_provided( self): # Given token = create_token('0205', '1') self.get('/session?token=' + token.decode()) # When self.get('/session?token=' + token.decode()) # Then self.assertStatusUnauthorised()
def test_multiple_surveys_open(self): # We start the first survey first_survey_token = create_token('0205', '1') self.client.get('/session?token=' + first_survey_token.decode(), follow_redirects=True) post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } first_survey_resp = self.client.post('/questionnaire/1/0205/789/introduction', data=post_data, follow_redirects=False) self.assertRegex(first_survey_resp.location, r'\/questionnaire\/1\/0205\/789\/mci\/0\/reporting-period$') # We start the second survey second_survey_token = create_token('0203', '1') self.client.get('/session?token=' + second_survey_token.decode(), follow_redirects=True) post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } second_survey_resp = self.client.post('/questionnaire/1/0203/789/introduction', data=post_data, follow_redirects=False) self.assertRegex(second_survey_resp.location, r'\/questionnaire\/1\/0203\/789\/mci\/0\/reporting-period') # We now try to post to the first survey, which is out of date form_data = { "period-from-day": "01", "period-from-month": "4", "period-from-year": "2016", "period-to-day": "30", "period-to-month": "04", "period-to-year": "2016", "total-retail-turnover": "100000", "action[save_continue]": "Save & Continue" } multiple_survey_resp = self.client.post(first_survey_resp.location, data=form_data, follow_redirects=False) content = multiple_survey_resp.get_data(True) self.assertRegex(content, 'Information') self.assertRegex(content, 'Unfortunately you can only complete one survey at a time.') self.assertRegex(content, 'Close this window to continue with your current survey.')
def launchSurvey(self, eq_id='test', form_type_id='radio', **payload_kwargs): """ Launch a survey as an authenticated user and follow re-directs :param eq_id: The id of the survey to launch e.g. 'census', 'test' etc. :param form_type_id: The form type of the survey e.g. 'household', 'radio' etc. """ token = create_token(form_type_id=form_type_id, eq_id=eq_id, **payload_kwargs) self.get('/session?token=' + token.decode())
def test_get_block_with_non_block_id_shows_not_found(self): # Given token = create_token('0205', '1') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When resp = self.client.get(mci_test_urls.MCI_0205_BASE + 'mci/0/period-to', follow_redirects=False) # Then self.assertEqual(resp.status_code, 404) self.assertRegex(resp.get_data(as_text=True), 'Error 404')
def test_get_invalid_questionnaire_location_shows_error_page(self): # Given token = create_token('0205', '1') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When resp = self.client.get(mci_test_urls.MCI_0205_BASE + 'some_group/0/test', follow_redirects=False) # Then self.assertEqual(resp.status_code, 404) self.assertRegex(resp.get_data(as_text=True), 'Error 404')
def test_should_not_remove_answers_when_yes_answer(self): with patch('app.views.questionnaire.get_answer_store' ) as get_answer_store: # Given self.token = create_token('household', 'census') self.client.get('/session?token=' + self.token.decode(), follow_redirects=True) answer = {'permanent-or-family-home-answer': 'Yes'} # When self.client.post( '/questionnaire/census/household/789/who-lives-here/0/permanent-or-family-home', data=answer) # Then assert get_answer_store().remove.call_count == 0
def test_save_sign_out_complete_a_block_then_revist_it(self): # If a user completes a block, but then goes back and uses save and come back on that block, that block # should no longer be considered complete and on re-authenticate it should return to it base_url = '/questionnaire/1/0102/789/' token = create_token('0102', '1') self.client.get('/session?token=' + token.decode(), follow_redirects=False) post_data = {'action[start_questionnaire]': 'Start Questionnaire'} resp = self.client.post(base_url + 'introduction', data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] post_data = { "period-from-day": "01", "period-from-month": "4", "period-from-year": "2016", "period-to-day": "30", "period-to-month": "4", "period-to-year": "2016", "action[save_continue]": "Save & Continue" } resp = self.client.post(block_one_url, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # We go back to the first page and save and complete later self.client.get(block_one_url, follow_redirects=False) post_data = {"action[save_sign_out]": "Save and sign out"} self.client.post(block_one_url, data=post_data, follow_redirects=False) # We re-authenticate and check we are on the first page resp = self.client.get('/session?token=' + token.decode(), follow_redirects=False) block_one_url = resp.headers['Location'] self.assertRegexpMatches(block_one_url, 'reporting-period')
def test_should_remove_household_composition_answer_when_no_answer(self): with patch('app.views.questionnaire.get_answer_store' ) as get_answer_store: # Given self.token = create_token('household', 'census') self.client.get('/session?token=' + self.token.decode(), follow_redirects=True) answer = {'permanent-or-family-home-answer': 'No'} # When self.client.post( '/questionnaire/census/household/789/who-lives-here/0/permanent-or-family-home', data=answer) # Then get_answer_store().assert_has_calls([ call.remove(block_id='household-composition', group_id='who-lives-here') ])
def test_empty_questionnaire(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=False) self.assertEqual(resp.status_code, 302) intro_page_url = resp.location # Navigate to the Introduction Page resp = self.client.get(intro_page_url, follow_redirects=False) self.assertEqual(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegex(content, '>Start survey<') post_data = {'action[start_questionnaire]': "Submit Answers"} # Submit the Introduction page to get the first question page resp = self.client.post(intro_page_url, data=post_data, follow_redirects=False) self.assertEqual(resp.status_code, 302) first_question_page = resp.location # We try to access the submission page without entering anything resp = self.client.get(mci_test_urls.MCI_0205_SUMMARY, follow_redirects=False) self.assertEqual(resp.status_code, 302) # Check we are redirected back to the questionnaire self.assertEqual(resp.location, first_question_page) # We try posting to the submission page without our answers post_data = {'action[submit_answers]': "Submit Answers"} resp = self.client.post(mci_test_urls.MCI_0205_SUBMIT, data=post_data, follow_redirects=False) self.assertEqual(resp.status_code, 302) # Check we are redirected back to the questionnaire self.assertEqual(resp.location, first_question_page)
def test_requesting_final_confirmation_before_finished_redirects(self): base_url = '/questionnaire/test/final_confirmation/789/' # Given token = create_token('final_confirmation', 'test') self.client.get('/session?token=' + token.decode(), follow_redirects=False) # When # We proceed through the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(base_url + 'introduction', data=post_data, follow_redirects=False) self.assertEqual(resp.status_code, 302) block_one_url = resp.location resp = self.client.get(base_url + 'confirmation', follow_redirects=False) self.assertEqual(resp.location, block_one_url) self.assertEqual(resp.status_code, 302)
def test_empty_questionnaire(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=False) self.assertEquals(resp.status_code, 302) intro_page_url = resp.headers['Location'] # Navigate to the Introduction Page resp = self.client.get(intro_page_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, '>Start survey<') post_data = { 'action[start_questionnaire]': "Submit Answers" } # Submit the Introduction page to get the first question page resp = self.client.post(intro_page_url, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) first_question_page = resp.headers['Location'] # We try to access the submission page without entering anything resp = self.client.get(mci_test_urls.MCI_0205_SUMMARY, follow_redirects=False) self.assertEquals(resp.status_code, 302) # Check we are redirected back to the questionnaire self.assertEqual(resp.headers['Location'], first_question_page) # We try posting to the submission page without our answers post_data = { 'action[submit_answers]': "Submit Answers" } resp = self.client.post(mci_test_urls.MCI_0205_SUBMIT, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # Check we are redirected back to the questionnaire self.assertEqual(resp.headers['Location'], first_question_page)
def happy_path(self, form_type_id, eq_id): # Get a token token = create_token(form_type_id, eq_id) resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Introduction</title>') self.assertRegexpMatches(content, '>Start survey<') self.assertRegexpMatches(content, 'Monthly Business Survey - Retail Sales Index') # We proceed to the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post('/questionnaire/' + eq_id + '/' + form_type_id + '/201604/789/introduction', data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] resp = self.client.get(block_one_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are in the Questionnaire content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Survey</title>') self.assertRegexpMatches(content, '>Monthly Business Survey - Retail Sales Index</') self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") self.assertRegexpMatches(content, ">Save and continue<") # We fill in our answers form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "01", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "4", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "30", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "100000", # User Action "action[save_continue]": "Save & Continue" } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # There are no validation errors self.assertRegexpMatches(resp.headers['Location'], r'\/questionnaire\/1/' + form_type_id + '\/201604\/789\/summary$') summary_url = resp.headers['Location'] resp = self.client.get(summary_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are on the review answers page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Summary</title>') self.assertRegexpMatches(content, '>Monthly Business Survey - Retail Sales Index</') self.assertRegexpMatches(content, '>Your responses<') self.assertRegexpMatches(content, 'Please check carefully before submission') self.assertRegexpMatches(content, '>Submit answers<')
def test_empty_comments(self): # Get a token token = create_token('0203', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Introduction</title>') self.assertRegexpMatches(content, '>Start survey<') self.assertRegexpMatches(content, 'Monthly Business Survey - Retail Sales Index') # We proceed to the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(mci_test_urls.MCI_0203_INTRODUCTION, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] resp = self.client.get(block_one_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are in the Questionnaire content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Survey</title>') self.assertRegexpMatches(content, '>Monthly Business Survey - Retail Sales Index</') self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") self.assertRegexpMatches(content, ">Save and continue<") # We fill in our answers form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "01", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "4", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "30", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "100000", # User Action "action[save_continue]": "Save & Continue", # Empty comment "215015b1-f87c-4740-9fd4-f01f707ef558": " " } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # There are no validation errors self.assertRegexpMatches(resp.headers['Location'], mci_test_urls.MCI_0203_SUMMARY_REGEX) summary_url = resp.headers['Location'] resp = self.client.get(summary_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are on the review answers page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Summary</title>') self.assertRegexpMatches(content, '>Monthly Business Survey - Retail Sales Index</') self.assertRegexpMatches(content, '>Your responses<') self.assertRegexpMatches(content, 'Please check carefully before submission') self.assertRegexpMatches(content, '>Submit answers<') # We submit our answers post_data = { "action[submit_answers]": "Submit answers" } resp = self.client.post(summary_url, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) self.assertRegexpMatches(resp.headers['Location'], mci_test_urls.MCI_0203_THANKYOU_REGEX) resp = self.client.get(resp.headers['Location'], follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the thank you page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Submission Successful</title>') self.assertRegexpMatches(content, '(?s)Monthly Business Survey - Retail Sales Index.*?Monthly Business Survey - Retail Sales Index')
def login_and_check_introduction_text(self): self.token = create_token('star_wars', '0') resp = self.get_first_page() self.check_introduction_text(resp)
def rogue_one_login_and_check_introduction_text(self): self.token = create_token('rogue_one', '0') response = self.get_first_page() self.rogue_one_check_introduction_text(response)
def empty_submission(self, form_type_id, eq_id): # Get a token token = create_token(form_type_id, eq_id) resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Introduction</title>') self.assertRegexpMatches(content, '>Start survey<') self.assertRegexpMatches(content, 'Monthly Business Survey - Retail Sales Index') # We proceed to the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(mci_test_urls.MCI_0205_INTRODUCTION, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # We proceed to the questionnaire resp = self.client.get(mci_test_urls.MCI_0205_BLOCK1, follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are in the Questionnaire content = resp.get_data(True) self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") self.assertRegexpMatches(content, ">Save and continue<") form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "", # User action "action[save_continue]": "Save & continue" } # We submit the form without data resp = self.client.post(mci_test_urls.MCI_0205_BLOCK1, data=form_data, follow_redirects=True) self.assertEquals(resp.status_code, 200) content = resp.get_data(True) self.assertRegexpMatches(content, "The date entered is not valid. Please correct your answer.") self.assertRegexpMatches(content, "Please provide a value, even if your value is 0.") # We try to access the submission page without correction resp = self.client.get(mci_test_urls.MCI_0205_SUMMARY, follow_redirects=True) self.assertEquals(resp.status_code, 200) content = resp.get_data(True) self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "01", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "04", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "30", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "100000", # User action "action[save_continue]": "Save & continue" } # We correct our answers and submit resp = self.client.post(mci_test_urls.MCI_0205_BLOCK1, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # There are no validation errors self.assertRegexpMatches(resp.headers['Location'], mci_test_urls.MCI_0205_SUMMARY_REGEX) resp = self.client.get(resp.headers['Location'], follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the review answers page content = resp.get_data(True) self.assertRegexpMatches(content, '>Your responses<') self.assertRegexpMatches(content, 'Please check carefully before submission') self.assertRegexpMatches(content, '>Submit answers<') # We submit our answers post_data = { 'action[submit_answers]': "Submit Answers" } resp = self.client.post(mci_test_urls.MCI_0205_SUMMARY, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) self.assertRegexpMatches(resp.headers['Location'], mci_test_urls.MCI_0205_THANKYOU_REGEX) resp = self.client.get(resp.headers['Location'], follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the thank you page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Submission Successful</title>')
def setUp(self): super().setUp() self.token = create_token('hh2016', '0')
def setUp(self): super().setUp() self.token = create_token('star_wars', '0')
def test_non_mandatory_error_to_empty_value(self): # Get a token token = create_token('0203', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We proceed to the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(mci_test_urls.MCI_0203_INTRODUCTION, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] resp = self.client.get(block_one_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We fill in our answers, generating a error in a non-mandatory field form_data = { # Start Date "bb8168e6-2272-450d-b5a7-d3170508efb2": "01", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "04", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "01", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2017", # Non Mandatory field but fails validation as should be Integer "e81adc6d-6fb0-4155-969c-d0d646f15345" : "failing test", # User Action "action[save_continue]": "Save & Continue" } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 200) # Get the page content content = resp.get_data(True) self.assertRegexpMatches(content, "Please only enter whole numbers into the field") # We remove the non-mandatory field value form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "01", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "4", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "30", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "100000", # User Action "action[save_continue]": "Save & Continue" } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) # There are no validation errors self.assertRegexpMatches(resp.headers['Location'], mci_test_urls.MCI_0203_SUMMARY_REGEX)
def test_clear_value(self): # Get a token token = create_token('0205', '1') resp = self.client.get('/session?token=' + token.decode(), follow_redirects=True) self.assertEquals(resp.status_code, 200) # We are on the landing page content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Introduction</title>') self.assertRegexpMatches(content, '>Start survey<') self.assertRegexpMatches(content, 'Monthly Business Survey - Retail Sales Index') # We proceed to the questionnaire post_data = { 'action[start_questionnaire]': 'Start Questionnaire' } resp = self.client.post(mci_test_urls.MCI_0205_INTRODUCTION, data=post_data, follow_redirects=False) self.assertEquals(resp.status_code, 302) block_one_url = resp.headers['Location'] resp = self.client.get(block_one_url, follow_redirects=False) self.assertEquals(resp.status_code, 200) # We are in the Questionnaire content = resp.get_data(True) self.assertRegexpMatches(content, '<title>Survey</title>') self.assertRegexpMatches(content, '>Monthly Business Survey - Retail Sales Index</') self.assertRegexpMatches(content, "What are the dates of the sales period you are reporting for\?") self.assertRegexpMatches(content, ">Save and continue<") # check with have some guidance self.assertRegexpMatches(content, "alcoholic drink") # We fill in our answers using an incorrect date range # This is to ensure that our valid retail total gets stored # but that we do not proceed to the next page form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "30", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "4", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "01", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "100000", # Valid value # User Action "action[save_continue]": "Save & Continue" } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 200) # Get the page content content = resp.get_data(True) self.assertRegexpMatches(content, "The 'period to' date cannot be before the 'period from' date.") # Fill the dates incorrectly again, but this time supply an invalid value for retail total form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "30", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "04", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "01", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "Invalid Retail Total", # User action "action[save_continue]": "Save & Continue" } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 200) # Get the page content again content = resp.get_data(True) self.assertRegexpMatches(content, "The 'period to' date cannot be before the 'period from' date.") self.assertRegexpMatches(content, "Please only enter whole numbers into the field.") self.assertNotRegex(content, '100000') # We have cleared the valid value self.assertRegexpMatches(content, 'Invalid Retail Total') # Our invalid value is redisplayed # Fill the dates incorrectly again, but this time supply an valid value for retail total form_data = { # Start Date "6fd644b0-798e-4a58-a393-a438b32fe637-day": "30", "6fd644b0-798e-4a58-a393-a438b32fe637-month": "04", "6fd644b0-798e-4a58-a393-a438b32fe637-year": "2016", # End Date "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-day": "01", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-month": "04", "06a6a4b7-6ce4-4687-879d-3443cd8e2ff0-year": "2016", # Total Turnover "e81adc6d-6fb0-4155-969c-d0d646f15345": "1000", # User action "action[save_continue]": "Save & Continue" } # We submit the form resp = self.client.post(block_one_url, data=form_data, follow_redirects=False) self.assertEquals(resp.status_code, 200) # Get the page content again content = resp.get_data(True) self.assertRegexpMatches(content, "The 'period to' date cannot be before the 'period from' date.") self.assertNotRegex(content, "Please only enter whole numbers into the field.") # Our message has gone self.assertNotRegex(content, 'Invalid Retail Total') # Our invalid value has gone self.assertRegexpMatches(content, '1000') # Our new valid value is redisplayed