class TestPolicyBase(test_helper.MoxTestCase): def _create_mock_version_adapter(self, version_string): if version_string == None: return None mva = self.mox.CreateMock(VersionAdapter) mva.files = [] if type(version_string) == tuple: mva.string = version_string[0] for o in version_string[1]: mva.files.append(PackageFileAdapter(FakePackageFile(origin = o))) else: mva.string = version_string mva.files.append(PackageFileAdapter(FakePackageFile(origin = 'Debian'))) return mva def _create_mock_status(self, package, current_version, candidate_version, _official_versions, other_versions = {}): official_versions = [self._create_mock_version_adapter(v) for v in _official_versions] vbo = {} vbo['Debian'] = official_versions for o, vers in other_versions.items(): vbo[o] = [self._create_mock_version_adapter((v, o,)) for v in vers] return Status(package, self._create_mock_version_adapter(current_version), self._create_mock_version_adapter(candidate_version), vbo) def _create_mock_config(self, hashes): stanzas = [] for hash in hashes: stanza = ConfigStanza() stanza.set('package', 'apackage', 1) stanza.set('accept-origin', hash['accepted_origin'], 2) stanza.set('track-origin', hash['track_origin'], 3) stanza.set('track-version', hash['track_version'], 4) stanza.finish(4) stanzas.append(stanza) mock_config = self.struct() mock_config.package = lambda name: name == 'apackage' and stanzas or [] return mock_config def setUp(self): super(TestPolicyBase, self).setUp() self.apt_pkg_adapter = AptPkgAdapter(self._create_mock_apt_pkg_module()) self.apt_pkg_adapter.init() self.mock_facter = self._create_mock_facter('Debian') self.set_up_policy_creation() def set_up_policy_creation(self): self.policy = Policy(self.apt_pkg_adapter, self.mock_facter, self._create_mock_config([])) def assert_should_report_yes(self, current_version, candidate_version, official_versions, package = 'apackage', other_versions = {}): s = self._create_mock_status(package, current_version, candidate_version, official_versions, other_versions = other_versions) self.assert_(self.policy.should_report(s)) def assert_should_report_NOT(self, current_version, candidate_version, official_versions, package = 'apackage', other_versions = {}): s = self._create_mock_status(package, current_version, candidate_version, official_versions, other_versions = other_versions) self.assert_(not self.policy.should_report(s)) def test_missing_version(self): self.mox.ReplayAll() self.assert_should_report_yes('2.1~1', None, ['2.1']) self.assert_should_report_yes(None, '2.1~1', ['2.1']) self.assert_should_report_yes('2.1~1', '2.1~1', [])
def set_up_policy_creation(self): self.policy = Policy( self.apt_pkg_adapter, self.mock_facter, self._create_mock_config([{ 'accepted_origin': 'accepted origin', 'track_origin': '*', 'track_version': '2.0' }]))
def set_up_policy_creation(self): self.policy = Policy( self.apt_pkg_adapter, self.mock_facter, self._create_mock_config([{ 'accepted_origin': 'accepted origin', 'track_origin': 'Debian', 'track_version': '=candidate-base' }]))
def test_non_verbose(self): # libc6 - never self.reporter.report(mox.Func(lambda o: o.package_name == 'libspf')) # libfoobar - never # git-core - never self.mox.ReplayAll() self.finishSetUp() checker = Checker(self.facter) policy = Policy(self.apt_pkg_adapter, self.facter, self.config) self.cache_adapter.run(checker, policy, self.package_adapter_factory)
def run(verbose): facter = Facter() reporter = Reporter() apt_pkg_adapter = AptPkgAdapter(apt_pkg) apt_pkg_adapter.init() cache_adapter = apt_pkg_adapter.get_cache_adapter(CacheAdapterFactory(), reporter, NullProgress()) apt_depcache_adapter = apt_pkg_adapter.get_depcache_adapter( DepCacheAdapterFactory()) package_adapter_factory = PackageAdapterFactory(apt_depcache_adapter) checker = Checker(facter, verbose) config = Config() config_finder = ConfigFinder('/etc/apt/forktracer.conf', '/etc/apt/forktracer.d') config_parser = ConfigParser() for path, file in config_finder: config_parser.load(file, config) if verbose: policy = VerbosePolicy() else: policy = Policy(apt_pkg_adapter, facter, config) cache_adapter.run(checker, policy, package_adapter_factory)
def set_up_policy_creation(self): self.policy = Policy(self.apt_pkg_adapter, self.mock_facter, self._create_mock_config([]))
class TestPolicyBase(test_helper.MoxTestCase): def _create_mock_version_adapter(self, version_string): if version_string == None: return None mva = self.mox.CreateMock(VersionAdapter) mva.files = [] if type(version_string) == tuple: mva.string = version_string[0] for o in version_string[1]: mva.files.append(PackageFileAdapter(FakePackageFile(origin=o))) else: mva.string = version_string mva.files.append( PackageFileAdapter(FakePackageFile(origin='Debian'))) return mva def _create_mock_status(self, package, current_version, candidate_version, _official_versions, other_versions={}): official_versions = [ self._create_mock_version_adapter(v) for v in _official_versions ] vbo = {} vbo['Debian'] = official_versions for o, vers in other_versions.items(): vbo[o] = [ self._create_mock_version_adapter(( v, o, )) for v in vers ] return Status(package, self._create_mock_version_adapter(current_version), self._create_mock_version_adapter(candidate_version), vbo) def _create_mock_config(self, hashes): stanzas = [] for hash in hashes: stanza = ConfigStanza() stanza.set('package', 'apackage', 1) stanza.set('accept-origin', hash['accepted_origin'], 2) stanza.set('track-origin', hash['track_origin'], 3) stanza.set('track-version', hash['track_version'], 4) stanza.finish(4) stanzas.append(stanza) mock_config = self.struct() mock_config.package = lambda name: name == 'apackage' and stanzas or [] return mock_config def setUp(self): super(TestPolicyBase, self).setUp() self.apt_pkg_adapter = AptPkgAdapter( self._create_mock_apt_pkg_module()) self.apt_pkg_adapter.init() self.mock_facter = self._create_mock_facter('Debian') self.set_up_policy_creation() def set_up_policy_creation(self): self.policy = Policy(self.apt_pkg_adapter, self.mock_facter, self._create_mock_config([])) def assert_should_report_yes(self, current_version, candidate_version, official_versions, package='apackage', other_versions={}): s = self._create_mock_status(package, current_version, candidate_version, official_versions, other_versions=other_versions) self.assert_(self.policy.should_report(s)) def assert_should_report_NOT(self, current_version, candidate_version, official_versions, package='apackage', other_versions={}): s = self._create_mock_status(package, current_version, candidate_version, official_versions, other_versions=other_versions) self.assert_(not self.policy.should_report(s)) def test_missing_version(self): self.mox.ReplayAll() self.assert_should_report_yes('2.1~1', None, ['2.1']) self.assert_should_report_yes(None, '2.1~1', ['2.1']) self.assert_should_report_yes('2.1~1', '2.1~1', [])