def test_get_requests(self, fake_request): listener = Mock() base_url = 'http://host' units = [ Unit(), Unit(), Unit(), ] # set each unit to use a different base url for n, unit in enumerate(units): unit.base_url = '%s:%s/' % (base_url, n) unit.filename = 'file%d' % n unit.download_path = unit.filename unit.relativepath = unit.filename # test packages = Packages(base_url, None, units, '', listener) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): self.assertEqual(call[1]['unit_key'], units[n].unit_key) self.assertEqual(call[1]['url'], urljoin(units[n].base_url, units[n].download_path)) self.assertEqual(call[1]['destination'], os.path.join(packages.dst_dir, units[n].relativepath)) self.assertEqual(len(requests), len(units))
def test_get_requests_auth_token(self, fake_request): qstring = '?foo' listener = Mock() base_url = 'http://host' units = [ Unit(), Unit(), Unit(), ] # set each unit to use a different base url for n, unit in enumerate(units): unit.base_url = '%s:%s/' % (base_url, n) unit.filename = 'file%d' % n unit.download_path = unit.filename unit.relativepath = unit.filename # test url_modify = RepoURLModifier(query_auth_token=qstring[1:]) packages = Packages(base_url, None, units, '', listener, url_modify) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): unit_base_url = '%s:%s/' % (base_url, n) expected = urljoin(unit_base_url, units[n].download_path) + qstring self.assertEqual(call[1]['url'], expected) self.assertEqual(len(requests), len(units))
def test_get_requests_base_url(self, fake_request): listener = Mock() base_url = 'http://host' units = [ Unit(), Unit(), Unit(), ] # set each unit to use a different base url for n, unit in enumerate(units): unit.metadata['base_url'] = '%s:%s/' % (base_url, n) # test packages = Packages(base_url, None, units, '', listener) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): self.assertEqual(call[1]['type_id'], units[n].TYPE) self.assertEqual(call[1]['unit_key'], units[n].unit_key) unit_base_url = '%s:%s/' % (base_url, n) self.assertEqual(call[1]['url'], urljoin(unit_base_url, units[n].download_path)) self.assertEqual(call[1]['destination'], os.path.join(packages.dst_dir, units[n].relative_path)) self.assertEqual(len(requests), len(units))
def test_get_requests_auth_token(self, fake_request): qstring = '?foo' listener = Mock() base_url = 'http://host' units = [ Unit(), Unit(), Unit(), ] # set each unit to use a different base url for n, unit in enumerate(units): unit.base_url = '%s:%s/' % (base_url, n) unit.filename = 'file%d' % n unit.download_path = unit.filename unit.relativepath = unit.filename # test url_modify = RepoURLModifier(query_auth_token=qstring[1:]) packages = Packages(base_url, None, units, '', listener, url_modify) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): unit_base_url = '%s:%s/' % (base_url, n) expected = urljoin(unit_base_url, units[n].download_path) + qstring self.assertEqual(call[1]['url'], expected) self.assertEqual(len(requests), len(units))
def test_get_requests(self, fake_request): listener = Mock() base_url = "http://host" units = [Unit(), Unit(), Unit()] # test packages = Packages(base_url, None, units, "", listener) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): self.assertEqual(call[1]["type_id"], units[n].TYPE) self.assertEqual(call[1]["unit_key"], units[n].unit_key) self.assertEqual(call[1]["url"], urljoin(base_url, units[n].download_path)) self.assertEqual(call[1]["destination"], os.path.join(packages.dst_dir, units[n].relative_path)) self.assertEqual(len(requests), len(units))
def test_get_requests(self, fake_request): listener = Mock() base_url = 'http://host' units = [ Unit(), Unit(), Unit(), ] # test packages = Packages(base_url, None, units, '', listener) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): self.assertEqual(call[1]['type_id'], units[n].TYPE) self.assertEqual(call[1]['unit_key'], units[n].unit_key) self.assertEqual(call[1]['url'], urljoin(base_url, units[n].download_path)) self.assertEqual(call[1]['destination'], os.path.join(packages.dst_dir, units[n].relative_path)) self.assertEqual(len(requests), len(units))
def test_get_requests(self, fake_request): listener = Mock() base_url = "http://host" units = [Unit(), Unit(), Unit()] # set each unit to use a different base url for n, unit in enumerate(units): unit.base_url = "%s:%s/" % (base_url, n) unit.filename = "file%d" % n unit.download_path = unit.filename unit.relativepath = unit.filename # test packages = Packages(base_url, None, units, "", listener) requests = list(packages.get_requests()) calls = fake_request.call_args_list self.assertEqual(len(requests), len(units)) for n, call in enumerate(calls): self.assertEqual(call[1]["unit_key"], units[n].unit_key) self.assertEqual(call[1]["url"], urljoin(units[n].base_url, units[n].download_path)) self.assertEqual(call[1]["destination"], os.path.join(packages.dst_dir, units[n].relativepath)) self.assertEqual(len(requests), len(units))