Beispiel #1
0
 def test_working_erratum(self):
     """We can create an Erratum object with a known erratum from the API"""
     # If there is an error, it will raise on its own during parsing
     #
     # If the tool fails in the future due to a schema change in
     # the returned erratum object from the ET API then the
     # `example_erratum` in this test file will need to be updated.
     e = errata.Erratum(body=test_structures.example_erratum)
     self.assertEqual(type(e), type(errata.Erratum()))
Beispiel #2
0
    def test_add_builds_success(self):
        """Ensure legit builds are added correctly"""
        with nested(mock.patch('errata.requests.post'),
                    mock.patch('errata.HTTPKerberosAuth')) as (post, kerb):
            response = mock.MagicMock(status_code=200)
            response.json.return_value = test_structures.example_erratum_filtered_list
            post.return_value = response

            pv = 'rhaos-test-7'
            e = errata.Erratum(body=test_structures.example_erratum)
            b1 = brew.Build(nvr='coreutils-8.22-21.el7',
                            body=test_structures.rpm_build_attached_json,
                            product_version=pv)
            b2 = brew.Build(nvr='ansible-service-broker-1.0.21-1.el7',
                            body=test_structures.rpm_build_unattached_json,
                            product_version=pv)
            builds = [b1, b2]

            result = e.add_builds(builds)

            # add_builds returns True on success
            self.assertTrue(result)
            # Even though we have multiple builds, the add_builds
            # endpoint allows us to make just one call, as it
            # accepts a list of builds in the request body
            self.assertEqual(post.call_count, 1)

            post.assert_called_once_with(
                constants.errata_add_builds_url.format(
                    id=test_structures.example_erratum['content']['content']
                    ['errata_id']),
                auth=kerb(),
                json=[b1.to_json(), b2.to_json()])
Beispiel #3
0
    def test_add_bug(self):
        """Verify Bugs are added the right way"""
        with nested(
                mock.patch('errata.requests.post'),
                # Mock the HTTPKerberosAuth object in the module
                mock.patch('errata.HTTPKerberosAuth')) as (post, kerb):
            response = mock.MagicMock(status_code=404)
            response.json.return_value = test_structures.example_erratum_filtered_list
            post.return_value = response

            b = bugzilla.Bug(id=1337)

            # With the mocked HTTPKerberosAuth object we can now
            # create an erratum
            e = errata.Erratum(body=test_structures.example_erratum)

            # When we make the method call, we will be using the same
            # mocked ('kerb') HTTPKerberosAuth object
            e.add_bug(b)

            post.assert_called_once_with(constants.errata_add_bug_url.format(
                id=test_structures.example_erratum['content']['content']
                ['errata_id']),
                                         auth=kerb(),
                                         json={'bug': b.id})
Beispiel #4
0
 def test_erratum_as_string(self):
     """Verify str(Erratum) is formatted correctly"""
     ds = test_structures.example_erratum
     e = errata.Erratum(body=ds)
     expected_str = "{date} {state} {synopsis} {url}".format(
         date=datetime.datetime.strptime(ds['errata']['rhba']['created_at'],
                                         '%Y-%m-%dT%H:%M:%SZ').isoformat(),
         state=ds['errata']['rhba']['status'],
         synopsis=ds['errata']['rhba']['synopsis'],
         url="{et}/advisory/{id}".format(et=constants.errata_url,
                                         id=ds['errata']['rhba']['id']))
     self.assertEqual(expected_str, str(e))
Beispiel #5
0
    def test_add_builds_failure(self):
        """Ensure failing add_builds raises correctly on a known bad status code"""
        with nested(mock.patch('errata.requests.post'),
                    mock.patch('errata.HTTPKerberosAuth')) as (post, kerb):
            # This triggers the failure code-branch
            response = mock.MagicMock(status_code=422)
            response.json.return_value = test_structures.example_erratum_filtered_list
            post.return_value = response

            pv = 'rhaos-test-7'
            e = errata.Erratum(body=test_structures.example_erratum)
            b1 = brew.Build(nvr='coreutils-8.22-21.el7',
                            body=test_structures.rpm_build_attached_json,
                            product_version=pv)
            b2 = brew.Build(nvr='ansible-service-broker-1.0.21-1.el7',
                            body=test_structures.rpm_build_unattached_json,
                            product_version=pv)
            builds = [b1, b2]

            with self.assertRaises(exceptions.BrewBuildException):
                e.add_builds(builds)
Beispiel #6
0
 def test_erratum_to_json(self):
     """Ensure Erratum.to_json returns the source datastructure"""
     e = errata.Erratum(body=test_structures.example_erratum)
     self.assertEqual(json.loads(e.to_json()),
                      test_structures.example_erratum)