def testVerifySourcesTrapsSourceUnavailable(self): self.conf.maps = [] self.assertEquals(1, command.Verify().VerifySources(self.conf)) def FakeCreate(conf): """Stub routine returning a pmock to test VerifySources.""" self.assertEquals(conf, self.conf.options[config.MAP_PASSWORD].source) raise error.SourceUnavailable old_source_base_create = source_factory.Create source_factory.Create = FakeCreate self.conf.maps = [config.MAP_PASSWORD] self.assertEquals(1, command.Verify().VerifySources(self.conf)) source_factory.Create = old_source_base_create
def testVerifySourcesBad(self): self.conf.maps = [] self.assertEquals(1, command.Verify().VerifySources(self.conf)) source_mock = self.mox.CreateMock(source.Source) source_mock.Verify().AndReturn(1) self.mox.StubOutWithMock(source_factory, 'Create') source_factory.Create(self.conf.options[ config.MAP_PASSWORD].cache).AndReturn(source_mock) self.conf.maps = [config.MAP_PASSWORD] self.mox.ReplayAll() self.assertEquals(1, command.Verify().VerifySources(self.conf))
def testRunWithBadParameters(self): c = command.Verify() # Trap stderr so the unit test runs clean, # since unit test status is printed on stderr. dev_null = StringIO.StringIO() stderr = sys.stderr sys.stderr = dev_null self.assertEquals(2, c.Run(None, ['--invalid'])) sys.stderr = stderr
def testVerifySourcesGood(self): source_mock = self.mox.CreateMock(source.Source) source_mock.Verify().AndReturn(0) self.mox.StubOutWithMock(source_factory, 'Create') source_factory.Create(mox.IgnoreArg()).AndReturn(source_mock) self.conf.maps = [config.MAP_PASSWORD] self.mox.ReplayAll() self.assertEquals(0, command.Verify().VerifySources(self.conf))
def testVerifyMapsSkipsNetgroups(self): self.mox.StubOutWithMock(cache_factory, 'Create') self.conf.maps = [config.MAP_NETGROUP] self.mox.StubOutWithMock(nss, 'GetMap') self.mox.ReplayAll() c = command.Verify() self.assertEquals(0, c.VerifyMaps(self.conf))
def testRunWithParameters(self): def FakeVerifyConfiguration(conf): """Assert that we call VerifyConfiguration correctly.""" self.assertEquals(conf, self.conf) return (0, 0) def FakeVerifyMaps(conf): """Assert that VerifyMaps is called with a config object.""" self.assertEquals(conf, self.conf) return 0 config.VerifyConfiguration = FakeVerifyConfiguration c = command.Verify() c.VerifyMaps = FakeVerifyMaps self.assertEquals(0, c.Run(self.conf, ['-m', config.MAP_PASSWORD]))
def testVerifyMapsException(self): cache_mock = self.mox.CreateMock(caches.Cache) cache_mock.GetMap().AndRaise(error.CacheNotFound) self.mox.StubOutWithMock(cache_factory, 'Create') cache_factory.Create(self.conf.options[config.MAP_PASSWORD].cache, config.MAP_PASSWORD).AndReturn(cache_mock) self.conf.maps = [config.MAP_PASSWORD] self.mox.StubOutWithMock(nss, 'GetMap') nss.GetMap(config.MAP_PASSWORD).AndReturn(self.small_map) self.mox.ReplayAll() c = command.Verify() self.assertEquals(1, c.VerifyMaps(self.conf))
def testVerifyMapsSucceedsOnGoodMaps(self): cache_mock = self.mox.CreateMock(caches.Cache) cache_mock.GetMap().AndReturn(self.small_map) self.mox.StubOutWithMock(cache_factory, 'Create') cache_factory.Create(self.conf.options[config.MAP_PASSWORD].cache, config.MAP_PASSWORD).AndReturn(cache_mock) self.conf.maps = [config.MAP_PASSWORD] self.mox.StubOutWithMock(nss, 'GetMap') nss.GetMap(config.MAP_PASSWORD).AndReturn(self.big_map) self.mox.ReplayAll() c = command.Verify() self.assertEqual(0, c.VerifyMaps(self.conf))
def testRunWithNoParameters(self): def FakeVerifyConfiguration(conf): """Assert that we call VerifyConfiguration correctly.""" self.assertEqual(conf, self.conf) return (0, 0) def FakeVerifyMaps(conf): """Assert that VerifyMaps is called with a config object.""" self.assertEqual(conf, self.conf) return 0 config.VerifyConfiguration = FakeVerifyConfiguration c = command.Verify() c.VerifyMaps = FakeVerifyMaps self.conf.maps = [] self.assertEqual(1, c.Run(self.conf, []))
def testHelp(self): c = command.Verify() self.failIfEqual(None, c.Help())
def testConstructor(self): c = command.Verify() self.assertTrue(isinstance(c, command.Verify))
def testHelp(self): c = command.Verify() self.assertNotEqual(None, c.Help())