コード例 #1
0
    def test_without_authorization(self):
        responses.add(responses.GET, "http://example.com", json={})

        resp = AuthApiClient().get("http://example.com")
        assert resp.status_code == 200

        request = responses.calls[-1].request
        assert not request.headers.get("Authorization")
コード例 #2
0
    def test_with_authorization_and_no_auth(self):
        responses.add(responses.GET, "http://example.com", json={})

        auth = Mock()
        auth.tokens = {"access_token": "access-token"}

        resp = AuthApiClient(auth=auth).get("http://example.com", auth=None)
        assert resp.status_code == 200

        request = responses.calls[-1].request
        assert not request.headers.get("Authorization")
コード例 #3
0
ファイル: test_client.py プロジェクト: xsbchen/sentry-plugins
    def test_with_authorization(self):
        responses.add(responses.GET, 'http://example.com', json={})

        auth = Mock()
        auth.tokens = {
            'access_token': 'access-token',
        }

        resp = AuthApiClient(auth=auth).get('http://example.com')
        assert resp.status_code == 200

        request = responses.calls[-1].request
        assert request.headers.get('Authorization') == 'Bearer access-token'
コード例 #4
0
 def test_unauthorized(self):
     responses.add(responses.GET, "http://example.com", status=404)
     with pytest.raises(ApiError):
         AuthApiClient().get("http://example.com")
コード例 #5
0
 def test_invalid_host(self):
     with pytest.raises(ApiHostError):
         AuthApiClient().get("http://example.com")
コード例 #6
0
 def test_invalid_plaintext(self):
     responses.add(responses.GET, "http://example.com", body="")
     with pytest.raises(UnsupportedResponseType):
         AuthApiClient().get("http://example.com")
コード例 #7
0
 def test_forbidden(self):
     responses.add(responses.GET, "http://example.com", status=401)
     with pytest.raises(ApiUnauthorized):
         AuthApiClient().get("http://example.com")