def test_request_get_sends_headers_with_the_request(): responses.add(responses.GET, BASE_URL, body=json.dumps(dummy_data), status=200, content_type='application/json') api = TwitchAPI(client_id='client') api._request_get('') assert 'Client-ID' in responses.calls[0].request.headers assert 'Accept' in responses.calls[0].request.headers
def test_request_get_raises_exception_if_not_200_response(status, monkeypatch): responses.add( responses.GET, BASE_URL, status=status, content_type="application/json" ) def mockreturn(path): return "tests/api/dummy_credentials.cfg" monkeypatch.setattr(os.path, "expanduser", mockreturn) api = TwitchAPI(client_id="client") with pytest.raises(exceptions.HTTPError): api._request_get("")
def test_request_get_sends_headers_with_the_request(): responses.add( responses.GET, BASE_URL, body=json.dumps(dummy_data), status=200, content_type="application/json", ) api = TwitchAPI(client_id="client") api._request_get("") assert "Client-ID" in responses.calls[0].request.headers assert "Accept" in responses.calls[0].request.headers
def test_request_get_binary_body(): responses.add(responses.GET, BASE_URL, body=b'binary', status=200, content_type='application/octet-stream') api = TwitchAPI(client_id='client') response = api._request_get('', json=False) assert response.content == b'binary'
def test_request_get_returns_dictionary_if_successful(): responses.add(responses.GET, BASE_URL, body=json.dumps(dummy_data), status=200, content_type='application/json') api = TwitchAPI(client_id='client') response = api._request_get('') assert isinstance(response, dict) assert response == dummy_data
def test_request_get_binary_body(): responses.add( responses.GET, BASE_URL, body=b"binary", status=200, content_type="application/octet-stream", ) api = TwitchAPI(client_id="client") response = api._request_get("", json=False) assert response.content == b"binary"