def test_query_str(self): url = self.url url.set_query(self._query) self.assertEqual(url.query_str, self._query_string) path = "/path?a=1&b=2" url = URL(self._url, path) self.assertEqual(url.query_str, "a=1&b=2")
def test_size(self): pool = URLPool() count = random.randint(10, 20) for i in range(count): url = URL(self._url) pool.put_url(url) self.assertEqual(pool.size, count)
def travel_mod(self): pool = URLPool() n = 10 for i in range(n): url = URL(self._url, depth=1) pool.put_url(url) pool.set_treval_mod(Treval.BFS) url = pool.get_url() self.assertEqual(url.depth, 0) pool.set_treval_mod(Treval.DFS) url = pool.get_url() self.assertEqual(url.depth, n - 1)
def test_is_full_url(self): url1 = "http://www.aaa.com/path?sdsd=ss" url2 = "/path?uu=11" self.assertTrue(URL.is_full_url(url1)) self.assertFalse(URL.is_full_url(url2))
def test_dict_to_qs(self): self.assertEqual(URL.dict_to_qs(self._query), self._query_string)
def test_urljoin(self): target = "http://www.aaa.com/bbb" origin = "http://www.aaa.com/aaa" self.assertEqual(URL.urljoin(origin, target), target) self.assertEqual(URL.urljoin(origin, "/bbb"), target)
def test_query(self): path = "/path?a=1&b=2" d = {"a": "1", "b": "2"} url = URL(self._url, path) self.assertEqual(url.query, d)
def url(self): return URL(self._url, self._path)