def test_url_path_join(self): root = client.get_host() items = ["data", "persons"] expected_url = "{host}data/persons".format( host=client.get_host() ) self.assertEquals(client.url_path_join(root, *items), expected_url)
def test_init_log_out(self): with requests_mock.mock() as mock: mock.head(raw.get_host()) mock.get( raw.get_full_url("auth/logout"), text=json.dumps({}), status_code=400, ) gazu.log_out() self.assertEqual(raw.default_client.tokens, {})
def test_host_is_valid(self): self.assertFalse(raw.host_is_valid()) with requests_mock.mock() as mock: mock.head(raw.get_host()) mock.post( raw.get_full_url("auth/login"), text=json.dumps({}), status_code=400, ) self.assertTrue(raw.host_is_valid())
def test_init_log_in_fail(self): with requests_mock.mock() as mock: mock.post( raw.get_full_url("auth/login"), text=json.dumps({"login": False}), ) self.assertRaises(AuthFailedException, gazu.log_in, "frank", "test") self.assertRaises(AuthFailedException, gazu.log_in, "", "") with requests_mock.mock() as mock: mock.head(raw.get_host()) mock.post( raw.get_full_url("auth/login"), text=json.dumps({}), status_code=400, ) with self.assertRaises(AuthFailedException): gazu.log_in("", "")
def test_get_full_url(self): test_route = "test_route" expected_url = client.url_path_join(client.get_host(), test_route) self.assertEqual(client.get_full_url(test_route), expected_url)
def test_set_host(self): client.set_host("newhost") self.assertEqual(client.get_host(), "newhost") client.set_host("http://gazu-server/")
def test_get_host(self): self.assertEqual(client.get_host(), client.HOST)
def test_host_is_up(self): with requests_mock.mock() as mock: mock.head(client.get_host()) self.assertTrue(client.host_is_up())
def test_version(self): with requests_mock.mock() as mock: mock.get(client.get_host(), text='{"version": "0.2.0"}') self.assertEqual(client.get_api_version(), "0.2.0")
def test_set_host(self): raw.set_host("newhost") self.assertEqual(raw.get_host(), "newhost") raw.set_host("http://gazu-server/api")
def test_get_host(self): self.assertEqual(raw.get_host(), raw.default_client.host)
def test_host_is_up(self): with requests_mock.mock() as mock: mock.head(raw.get_host()) self.assertTrue(raw.host_is_up()) self.assertFalse(raw.host_is_up())
def test_version(self): with requests_mock.mock() as mock: mock.get(raw.get_host() + "/", text=json.dumps({"version": "0.2.0"})) self.assertEqual(raw.get_api_version(), "0.2.0")