Exemple #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'])
Exemple #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
    def test_set_your_preference_inactive(self, _, **kwargs):
        """ Test set-preference page is inactive when expected """

        mock = kwargs['mock']
        mock.get(self.app.config['PREFERENCE_RESULT_URL'],
                 text=get_preference_results_callback_inactive)

        headers = {
            'Content-type': 'application/json',
            'cookie': common.SESSION_ID
        }
        result = self.client.get('/setyourpreference', headers=headers)

        self.assertEqual(HTTPStatus(result.status_code), HTTPStatus.OK)
        doc = common.html(result)
        self.assertIn('checked', doc.find_all(id='single-opted-in')[0].attrs)
        self.assertNotIn('checked',
                         doc.find_all(id='single-opted-out')[0].attrs)