def test_logging_post(self, mocker, requests_mock): logging_debug_mock = mocker.patch.object(logging.Logger, 'debug') logging_error_mock = mocker.patch.object(logging.Logger, 'error') requests_mock.post("https://demo.dev/1", [ dict(status_code=200, json=dict(hello="fish")), dict(status_code=200, json=dict(hello="bear")), ]) conn = Connector("https://demo.dev", "user", "pass") conn.post("/1", payload=dict(iam="cat")) logging_error_mock.assert_not_called() logging_debug_mock.assert_has_calls([ mocker.call('{"request": {' '"method": "POST", "base_url": "https://demo.dev", ' '"path": "/1", "payload": {"iam": "cat"}}' '}'), mocker.call('POST https://demo.dev/1 200'), mocker.call( '{"request_data": ' '{"method": "POST", "base_url": "https://demo.dev", "path": "/1"}, ' '"response": {"status_code": 200, "headers": {}, ' '"content": "b\'{\\"hello\\": \\"fish\\"}\'", ' '"json_data": {"hello": "fish"}}' '}') ])
def test_post_empty_payload(self, requests_mock): requests_mock.post("https://demo.dev/post", status_code=200, additional_matcher=lambda r: r.json() == {}) conn = Connector("https://demo.dev", None, None) status, *_ = conn.post("/post", dict()) assert status == 200
def test_post_no_payload(self, requests_mock): requests_mock.post("https://demo.dev/post", status_code=200) conn = Connector("https://demo.dev", None, None) status, *_ = conn.post("/post") assert status == 200