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()])
def test_build_sorting(self): """Ensure we can sort a list of builds""" b1 = brew.Build(nvr='abcd-1.0.0') b2 = brew.Build(nvr='zyxw-1.0.0') # Same one as before for equality b3 = brew.Build(nvr='zyxw-1.0.0') self.assertGreater(b2, b1) self.assertLess(b1, b2) self.assertEqual(b2, b3)
def test_build_equality(self): """Ensure brew Builds are unique and can be tested for equality""" b1 = brew.Build(nvr='megafrobber-1.3.3-7') b2 = brew.Build(nvr='tuxracer-42') builds = set([]) builds.add(b1) builds.add(b1) self.assertEqual(1, len(builds)) self.assertTrue(b1 != b2)
def test_build_attached_to_closed_erratum(self): """We can tell if a build is attached to any closed erratum""" # Use filter #1991: (Active; Product: RHOSE; sorted by newest) b = brew.Build(nvr='template-service-broker-docker-v3.7.36-2', body=test_structures.image_build_attached_closed_json, product_version='rhaos-test-7') self.assertTrue(b.attached_to_closed_erratum)
def test_build_attached_to_open_erratum(self): """We can tell if a build is attached to any open erratum""" # Create Erratum(), create Build() using dict with all_errata # containing an object with 'id' matching Erratum.advisory_id b = brew.Build(nvr='template-service-broker-docker-v3.7.36-2', body=test_structures.image_build_attached_open_json, product_version='rhaos-test-7') self.assertTrue(b.attached_to_open_erratum)
def test_good_unattached_brew_rpm_build(self): """We can create and process an unattached rpm Build object""" b = brew.Build(nvr='ansible-service-broker-1.0.21-1.el7', body=test_structures.rpm_build_unattached_json, product_version='rhaos-test-7') self.assertEqual('ansible-service-broker-1.0.21-1.el7', b.nvr) self.assertEqual('rpm', b.kind) self.assertEqual('rpm', b.file_type) self.assertFalse(b.attached)
def test_good_attached_brew_rpm_build(self): """We can create and process an attached rpm Build object""" b = brew.Build(nvr='coreutils-8.22-21.el7', body=test_structures.rpm_build_attached_json, product_version='rhaos-test-7') self.assertEqual('coreutils-8.22-21.el7', b.nvr) self.assertEqual('rpm', b.kind) self.assertEqual('rpm', b.file_type) self.assertTrue(b.attached)
def test_good_unattached_brew_image_build(self): """We can create and process an unattached image Build object""" b = brew.Build(nvr='cri-o-docker-v3.7.37-1', body=test_structures.image_build_unattached_json, product_version='rhaos-test-7') self.assertEqual('cri-o-docker-v3.7.37-1', b.nvr) self.assertEqual('image', b.kind) self.assertEqual('tar', b.file_type) self.assertFalse(b.attached)
def test_good_attached_brew_image_build(self): """We can create and process an attached image Build object""" b = brew.Build(nvr='template-service-broker-docker-v3.7.36-2', body=test_structures.image_build_attached_json, product_version='rhaos-test-7') self.assertEqual('template-service-broker-docker-v3.7.36-2', b.nvr) self.assertEqual('image', b.kind) self.assertEqual('tar', b.file_type) self.assertTrue(b.attached)
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)
def test_image_build_json_formatting(self): """Ensure a brew Build returns proper JSON for API posting""" nvr = 'template-service-broker-docker-v3.7.36-2' pv = 'rhaos-test-7' b = brew.Build(nvr=nvr, body=test_structures.image_build_attached_json, product_version=pv) expected_json = { 'product_version': pv, 'build': nvr, 'file_types': ['tar'] } self.assertEqual(expected_json, b.to_json())
def test_rpm_build_json_formatting(self): """Ensure a brew Build returns proper JSON for API posting""" nvr = 'coreutils-8.22-21.el7' pv = 'rhaos-test-7' b = brew.Build(nvr=nvr, body=test_structures.rpm_build_attached_json, product_version=pv) expected_json = { 'product_version': pv, 'build': nvr, 'file_types': ['rpm'] } self.assertEqual(expected_json, b.to_json())
def test_build_display(self): """Verify brew Builds display correctly""" nvr = 'megafrobber-1.3.3-7' b = brew.Build(nvr=nvr) self.assertEqual(nvr, str(b)) self.assertEqual("Build({nvr})".format(nvr=nvr), repr(b))