async def request(self, request: Request) -> Response: async with self.session.request( method=request.method, url=request.url, data=request.body, headers=request.headers, ) as resp: response = Response( request, resp.status, resp.headers, await resp.read() ) response.raise_for_status() return response
def request(self, request: Request) -> Response: resp = self.session.request( method=request.method, url=request.url, data=request.body, headers=request.headers, ) response = Response( request, resp.status_code, resp.headers, resp.content ) response.raise_for_status() return response
def test__raise_for_status__403_premium_required(builder): request = builder.top_artists() response = Response( request, 403, {}, byte_body({ "error": { "status": 403, "message": "Player command failed: Premium required", "reason": "PREMIUM_REQUIRED", } }), ) with pytest.raises(SpotifyPremiumRequired): response.raise_for_status()
def test__text_when_content_empty__empty_string(builder): request = builder.top_artists() response = Response(request, 200, {}, b"") assert response.text == ""
def test__text_when_no_content__none(builder): request = builder.top_artists() response = Response(request, 200, {}, None) assert response.text is None
def test__json_when_no_content__none(builder): request = builder.top_artists() response = Response(request, 200, {}, b"") assert response.json is None
def test__raise_for_status__500(builder): request = builder.top_artists() response = Response(request, 500, {}, b"") with pytest.raises(SpotifyException): response.raise_for_status()
def test__raise_for_status__401(builder): request = builder.top_artists() response = Response(request, 401, {}, b"") with pytest.raises(SpotifyUnauthorized): response.raise_for_status()
def test__raise_for_status__no_error(builder): request = builder.top_artists() response = Response(request, 200, {}, b"") response.raise_for_status()