Example #1
0
    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
Example #2
0
    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))
Example #3
0
 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
Example #4
0
    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))
Example #5
0
    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))
Example #6
0
    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]))
Example #7
0
    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))
Example #8
0
    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))
Example #9
0
    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, []))
Example #10
0
 def testHelp(self):
     c = command.Verify()
     self.failIfEqual(None, c.Help())
Example #11
0
 def testConstructor(self):
     c = command.Verify()
     self.assertTrue(isinstance(c, command.Verify))
Example #12
0
 def testHelp(self):
     c = command.Verify()
     self.assertNotEqual(None, c.Help())