def testGetPackageChangeLogRealOpenssl(self):
        # arrange
        fetcher = package_fetcher.PackageFetcher(package_fetcher.ChangeLogParser(),mockable_execute.MockableExecute())

        # act
        result = fetcher.get_package_changelog('openssl', '1.0.1e', '34.el7_0.4')

        # assert
        self.assertNotEquals(result, None)
    def testGetPackageChangeLogRealBashExclusionsSetup(self):
        # arrange
        fetcher = package_fetcher.PackageFetcher(package_fetcher.ChangeLogParser(),mockable_execute.MockableExecute(),['epel', 'extras', 'updates'])

        # act
        result = fetcher.get_package_changelog('bash', '4.2.45', '5.el7_0.4')

        # assert
        assert result == 'Unable to parse changelog for package bash version 4.2.45 release 5.el7_0.4'
    def testGetPackageChangeLogRealBashInclusionsSetup(self):
        # arrange
        fetcher = package_fetcher.PackageFetcher(package_fetcher.ChangeLogParser(),mockable_execute.MockableExecute(),['epel', 'extras', 'updates'],['*'])

        # act
        result = fetcher.get_package_changelog('bash', '4.2.45', '5.el7_0.4')

        # assert
        self.assertNotEquals(result, None)
    def testGetWhatDependsOnNone(self):
        # arrange
        fetcher = package_fetcher.PackageFetcher(package_fetcher.ChangeLogParser(),mockable_execute.MockableExecute())

        # act
        result = fetcher.get_what_depends_on('postgresql93-devel')

        # assert
        assert result == []
    def testGetPackageChangeLogRealBash(self):
        # arrange
        fetcher = package_fetcher.PackageFetcher(package_fetcher.ChangeLogParser(),mockable_execute.MockableExecute())

        # act
        result = fetcher.get_package_changelog('bash', '4.2.45', '5.el7_0.4')

        # assert
        self.assertNotEquals(result, None)
    def testGet_package_updates_with_inclusions_wildcard(self):
        # arrange
        ch_log_parser = Mock()
        executor = Mock()
        fetcher = package_fetcher.PackageFetcher(ch_log_parser,executor,['updates'],['*'])

        # act
        result = fetcher.get_package_updates()

        # assert
        assert len(result) > 0
    def testGet_package_updates_with_exclusions_wildcard(self):
        # arrange
        ch_log_parser = Mock()
        executor = Mock()
        fetcher = package_fetcher.PackageFetcher(ch_log_parser,executor,['*'])

        # act
        result = fetcher.get_package_updates()

        # assert
        # We should have excluded everything by now
        assert len(result) == 0
    def testGet_package_updates_with_exclusions_specific(self):
        # arrange
        ch_log_parser = Mock()
        executor = Mock()
        fetcher = package_fetcher.PackageFetcher(ch_log_parser,executor,['epel', 'extras', 'updates', 'base'])

        # act
        result = fetcher.get_package_updates()

        # assert
        # We should have excluded everything by now
        assert len(result) == 0
    def testGetWhatDependsOn(self):
        # arrange
        fetcher = package_fetcher.PackageFetcher(package_fetcher.ChangeLogParser(),mockable_execute.MockableExecute())

        # act
        result = fetcher.get_what_depends_on('nss')

        # assert
        assert len(result) >= 2, "Actual size is %d" % (len(result))
        names = map(lambda p:p.name, result)
        # list includes
        anything_missing = list(set(['rpm-libs']) - set(names))
        assert anything_missing == []
    def testGetPackageChangeLogMockWithInclusions(self):
        # arrange
        ch_log_parser = Mock()
        ch_log_parser.parse = Mock(return_value='the changelog info')
        executor = Mock()
        executor.run_command = Mock(return_value='the raw output')
        fetcher = package_fetcher.PackageFetcher(ch_log_parser,executor,repos_to_include=['epel'])

        # act
        result = fetcher.get_package_changelog('bash', '1.2', '33')

        # assert
        executor.run_command.assert_called_once_with(['/usr/bin/yum', '--enablerepo=epel' ,'changelog', 'updates', 'bash'])
        self.assertEquals(result, 'the changelog info')
    def testFetch_package_updates(self):
        # arrange
        ch_log_parser = Mock()
        executor = Mock()
        fetcher = package_fetcher.PackageFetcher(ch_log_parser,executor)

        # act
        result = fetcher.get_package_updates()

        # assert
        assert len(result) > 0
        first_package = result[0]
        assert isinstance(first_package, package_fetcher.Package)
        print "1st package name is %s" % (first_package.name)
        self.assertNotEquals(first_package.name, None)
        print "1st package version is %s" % (first_package.version)
        self.assertNotEquals(first_package.version, None)
        print "1st package release is %s" % (first_package.release)
        self.assertNotEquals(first_package.release, None)
        self.assertNotEquals(first_package.arch, None)
        assert first_package.repository != None
    def testfetch_installed_packages(self):
        # arrange
        ch_log_parser = Mock()
        executor = Mock()
        fetcher = package_fetcher.PackageFetcher(ch_log_parser,executor)

        # act
        result = fetcher.fetch_installed_packages()

        # assert
        expected_min_number = 154 if os.environ['CENTOS'] == 'centos6' else 183
        assert len(result) >= expected_min_number, "Actual size is %d" % (len(result))
        first_package = result[0]
        assert isinstance(first_package, package_fetcher.Package)
        print "1st package name is %s" % (first_package.name)
        assert first_package.name != None
        print "1st package version is %s" % (first_package.version)
        assert first_package.version != None
        print "1st package release is %s" % (first_package.release)
        assert first_package.release != None
        self.assertEquals(first_package.arch, 'x86_64')
        assert first_package.repository != None