Esempio n. 1
0
 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
Esempio n. 2
0
 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
Esempio n. 3
0
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()
Esempio n. 4
0
def test__text_when_content_empty__empty_string(builder):
    request = builder.top_artists()
    response = Response(request, 200, {}, b"")

    assert response.text == ""
Esempio n. 5
0
def test__text_when_no_content__none(builder):
    request = builder.top_artists()
    response = Response(request, 200, {}, None)

    assert response.text is None
Esempio n. 6
0
def test__json_when_no_content__none(builder):
    request = builder.top_artists()
    response = Response(request, 200, {}, b"")

    assert response.json is None
Esempio n. 7
0
def test__raise_for_status__500(builder):
    request = builder.top_artists()
    response = Response(request, 500, {}, b"")

    with pytest.raises(SpotifyException):
        response.raise_for_status()
Esempio n. 8
0
def test__raise_for_status__401(builder):
    request = builder.top_artists()
    response = Response(request, 401, {}, b"")

    with pytest.raises(SpotifyUnauthorized):
        response.raise_for_status()
Esempio n. 9
0
def test__raise_for_status__no_error(builder):
    request = builder.top_artists()
    response = Response(request, 200, {}, b"")

    response.raise_for_status()