def setUp(self): stub_prod = StubProduct("fauxprod", provided_tags="TAG1,TAG2") stub_prod2 = StubProduct("fauxprovidedprod", provided_tags="TAG4") stub_prod_cert = StubProductCertificate(stub_prod, provided_products=[stub_prod2]) stub_prod2 = StubProduct("fauxprod2", provided_tags="TAG5,TAG6") stub_prod2_cert = StubProductCertificate(stub_prod2) stub_prod_dir = StubProductDirectory([stub_prod_cert, stub_prod2_cert]) stub_content = [ StubContent("c1", required_tags="", gpg=None), # no required tags StubContent("c2", required_tags="TAG1", gpg=""), StubContent("c3", required_tags="TAG1,TAG2,TAG3"), # should get skipped StubContent("c4", required_tags="TAG1,TAG2,TAG4,TAG5,TAG6", gpg="/gpg.key", url="/$some/$path"), StubContent("c5", content_type="file", required_tags="", gpg=None), StubContent("c6", content_type="file", required_tags="", gpg=None), ] self.stub_ent_cert = StubEntitlementCertificate(stub_prod, content=stub_content) stub_ent_dir = StubCertificateDirectory([self.stub_ent_cert]) repolib.ConsumerIdentity = stubs.StubConsumerIdentity stub_uep = stubs.StubUEP() self.update_action = UpdateAction(prod_dir=stub_prod_dir, ent_dir=stub_ent_dir, uep=stub_uep)
def setUp(self): stub_prod = StubProduct("fauxprod", provided_tags="TAG1,TAG2") stub_prod2 = StubProduct("fauxprovidedprod", provided_tags="TAG4") stub_prod_cert = StubProductCertificate(stub_prod, provided_products=[stub_prod2]) stub_prod2 = StubProduct("fauxprod2", provided_tags="TAG5,TAG6") stub_prod2_cert = StubProductCertificate(stub_prod2) stub_prod_dir = StubProductDirectory([stub_prod_cert, stub_prod2_cert]) stub_content = [ StubContent("c1", required_tags="", gpg=None), # no required tags StubContent("c2", required_tags="TAG1", gpg=""), StubContent("c3", required_tags="TAG1,TAG2,TAG3"), # should get skipped StubContent("c4", required_tags="TAG1,TAG2,TAG4,TAG5,TAG6", gpg="/gpg.key"), ] self.stub_ent_cert = StubEntitlementCertificate(stub_prod, content=stub_content) stub_ent_dir = StubCertificateDirectory([self.stub_ent_cert]) repolib.ConsumerIdentity = stubs.StubConsumerIdentity stub_uep = stubs.StubUEP() self.update_action = UpdateAction(prod_dir=stub_prod_dir, ent_dir=stub_ent_dir, uep=stub_uep)
class UpdateActionTests(unittest.TestCase): def setUp(self): stub_prod = StubProduct("fauxprod", provided_tags="TAG1,TAG2") stub_prod2 = StubProduct("fauxprovidedprod", provided_tags="TAG4") stub_prod_cert = StubProductCertificate(stub_prod, provided_products=[stub_prod2]) stub_prod2 = StubProduct("fauxprod2", provided_tags="TAG5,TAG6") stub_prod2_cert = StubProductCertificate(stub_prod2) stub_prod_dir = StubProductDirectory([stub_prod_cert, stub_prod2_cert]) stub_content = [ StubContent("c1", required_tags="", gpg=None), # no required tags StubContent("c2", required_tags="TAG1", gpg=""), StubContent("c3", required_tags="TAG1,TAG2,TAG3"), # should get skipped StubContent("c4", required_tags="TAG1,TAG2,TAG4,TAG5,TAG6", gpg="/gpg.key", url="/$some/$path"), StubContent("c5", content_type="file", required_tags="", gpg=None), StubContent("c6", content_type="file", required_tags="", gpg=None), ] self.stub_ent_cert = StubEntitlementCertificate(stub_prod, content=stub_content) stub_ent_dir = StubCertificateDirectory([self.stub_ent_cert]) repolib.ConsumerIdentity = stubs.StubConsumerIdentity stub_uep = stubs.StubUEP() self.update_action = UpdateAction(prod_dir=stub_prod_dir, ent_dir=stub_ent_dir, uep=stub_uep) def _find_content(self, content_list, name): """ Scan list of content for one with name. """ for content in content_list: if content['name'] == name: return content return None def test_no_gpg_key(self): content = self.update_action.get_content(self.stub_ent_cert, "http://example.com", None) c1 = self._find_content(content, 'c1') self.assertEquals('', c1['gpgkey']) self.assertEquals('0', c1['gpgcheck']) c2 = self._find_content(content, 'c2') self.assertEquals('', c2['gpgkey']) self.assertEquals('0', c2['gpgcheck']) def test_gpg_key(self): content = self.update_action.get_content(self.stub_ent_cert, "http://example.com", None) c4 = self._find_content(content, 'c4') self.assertEquals('http://example.com/gpg.key', c4['gpgkey']) self.assertEquals('1', c4['gpgcheck']) def test_ui_repoid_vars(self): content = self.update_action.get_content(self.stub_ent_cert, "http://example.com", None) c4 = self._find_content(content, 'c4') self.assertEquals('some path', c4['ui_repoid_vars']) c2 = self._find_content(content, 'c2') self.assertEquals(None, c2['ui_repoid_vars']) def test_tags_found(self): content = self.update_action.get_unique_content() self.assertEquals(3, len(content)) def test_join(self): base = "http://foo/bar" # File urls should be preserved self.assertEquals( "file://this/is/a/file", self.update_action.join(base, "file://this/is/a/file")) # Http locations should be preserved self.assertEquals( "http://this/is/a/url", self.update_action.join(base, "http://this/is/a/url")) # Blank should remain blank self.assertEquals("", self.update_action.join(base, "")) # Url Fragments should work self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "baz")) self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "/baz")) base = base + "/" self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "baz")) self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "/baz")) def test_only_allow_content_of_type_yum(self): content = self.update_action.get_content(self.stub_ent_cert, "http://example.com", None) self.assertTrue(self._find_content(content, "c1") is not None) self.assertTrue(self._find_content(content, "c5") is None) self.assertTrue(self._find_content(content, "c6") is None)
class UpdateActionTests(unittest.TestCase): def setUp(self): stub_prod = StubProduct("fauxprod", provided_tags="TAG1,TAG2") stub_prod2 = StubProduct("fauxprovidedprod", provided_tags="TAG4") stub_prod_cert = StubProductCertificate(stub_prod, provided_products=[stub_prod2]) stub_prod2 = StubProduct("fauxprod2", provided_tags="TAG5,TAG6") stub_prod2_cert = StubProductCertificate(stub_prod2) stub_prod_dir = StubProductDirectory([stub_prod_cert, stub_prod2_cert]) stub_content = [ StubContent("c1", required_tags="", gpg=None), # no required tags StubContent("c2", required_tags="TAG1", gpg=""), StubContent("c3", required_tags="TAG1,TAG2,TAG3"), # should get skipped StubContent("c4", required_tags="TAG1,TAG2,TAG4,TAG5,TAG6", gpg="/gpg.key"), ] self.stub_ent_cert = StubEntitlementCertificate(stub_prod, content=stub_content) stub_ent_dir = StubCertificateDirectory([self.stub_ent_cert]) repolib.ConsumerIdentity = stubs.StubConsumerIdentity stub_uep = stubs.StubUEP() self.update_action = UpdateAction(prod_dir=stub_prod_dir, ent_dir=stub_ent_dir, uep=stub_uep) def _find_content(self, content_list, name): """ Scan list of content for one with name. """ for content in content_list: if content['name'] == name: return content return None def test_no_gpg_key(self): content = self.update_action.get_content(self.stub_ent_cert, "http://example.com", None) c1 = self._find_content(content, 'c1') self.assertEquals('', c1['gpgkey']) self.assertEquals('0', c1['gpgcheck']) c2 = self._find_content(content, 'c2') self.assertEquals('', c2['gpgkey']) self.assertEquals('0', c2['gpgcheck']) def test_gpg_key(self): content = self.update_action.get_content(self.stub_ent_cert, "http://example.com", None) c4 = self._find_content(content, 'c4') self.assertEquals('http://example.com/gpg.key', c4['gpgkey']) self.assertEquals('1', c4['gpgcheck']) def test_tags_found(self): content = self.update_action.get_unique_content() self.assertEquals(3, len(content)) def test_join(self): base = "http://foo/bar" # File urls should be preserved self.assertEquals("file://this/is/a/file", self.update_action.join(base, "file://this/is/a/file")) # Http locations should be preserved self.assertEquals("http://this/is/a/url", self.update_action.join(base, "http://this/is/a/url")) # Blank should remain blank self.assertEquals("", self.update_action.join(base, "")) # Url Fragments should work self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "baz")) self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "/baz")) base = base + "/" self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "baz")) self.assertEquals("http://foo/bar/baz", self.update_action.join(base, "/baz"))