Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
    def test_cancel(self):
        packages = Packages("http://none", None, [], "", None)
        self.assertFalse(packages.canceled.is_set())

        # test
        packages.cancel()

        # validation
        self.assertTrue(packages.canceled.is_set())
Ejemplo n.º 6
0
    def test_cancel(self):
        packages = Packages('http://none', None, [], '', None)
        self.assertFalse(packages.canceled.is_set())

        # test
        packages.cancel()

        # validation
        self.assertTrue(packages.canceled.is_set())
Ejemplo n.º 7
0
    def test_download(self, fake_requests, fake_container):
        listener = Mock()
        base_url = "http://host"
        units = [Unit(), Unit(), Unit()]

        # test
        packages = Packages(base_url, None, units, "", listener)
        packages.download_packages()

        # validation
        fake_container().download.assert_called_with(packages.primary, fake_requests(), packages.listener)
Ejemplo n.º 8
0
    def test_download(self, fake_requests, fake_container):
        listener = Mock()
        base_url = 'http://host'
        units = [
            Unit(),
            Unit(),
            Unit(),
        ]

        # test
        packages = Packages(base_url, None, units, '', listener)
        packages.download_packages()

        # validation
        fake_container().download.assert_called_with(
            packages.primary, fake_requests(), packages.listener)
Ejemplo n.º 9
0
    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))
Ejemplo n.º 10
0
    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))
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
    def test_construction(self, fake_create_downloader, fake_container):
        base_url = str(uuid4())
        nectar_conf = Mock()
        units = Mock()
        dst_dir = str(uuid4())
        listener = Mock()

        # test
        packages = Packages(base_url, nectar_conf, units, dst_dir, listener)

        # validation
        fake_create_downloader.assert_called_with(base_url, nectar_conf)

        self.assertEqual(packages.base_url, base_url)
        self.assertEqual(packages.units, units)
        self.assertEqual(packages.dst_dir, dst_dir)
        self.assertTrue(isinstance(packages.listener, ContainerListener))
        self.assertEqual(packages.listener.content_listener, listener)
        self.assertEqual(packages.primary, fake_create_downloader())
        self.assertEqual(packages.container, fake_container())
Ejemplo n.º 13
0
    def test_downloader(self):
        # test
        packages = Packages('http://none', None, [], '', None)

        # validation
        self.assertEqual(packages.downloader, packages)