def test_raise_resource_does_not_exist(self): url = "http://dont_exist.com" responses.add(responses.GET, url, body='{"name": "betcha"}', status=404) with self.assertRaises(server_io_exceptions.ResourceDoesNotExist): server._unsafe_io_with_server(requests.get, [200], url, json={"name": "betcha"})
def test_server_with_okey_request(self): url = "http://this-is-ok.com" responses.add(responses.GET, url, body='{"name": "betcha"}', status=200) responses.add(responses.PUT, url, body='{"ok": "true"}', status=200) response_get = server._unsafe_io_with_server(requests.get, [200], url) response_put = server._unsafe_io_with_server(requests.put, [200], url) self.assertEqual(response_get.text, requests.get(url).text) self.assertEqual(response_put.text, requests.put(url).text)
def test_raise_conflict_in_database(self): url = "http://just_raise_conflict.com" responses.add(responses.PUT, url, status=409, content_type="application/json", json={'error': 'conflict'}) with self.assertRaises(server_io_exceptions.ConflictInDatabase): server._unsafe_io_with_server(requests.put, [200], url, json={"name": "betcha"})
def test_raise_unauthorized(self): url = "http://nope.com" responses.add(responses.GET, url, body='{"name": "betcha"}', status=403) with self.assertRaises(server_io_exceptions.Unauthorized): server._unsafe_io_with_server(requests.get, [200], url, json={"name": "betcha"}) url2 = "http://nope2.com" responses.add(responses.GET, url2, body='{"name": "betcha"}', status=401) with self.assertRaises(server_io_exceptions.Unauthorized): server._unsafe_io_with_server(requests.get, [200], url, json={"name": "betcha"})
def test_raise_cant_comm_with_server_on_wrong_response_code(self): url = "http://yes.com" responses.add(responses.GET, url, status=204) with self.assertRaises( server_io_exceptions.CantCommunicateWithServerError): server._unsafe_io_with_server(requests.get, [200], url)