Пример #1
0
    def test_endpoints_for_token_propogates_errors(self):
        """
        endpoints_for_token propagates API errors.
        """
        response = mock.Mock(code=500)
        self.treq.content.return_value = succeed('error_body')
        self.treq.get.return_value = succeed(response)

        d = endpoints_for_token('http://identity/v2.0', 'auth-token',
                                'user-token')
        failure = self.failureResultOf(d)

        self.assertTrue(failure.check(RequestError))
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, 'error_body')
Пример #2
0
    def test_endpoints_for_token_propogates_errors(self):
        """
        endpoints_for_token propagates API errors.
        """
        response = mock.Mock(code=500)
        self.treq.content.return_value = succeed('error_body')
        self.treq.get.return_value = succeed(response)

        d = endpoints_for_token('http://identity/v2.0', 'auth-token',
                                'user-token')
        failure = self.failureResultOf(d)

        self.assertTrue(failure.check(RequestError))
        real_failure = failure.value.reason

        self.assertTrue(real_failure.check(APIError))
        self.assertEqual(real_failure.value.code, 500)
        self.assertEqual(real_failure.value.body, 'error_body')
Пример #3
0
    def test_endpoints_for_token(self):
        """
        endpoints_for_token sends a properly formed request to the identity
        endpoint.
        """
        response = mock.Mock(code=200)
        response_body = {'endpoints': []}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.get.return_value = succeed(response)

        d = endpoints_for_token('http://identity/v2.0', 'auth-token',
                                'user-token')

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.get.assert_called_once_with(
            'http://identity/v2.0/tokens/user-token/endpoints',
            headers=expected_headers)
Пример #4
0
    def test_endpoints_for_token(self):
        """
        endpoints_for_token sends a properly formed request to the identity
        endpoint.
        """
        response = mock.Mock(code=200)
        response_body = {'endpoints': []}
        self.treq.json_content.return_value = succeed(response_body)
        self.treq.get.return_value = succeed(response)

        d = endpoints_for_token('http://identity/v2.0', 'auth-token',
                                'user-token')

        self.assertEqual(self.successResultOf(d), response_body)

        self.treq.get.assert_called_once_with(
            'http://identity/v2.0/tokens/user-token/endpoints',
            headers=expected_headers)