Example #1
0
    def test_should_raise_error_in_validate_token(self,
                                                  build_keystone_url_mock,
                                                  check_user_token_mock):
        """
        Should raise exception with json error in validate token and retry check token
        :param mock:
        :param build_keystone_url_mock:
        :param check_user_token_mock:
        :return:
        """
        # Given
        build_keystone_url_mock.return_value = 'http://fake_url/v2.0'

        error_json = '{"error": {"message":"The request you have made requires authentication."}}'

        check_user_token_mock.side_effect = Exception(error_json)
        access_token = 'f81de7d47c00449380cc6c2ac3a7b81e'
        # When
        try:
            validate_token(access_token)
        except Exception as ex:
            # Then
            self.assertEqual(
                'The request you have made requires authentication.',
                json.loads(ex.args[0])['error']['message'])
Example #2
0
    def test_should_raise_error_in_validate_token_and_retry_with_successfully_result(
            self, build_keystone_url_mock, check_user_token_mock):
        """
        Should raise exception with json error in validate token and retry check token with successfully result
        :param mock:
        :param build_keystone_url_mock:
        :param check_user_token_mock:
        :return:
        """
        # Given
        build_keystone_url_mock.return_value = 'http://fake_url/v2.0'

        error_json = '{"error": {"message":"The request you have made requires authentication."}}'
        result_token = TokenModel(expires='expires',
                                  id='id',
                                  username='******')

        check_user_token_mock.side_effect = [
            Exception(error_json), result_token
        ]
        access_token = 'f81de7d47c00449380cc6c2ac3a7b81e'
        # When
        token = validate_token(access_token)

        # Then
        self.assertEqual(token.username, 'the_username')
    def test_should_raise_error_in_validate_token(self, build_keystone_url_mock, check_user_token_mock):
        """
        Should raise exception with json error in validate token and retry check token
        :param mock:
        :param build_keystone_url_mock:
        :param check_user_token_mock:
        :return:
        """
        # Given
        build_keystone_url_mock.return_value = 'http://fake_url/v2.0'

        error_json = '{"error": {"message":"The request you have made requires authentication."}}'

        check_user_token_mock.side_effect = Exception(error_json)
        access_token = 'f81de7d47c00449380cc6c2ac3a7b81e'
        # When
        try:
            validate_token(access_token)
        except Exception as ex:
            # Then
            self.assertEqual('The request you have made requires authentication.', json.loads(ex.args[0])['error'][
                'message'])
    def test_should_raise_error_in_validate_token_and_retry_with_successfully_result(self, build_keystone_url_mock,
                                                                                     check_user_token_mock):
        """
        Should raise exception with json error in validate token and retry check token with successfully result
        :param mock:
        :param build_keystone_url_mock:
        :param check_user_token_mock:
        :return:
        """
        # Given
        build_keystone_url_mock.return_value = 'http://fake_url/v2.0'

        error_json = '{"error": {"message":"The request you have made requires authentication."}}'
        result_token = TokenModel(expires='expires', id='id', username='******')

        check_user_token_mock.side_effect = [Exception(error_json), result_token]
        access_token = 'f81de7d47c00449380cc6c2ac3a7b81e'
        # When
        token = validate_token(access_token)

        # Then
        self.assertEqual(token.username, 'the_username')