async def test_message_response_json(self): async with MangadexClient() as client: r = await client.request("get", routes["ping"]) with pytest.raises(HTTPException) as exc: raise HTTPException( "GET", routes["ping"], response=r, json={"errors": [{"title": "Test", "detail": "This is a test."}]} ) assert str(exc.value) == "HTTP 200: Test: This is a test."
def test_message_no_response_json_context(self): with pytest.raises(HTTPException) as exc: raise HTTPException( "GET", routes["ping"], response=None, json={"errors": [{"title": "Test", "detail": "This is a test.", "context": {"test": 1}}]}, ) assert str(exc.value) == "Test: This is a test. ({'test': 1})"
def test_subclass(self): assert issubclass(HTTPException, AsyncDexException) assert issubclass(HTTPException, ClientResponseError) exc = HTTPException("a", "a", None) assert isinstance(exc, AsyncDexException) assert isinstance(exc, ClientResponseError) with pytest.raises(HTTPException): raise exc with pytest.raises(AsyncDexException): raise exc with pytest.raises(ClientResponseError): raise exc
def test_message_no_response(self): with pytest.raises(HTTPException) as exc: raise HTTPException("GET", "/test", None) assert str(exc.value) == "HTTP Error on GET for /test."
def test_message_no_locals(self): with pytest.raises(KeyError): HTTPException("None", "None", None, msg="{i_do_not_exist}")
def test_message_custom_locals(self): with pytest.raises(HTTPException) as exc: raise HTTPException("None", "None", None, msg="{method}: {path}") assert str(exc.value) == "None: None"
def test_message_custom_no_locals(self): with pytest.raises(HTTPException) as exc: raise HTTPException("None", "None", None, msg="Test") assert str(exc.value) == "Test"