def test_post_makes_post_request_to_given_endpoint(requests_mock: RequestsMock) -> None: requests_mock.add(requests_mock.POST, API_BASE_URL + "endpoint", '{ "success": true }') api = APIClient(mock.Mock(), "123", "456") api.post("endpoint") assert len(requests_mock.calls) == 1 assert requests_mock.calls[0].request.url == API_BASE_URL + "endpoint"
def test_post_sets_body_of_request_as_form_data(requests_mock: RequestsMock) -> None: requests_mock.add(requests_mock.POST, API_BASE_URL + "endpoint", '{ "success": true }') api = APIClient(mock.Mock(), "123", "456") api.post("endpoint", {"key1": "value1", "key2": "value2"}, data_as_json=False) assert len(requests_mock.calls) == 1 assert requests_mock.calls[0].request.url == API_BASE_URL + "endpoint" assert requests_mock.calls[0].request.body == "key1=value1&key2=value2"
def test_post_sets_body_of_request_as_json(requests_mock: RequestsMock) -> None: requests_mock.add(requests_mock.POST, API_BASE_URL + "endpoint", '{ "success": true }') api = APIClient(mock.Mock(), "123", "456") api.post("endpoint", {"key1": "value1", "key2": "value2"}) assert len(requests_mock.calls) == 1 assert requests_mock.calls[0].request.url == API_BASE_URL + "endpoint" body = json.loads(requests_mock.calls[0].request.body) assert body["key1"] == "value1" assert body["key2"] == "value2"