Beispiel #1
0
    def do_test(self, date):
        """Upload errata, and parse `updateinfo.xml`.

        This does the following:

        1. Change the date of the errata and upload it to the repo.
        2. Publish the repo after uploading errata.
        3. Parse the ``updateinfo.xml`` and return the uploaded errata.
        """
        self.errata['updated'] = date
        upload_import_erratum(self.cfg, self.errata, self.repo)
        publish_repo(self.cfg, self.repo)
        update_elements = get_repodata(self.cfg, self.repo['distributors'][0],
                                       'updateinfo')
        return [
            item.find('updated').get('date')
            for item in update_elements.findall('update')
            if item.find('id').text == self.errata['id']
        ]
Beispiel #2
0
 def test_post(self):
     """Assert the function makes an HTTP POST request."""
     with mock.patch.object(api, "Client") as client:
         # post() is called twice, first to start a content upload and
         # second to import and upload. In both cases, a dict is returned.
         # Our dict mocks the first case, and just happens to work in the
         # second case too.
         client.return_value.post.return_value = {
             "_href": "foo",
             "upload_id": "bar",
         }
         response = upload_import_erratum(
             mock.Mock(),  # cfg
             {"id": "abc123"},  # erratum
             {"_href": "http://example.com"},  # repo
         )
     self.assertIs(response, client.return_value.post.return_value)
Beispiel #3
0
 def test_post(self):
     """Assert the function makes an HTTP POST request."""
     with mock.patch.object(api, 'Client') as client:
         # post() is called twice, first to start a content upload and
         # second to import and upload. In both cases, a dict is returned.
         # Our dict mocks the first case, and just happens to work in the
         # second case too.
         client.return_value.post.return_value = {
             '_href': 'foo',
             'upload_id': 'bar',
         }
         response = upload_import_erratum(
             mock.Mock(),  # cfg
             {'id': 'abc123'},  # erratum
             {'_href': 'http://example.com'},  # repo
         )
     self.assertIs(response, client.return_value.post.return_value)
Beispiel #4
0
    def setUpClass(cls):
        """Create, populate and publish a repository.

        More specifically, do the following:

        1. Create an RPM repository with a distributor.
        2. Populate the repository with an RPM and two errata, where one
           erratum references the RPM, and the other does not.
        3. Publish the repository Fetch and parse its ``updateinfo.xml`` file.
        """
        super().setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        cls.errata = {key: _gen_errata() for key in ('full', 'partial')}
        del cls.errata['partial']['pkglist']
        cls.tasks = {}

        # Create a repo.
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])

        try:
            # Populate and publish the repo.
            repo = client.get(repo['_href'], params={'details': True})
            unit = utils.http_get(RPM_UNSIGNED_URL)
            upload_import_unit(cls.cfg, unit, {'unit_type_id': 'rpm'}, repo)
            for key, erratum in cls.errata.items():
                report = upload_import_erratum(cls.cfg, erratum, repo)
                cls.tasks[key] = tuple(api.poll_spawned_tasks(cls.cfg, report))
            publish_repo(cls.cfg, repo)

            # Fetch and parse updateinfo.xml.
            cls.updates_element = (get_repodata(cls.cfg,
                                                repo['distributors'][0],
                                                'updateinfo'))
        except:  # noqa:E722
            cls.tearDownClass()
            raise
Beispiel #5
0
 def test_04_invalid_date(self):
     """Attempt to upload an errata with an invalid date."""
     self.errata['updated'] = ERRATA_UPDATE_INFO['invalid_updated_date']
     with self.assertRaises(TaskReportError):
         upload_import_erratum(self.cfg, self.errata, self.repo)