Пример #1
0
 def test_getresult_config_result_returns_false(self):
     conf = MagicMock(ConfigFile)
     type(conf).contents = PropertyMock(return_value=C.SAMPLE_CONFIG)
     pattern = ['interface GigabitEthernet1/0/27', '(shutdown)']
     expected = 'shutdown'
     case = audit.TestCase('testTest', pattern=pattern, expected=expected)
     self.assertFalse(case.get_result(conf))
Пример #2
0
 def test_init_properties_set(self):
     properties = self.properties
     case = audit.TestCase(properties['name'], properties['command'],
                           properties['pattern'], properties['expected'],
                           properties['type'])
     for attr in properties:
         self.assertEqual(getattr(case, attr), properties[attr])
Пример #3
0
 def test_properties_setter(self):
     properties = self.properties
     case = audit.TestCase(properties['name'])
     for attr in properties:
         if attr == 'name':
             continue
         setattr(case, attr, properties[attr])
         self.assertEqual(getattr(case, attr), properties[attr])
Пример #4
0
 def test_getresult_result_returns_false(self):
     conf = MagicMock(ConfigFile)
     conf.contents = PropertyMock()
     properties = self.properties
     case = audit.TestCase(properties['name'],
                           pattern=properties['pattern'],
                           expected=properties['expected'])
     result = case.get_result(conf)
     self.assertFalse(result)
Пример #5
0
 def test_getresult_result_returns_true(self):
     conf = MagicMock(ConfigFile)
     type(conf).contents = PropertyMock(return_value='PatternMatch')
     properties = self.properties
     case = audit.TestCase(properties['name'],
                           pattern=properties['pattern'],
                           expected=properties['expected'])
     result = case.get_result(conf)
     self.assertTrue(result)
Пример #6
0
 def test_getresult_deep_config_intermediate_returns_false(self):
     conf = MagicMock(ConfigFile)
     type(conf).contents = PropertyMock(return_value=C.SAMPLE_CONFIG)
     pattern = [
         'interface GigabitEthernet1/0/1$', 'Childish Configuration',
         'Grandchild (Configuration)'
     ]
     expected = 'Configuration'
     case = audit.TestCase('testTest', pattern=pattern, expected=expected)
     self.assertFalse(case.get_result(conf))
Пример #7
0
 def test_getresult_deep_config_intermediate_sets_message(self):
     conf = MagicMock(ConfigFile)
     type(conf).contents = PropertyMock(return_value=C.SAMPLE_CONFIG)
     pattern = [
         'interface GigabitEthernet1/0/1$', 'Childish Configuration',
         'Grandchild (Configuration)'
     ]
     expected = 'Configuration'
     case = audit.TestCase('testTest', pattern=pattern, expected=expected)
     case.get_result(conf)
     self.assertRegexpMatches(case.last_message, '^Could not find child')
Пример #8
0
    def setUp(self):
        patchers = {
            'TestCase': patch('netaudit.audit.TestCase', spec=True),
            'TestFile': patch('netaudit.audit.TestFile', spec=True)
        }
        mocks = {
            'TestCase': patchers['TestCase'].start(),
            'TestFile': patchers['TestFile'].start(),
        }
        self.patchers = patchers
        self.mocks = mocks
        for patcher in self.patchers.itervalues():
            self.addCleanup(patcher.stop)

        self.mocks['TestCase']().get_result.return_value = True

        self.mocks['TestFile'](
        ).find_test_by_name.return_value = audit.TestCase()
        type(mocks['TestFile']()).test_groups = PropertyMock(
            return_value={'testGroup1': ['test1']})
Пример #9
0
 def test_run_calls_testcase_getresult(self):
     suite = audit.AuditTests(C.FakeConfigFile())
     suite.tests = audit.TestFile('fake_file')
     suite.test_group = 'testGroup1'
     suite.run()
     audit.TestCase().get_result.assert_called_once_with(suite.config)