def test_simple_map(anchore_db): init_distro_mappings() found = DistroMapping() found.from_distro = 'centos' found.to_distro = 'centos' found.flavor = 'RHEL' mapper = VersionPreservingDistroMapper('centos', '7', None, found) logger.info('Mapped centos to: {}'.format(mapper.mapping)) assert mapper.mapping == [ DistroTuple(distro='centos', version='7', flavor='RHEL') ] found.from_distro = 'fedora' found.to_distro = 'centos' found.flavor = 'RHEL' mapper = VersionPreservingDistroMapper('fedora', '27', 'centos', found) logger.info('Mapped fedora to: {}'.format(mapper.mapping)) assert mapper.mapping == [ DistroTuple(distro='centos', version='27', flavor='RHEL') ] mapper = VersionPreservingDistroMapper('fedora', '27', 'centos', None) logger.info('Mapped fedora to: {} on empty input'.format(mapper.mapping)) assert mapper.mapping == [ DistroTuple(distro='fedora', version='27', flavor='RHEL') ]
def test_simple_map(anchore_db): init_distro_mappings() found = DistroMapping() found.from_distro = "centos" found.to_distro = "centos" found.flavor = "RHEL" mapper = VersionPreservingDistroMapper("centos", "7", None, found) logger.info("Mapped centos to: {}".format(mapper.mapping)) assert mapper.mapping == [ DistroTuple(distro="centos", version="7", flavor="RHEL") ] found.from_distro = "fedora" found.to_distro = "centos" found.flavor = "RHEL" mapper = VersionPreservingDistroMapper("fedora", "27", "centos", found) logger.info("Mapped fedora to: {}".format(mapper.mapping)) assert mapper.mapping == [ DistroTuple(distro="centos", version="27", flavor="RHEL") ] mapper = VersionPreservingDistroMapper("fedora", "27", "centos", None) logger.info("Mapped fedora to: {} on empty input".format(mapper.mapping)) assert mapper.mapping == [ DistroTuple(distro="fedora", version="27", flavor="RHEL") ]
def test_mapped_distros(initialized_mappings): assert DistroMapping.distros_for("centos", "5", "centos") == [ DistroTuple("rhel", "5", "RHEL") ] assert DistroMapping.distros_for("centos", "6", "centos") == [ DistroTuple("rhel", "6", "RHEL") ]
def test_distromappings(initialized_mappings): c7 = DistroNamespace(name='centos', version='7', like_distro='rhel') assert c7.mapped_names() == [] assert c7.like_namespace_names == ['rhel:7'] r7 = DistroNamespace(name='rhel', version='7', like_distro='rhel') assert set(r7.mapped_names()) == {'centos', 'fedora', 'rhel'} assert r7.like_namespace_names == ['rhel:7'] assert sorted(DistroMapping.distros_mapped_to('rhel', '7')) == sorted([ DistroTuple('rhel', '7', 'RHEL'), DistroTuple('centos', '7', 'RHEL'), DistroTuple('fedora', '7', 'RHEL') ])
def test_distromappings(initialized_mappings): c7 = DistroNamespace(name="centos", version="7", like_distro="rhel") assert c7.mapped_names() == [] assert c7.like_namespace_names == ["rhel:7"] r7 = DistroNamespace(name="rhel", version="7", like_distro="rhel") assert set(r7.mapped_names()) == {"centos", "fedora", "rhel", "redhat"} assert r7.like_namespace_names == ["rhel:7"] assert sorted(DistroMapping.distros_mapped_to("rhel", "7")) == sorted([ DistroTuple("redhat", "7", "RHEL"), DistroTuple("rhel", "7", "RHEL"), DistroTuple("centos", "7", "RHEL"), DistroTuple("fedora", "7", "RHEL"), ])
def test_distromappings(anchore_db): init_feed_registry() _init_distro_mappings() c7 = DistroNamespace(name='centos', version='7', like_distro='centos') assert c7.mapped_names() == [] assert c7.like_namespace_names == ['rhel:7'] r7 = DistroNamespace(name='rhel', version='7', like_distro='centos') assert set(r7.mapped_names()) == {'centos', 'fedora', 'rhel'} assert r7.like_namespace_names == ['rhel:7'] assert sorted(DistroMapping.distros_mapped_to('rhel', '7')) == sorted([ DistroTuple('rhel', '7', 'RHEL'), DistroTuple('centos', '7', 'RHEL'), DistroTuple('fedora', '7', 'RHEL') ])
def mock_distros_for(cls, distro, version, like_distro=''): """ Mock implementation that doesn't use db :param cls: :param distro: :param version: :param like_distro: :return: """ logger.info('Calling mocked distro_for %s %s %s %s', cls, distro, version, like_distro) return [DistroTuple(distro=distro, version=version, flavor='RHEL')]
def mock_distros_for(name: str, version: str, flavor: str) -> List[DistroTuple]: return [DistroTuple(name, version, flavor)]
def mock_distros_mapped_to(name: str, version: str) -> List[DistroTuple]: return [DistroTuple(name, version, "")]
def test_mapped_distros(initialized_mappings): assert DistroMapping.distros_for( 'centos', '5', 'centos') == [DistroTuple('rhel', '5', 'RHEL')] assert DistroMapping.distros_for( 'centos', '6', 'centos') == [DistroTuple('rhel', '6', 'RHEL')]