예제 #1
0
    def test_thank_you(self, user_details_mock, is_session_valid_mock):
        """Test correct text is displayed if user has opted_out"""
        headers = {'Content-type': 'application/json', 'cookie': common.SESSION_ID}
        userDetails = common.get_user_details()

        test_cases = [
            # (is_session_valid, opted_out, flask_session, expected_status, expected_text, expected_text_id, expected_location)
            (True,  'active',   {'is_successfully_stored': True},  HTTPStatus.OK,    'will not be used', 'not-shared', None),
            (True,  'inactive', {'is_successfully_stored': True},  HTTPStatus.OK,    'can be used',      'shared',     None),
            (True,  'active',   {'is_successfully_stored': False}, HTTPStatus.FOUND, None, None, routes.get_absolute('yourdetails.choice_not_saved')),
            (True,  'inactive', {'is_successfully_stored': False}, HTTPStatus.FOUND, None, None, routes.get_absolute('yourdetails.choice_not_saved')),
            (False, 'inactive', {},                                HTTPStatus.OK, 'Sorry, you\'ll have to start again', 'mainBody', None),
            (True,  'inactive', {},                                HTTPStatus.OK, 'Sorry, you\'ll have to start again', 'mainBody', None),
        ]


        for case in test_cases:
            is_session_valid, opted_out, flask_session, expected_status, expected_text, \
                expected_text_id, expected_location = case
            with self.subTest(case=case):
                userDetails["opted_out"] = opted_out
                user_details_mock.return_value = userDetails
                is_session_valid_mock.return_value = is_session_valid

                common.set_session_data(self.client, flask_session)

                result = self.client.get(routes.get_raw('yourdetails.thank_you'), headers=headers)

                self.assertEqual(result.status_code, expected_status)
                
                if expected_text:
                    doc = common.html(result)
                    self.assertIn(expected_text, str(doc.find(id=expected_text_id)))
                if expected_location:
                    self.assertIn(expected_location, result.headers['Location'])
예제 #2
0
    def test_review_your_choice_no(self, is_session_valid_mock, **kwargs):
        is_session_valid_mock.return_value = True
        mock = kwargs['mock']
        adapter = mock.get(self.app.config['GET_CONFIRMATION_DELIVERY_METHOD'],
                           text=confirmation_delivery_method_callback)
        expected_choice = 'cannot'
        user_details = common.get_user_details()
        user_details['opted_out'] = 'active'
        common.update_session_data(self.client, user_details)
        result = self.client.get('/reviewyourchoice')

        assert HTTPStatus(result.status_code) == HTTPStatus.OK
        doc = common.html(result)
        choice = doc.find(id='choice').text.strip()
        assert choice == expected_choice
예제 #3
0
    def test_review_your_choice_redirects_to_genericerror(
            self, confirmation_delivery_mock, _, **kwargs):

        confirmation_delivery_mock.return_value = None

        mock = kwargs['mock']
        adapter = mock.get(self.app.config['GET_CONFIRMATION_DELIVERY_METHOD'],
                           text=confirmation_delivery_method_callback)
        user_details = common.get_user_details()
        user_details['opted_out'] = 'active'
        common.set_session_data(self.client, user_details)
        result = self.client.get(
            routes.get_raw('yourdetails.review_your_choice'))

        assert HTTPStatus(result.status_code) == HTTPStatus.FOUND
        assert routes.get_absolute(
            'main.generic_error') == result.headers['Location']