コード例 #1
0
 def test_whitelist_regex_with_comments(self):
     whitelist_file = six.StringIO()
     for i in range(4):
         whitelist_file.write('fake_regex_%s # A Comment\n' % i)
     whitelist_file.seek(0)
     with mock.patch('six.moves.builtins.open',
                     return_value=whitelist_file):
         result = os_testr.construct_regex(None, 'fake_path', None, False)
     self.assertEqual(
         result, "fake_regex_0|fake_regex_1|fake_regex_2|fake_regex_3")
コード例 #2
0
 def test_blacklist_regex_without_comments(self):
     blacklist_file = six.StringIO()
     for i in range(4):
         blacklist_file.write('fake_regex_%s\n' % i)
     blacklist_file.seek(0)
     with mock.patch('six.moves.builtins.open',
                     return_value=blacklist_file):
         result = os_testr.construct_regex('fake_path', None, None, False)
     self.assertEqual(
         result,
         "^((?!fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0).)*$")
コード例 #3
0
ファイル: test_os_testr.py プロジェクト: bdrich/neutron-lbaas
 def test_whitelist_regex_with_comments(self):
     whitelist_file = six.StringIO()
     for i in range(4):
         whitelist_file.write('fake_regex_%s # A Comment\n' % i)
     whitelist_file.seek(0)
     with mock.patch('six.moves.builtins.open',
                     return_value=whitelist_file):
         result = os_testr.construct_regex(None, 'fake_path', None, False)
     self.assertEqual(
         result,
         "fake_regex_0|fake_regex_1|fake_regex_2|fake_regex_3")
コード例 #4
0
 def test_blacklist_regex_without_comments(self):
     blacklist_file = six.StringIO()
     for i in range(4):
         blacklist_file.write('fake_regex_%s\n' % i)
     blacklist_file.seek(0)
     with mock.patch('six.moves.builtins.open',
                     return_value=blacklist_file):
         result = os_testr.construct_regex('fake_path', None, None, False)
     self.assertEqual(
         result,
         "^((?!fake_regex_3|fake_regex_2|fake_regex_1|fake_regex_0).)*$")
コード例 #5
0
    def test_whitelist_regex_without_comments_and_regex(self):
        file_contents = """regex_a
regex_b"""
        whitelist_file = six.StringIO()
        whitelist_file.write(file_contents)
        whitelist_file.seek(0)
        with mock.patch('six.moves.builtins.open',
                        return_value=whitelist_file):
            result = os_testr.construct_regex(None, 'fake_path', None, False)

            expected_regex = 'regex_a|regex_b'
            self.assertEqual(result, expected_regex)
コード例 #6
0
    def test_whitelist_regex_without_comments_and_regex(self):
        file_contents = """regex_a
regex_b"""
        whitelist_file = six.StringIO()
        whitelist_file.write(file_contents)
        whitelist_file.seek(0)
        with mock.patch('six.moves.builtins.open',
                        return_value=whitelist_file):
            result = os_testr.construct_regex(None, 'fake_path',
                                              None, False)

            expected_regex = 'regex_a|regex_b'
            self.assertEqual(result, expected_regex)
コード例 #7
0
    def test_blacklist_regex_with_comments_and_regex(self):
        blacklist_file = six.StringIO()
        for i in range(4):
            blacklist_file.write('fake_regex_%s # Comments\n' % i)
        blacklist_file.seek(0)
        with mock.patch('six.moves.builtins.open',
                        return_value=blacklist_file):
            result = os_testr.construct_regex('fake_path', None,
                                              'fake_regex', False)

            expected_regex = ("^((?!fake_regex_3|fake_regex_2|fake_regex_1|"
                              "fake_regex_0).)*$fake_regex")
            self.assertEqual(result, expected_regex)
コード例 #8
0
    def test_blacklist_regex_with_comments_and_regex(self):
        blacklist_file = six.StringIO()
        for i in range(4):
            blacklist_file.write('fake_regex_%s # Comments\n' % i)
        blacklist_file.seek(0)
        with mock.patch('six.moves.builtins.open',
                        return_value=blacklist_file):
            result = os_testr.construct_regex('fake_path', None, 'fake_regex',
                                              False)

            expected_regex = ("^((?!fake_regex_3|fake_regex_2|fake_regex_1|"
                              "fake_regex_0).)*$fake_regex")
            self.assertEqual(result, expected_regex)
コード例 #9
0
    def test_blacklist_regex_without_comment_print_skips(self, print_mock):
        blacklist_file = six.StringIO()
        for i in range(4):
            blacklist_file.write('fake_regex_%s\n' % i)
        blacklist_file.seek(0)
        with mock.patch('six.moves.builtins.open',
                        return_value=blacklist_file):
            result = os_testr.construct_regex('fake_path', None, None, True)

        expected_regex = ("^((?!fake_regex_3|fake_regex_2|"
                          "fake_regex_1|fake_regex_0).)*$")
        self.assertEqual(result, expected_regex)
        calls = print_mock.mock_calls
        self.assertEqual(len(calls), 4)
        args = list(map(lambda x: x[1], calls))
        self.assertIn(('fake_regex_0', ''), args)
        self.assertIn(('fake_regex_1', ''), args)
        self.assertIn(('fake_regex_2', ''), args)
        self.assertIn(('fake_regex_3', ''), args)
コード例 #10
0
    def test_blacklist_regex_without_comment_print_skips(self, print_mock):
        blacklist_file = six.StringIO()
        for i in range(4):
            blacklist_file.write('fake_regex_%s\n' % i)
        blacklist_file.seek(0)
        with mock.patch('six.moves.builtins.open',
                        return_value=blacklist_file):
            result = os_testr.construct_regex('fake_path', None,
                                              None, True)

        expected_regex = ("^((?!fake_regex_3|fake_regex_2|"
                          "fake_regex_1|fake_regex_0).)*$")
        self.assertEqual(result, expected_regex)
        calls = print_mock.mock_calls
        self.assertEqual(len(calls), 4)
        args = list(map(lambda x: x[1], calls))
        self.assertIn(('fake_regex_0', ''), args)
        self.assertIn(('fake_regex_1', ''), args)
        self.assertIn(('fake_regex_2', ''), args)
        self.assertIn(('fake_regex_3', ''), args)
コード例 #11
0
 def test_regex_passthrough(self):
     result = os_testr.construct_regex(None, None, 'fake_regex', False)
     self.assertEqual(result, 'fake_regex')
コード例 #12
0
 def test_regex_passthrough(self):
     result = os_testr.construct_regex(None, None, 'fake_regex', False)
     self.assertEqual(result, 'fake_regex')