Пример #1
0
    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)
Пример #2
0
 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, {})
Пример #3
0
 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())
Пример #4
0
 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("", "")
Пример #5
0
    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)
Пример #6
0
 def test_set_host(self):
     client.set_host("newhost")
     self.assertEqual(client.get_host(), "newhost")
     client.set_host("http://gazu-server/")
Пример #7
0
 def test_get_host(self):
     self.assertEqual(client.get_host(), client.HOST)
Пример #8
0
 def test_host_is_up(self):
     with requests_mock.mock() as mock:
         mock.head(client.get_host())
         self.assertTrue(client.host_is_up())
Пример #9
0
 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")
Пример #10
0
 def test_set_host(self):
     raw.set_host("newhost")
     self.assertEqual(raw.get_host(), "newhost")
     raw.set_host("http://gazu-server/api")
Пример #11
0
 def test_get_host(self):
     self.assertEqual(raw.get_host(), raw.default_client.host)
Пример #12
0
 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())
Пример #13
0
 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")