Beispiel #1
0
    def test_should_stop_the_request_when_token_fails(self, request, post):
        post.return_value = Mock(status_code=500, ok=False)

        client = Client(token_endpoint=self.end_point,
                        client_id='client_id',
                        client_secret='client_secret')

        response = client.request('GET', self.resource_url)

        self.assertEqual(response.status_code, 500)
Beispiel #2
0
    def test_should_stop_the_request_when_token_fails(self, request, post):
        post.return_value = Mock(status_code=500, ok=False)

        client = Client(
            token_endpoint=self.end_point,
            client_id='client_id',
            client_secret='client_secret'
        )

        response = client.request('GET', self.resource_url)

        self.assertEqual(response.status_code, 500)
Beispiel #3
0
    def test_should_reset_token_when_gets_an_unauthorized_error(
            self, request, reset_token, _has_token):
        request.return_value = Mock(status_code=401)
        _has_token.return_value = True

        client = Client(token_endpoint=self.end_point,
                        client_id='client_id',
                        client_secret='client_secret')

        response = client.request('GET', self.resource_url)

        self.assertTrue(reset_token.called)

        self.assertEqual(response.status_code, 401)
Beispiel #4
0
    def test_should_reset_token_when_gets_an_unauthorized_error(self, request, reset_token, _has_token):
        request.return_value = Mock(status_code=401)
        _has_token.return_value = True

        client = Client(
            token_endpoint=self.end_point,
            client_id='client_id',
            client_secret='client_secret'
        )

        response = client.request('GET', self.resource_url)

        self.assertTrue(reset_token.called)

        self.assertEqual(response.status_code, 401)
Beispiel #5
0
    def test_token_manager_object_should_be_an_instance_of_token_manager_class(
            self):
        client = Client(token_endpoint=self.end_point,
                        client_id='client-id',
                        client_secret='client_secret')

        self.assertTrue(
            isinstance(client._token_manager, client.token_manager_class))
Beispiel #6
0
    def get_alf_client(self):
        # alf is an OAuth 2 Client
        # https://github.com/globocom/alf
        alf = Client(token_endpoint=self.token_endpoint,
                     client_id=self.client_id,
                     client_secret=self.client_secret)

        return alf
Beispiel #7
0
    def test_should_have_token_request_timeout(self, init):
        init.return_value = None

        client = Client(token_endpoint=self.end_point,
                        client_id='client_id',
                        client_secret='client_secret',
                        token_request_params={'timeout': 10})

        init.assert_called_with(client_id='client_id',
                                client_secret='client_secret',
                                token_endpoint=self.end_point,
                                token_request_params={'timeout': 10},
                                token_retries=None,
                                token_storage=None)