Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_can_post_request(self):
responses.add(responses.POST, "http://www.foo.com/endpoint")
client = util.ApiClient(
base_uri="http://www.foo.com", config={"version": util.API_VERSION_1}
)
client.post_request("endpoint")
def test_can_get_request(self):
responses.add(responses.GET, "http://www.foo.com/endpoint")
client = util.ApiClient(
base_uri="http://www.foo.com", config={"version": util.API_VERSION_1}
)
client.get_request("endpoint")
def test_can_patch_request(self):
responses.add(responses.PATCH, "http://www.foo.com/endpoint")
client = util.ApiClient(
base_uri="http://www.foo.com", config={"version": util.API_VERSION_1}
)
client.patch_request("endpoint")
def test_can_delete_request_with_dict_data_v2(self):
responses.add(
responses.DELETE, "http://www.foo.com/endpoint",
)
client = util.ApiClient(
base_uri="http://www.foo.com",
config={"version": util.API_VERSION_2, "token": "token"},
)
client.delete_request("endpoint", data={"foo": "bar"})
self.assertEqual(responses.calls[0].request.body, '{"foo": "bar"}')
expected_headers = {
"Authorization": "Bearer token",
}
actual_headers = responses.calls[0].request.headers
self.assertTrue(
set(expected_headers.items()).issubset(set(actual_headers.items()))
)
def test_url_for_returns_complete_url(self):
client = util.ApiClient(base_uri="http://www.foo.com")
self.assertEqual(client.url_for("bar"), "http://www.foo.com/bar")
def test_can_set_base_uri(self):
client = util.ApiClient(base_uri="http://www.foo.com")
client.base_uri = "http://www.bar.com"
self.assertEqual(client.base_uri, "http://www.bar.com")
def test_url_for_ignores_preceding_slash(self):
client = util.ApiClient(base_uri="http://www.foo.com")
self.assertEqual(client.url_for("/bar"), "http://www.foo.com/bar")
def test_can_delete_request_with_cookies(self):
responses.add(responses.DELETE, "http://www.foo.com/endpoint")
client = util.ApiClient(
base_uri="http://www.foo.com", config={"version": util.API_VERSION_1}
)
client.delete_request("endpoint", cookies={"foo": "bar"})
expected_headers = {"Cookie": "foo=bar"}
actual_headers = responses.calls[0].request.headers
self.assertTrue(
set(expected_headers.items()).issubset(set(actual_headers.items()))
)
def test_can_patch_request_with_dict_data(self):
responses.add(responses.PATCH, "http://www.foo.com/endpoint")
client = util.ApiClient(
base_uri="http://www.foo.com", config={"version": util.API_VERSION_1}
)
client.patch_request("endpoint", data={"foo": "bar"})
self.assertEqual(responses.calls[0].request.body, '{"foo": "bar"}')