コード例 #1
0
    @patch('ztpserver.repository.FileObject')
    def test_get_file_success(self, m_fileobj, _):
        store = Repository(random_string())
        store.get_file(random_string())
        self.assertTrue(m_fileobj.called)

    @patch('os.path.exists')
    @patch('ztpserver.repository.FileObject')
    def test_get_file_failure(self, m_fileobj, m_exists):
        m_exists.return_value = False
        store = Repository(random_string())
        self.assertRaises(FileObjectNotFound, store.get_file, random_string())
        self.assertFalse(m_fileobj.called)

    @patch('os.remove')
    def test_delete_file_success(self, m_remove):
        store = Repository(random_string())
        store.delete_file(random_string())
        self.assertTrue(m_remove.called)

    @patch('os.remove')
    def test_delete_file_failure(self, m_remove):
        m_remove.side_effect = OSError
        store = Repository(random_string())
        self.assertRaises(RepositoryError, store.delete_file, random_string())


if __name__ == '__main__':
    enable_logging()
    unittest.main()
コード例 #2
0
ファイル: test_ndb.py プロジェクト: arista-eosplus/ztpserver
            for test in tests:
                assert test in ['pattern', 'topology']
                suite.addTest(NeighbordbTest('neighbordb_%s' % test, 
                                             ndb, **kwargs))

            if 'nodes' in harness and 'topology' in tests:
                for key in harness['nodes'].keys():
                    assert key in ['pass', 'fail']
                    entries = harness['nodes'][key]
                    if not entries is None:
                        for entry in entries:
                            filename = entry['name'].split('/')[-1]
                            kwargs['node'] = harness.get(filename, 
                                                         entry['name'])
                            kwargs['match'] = entry.get('match')
                            kwargs['tag'] = '%s:%s' % (harness.get('tag'), 
                                                       filename)
                            log.info('Adding node %s', name)
                            suite.addTest(NeighbordbTest('node_%s' % key, 
                                                         ndb, **kwargs))

    except Exception as exc:      # pylint: disable=W0703
        log.exception('Unexpected error trying to execute load_tests: %s' %
                      exc)
    else:
        return suite

if __name__ == '__main__':
    enable_logging()
    unittest.main()