Пример #1
0
    def test_registered_checks_success(self, factory):
        """Checks that have been registered in the factory cannot be created."""
        factory.register('check1', MyCheck1)
        factory.register('check2', MyCheck2)

        check = factory.create(CheckConfig('check1', 'error'))
        assert isinstance(check, MyCheck1)
        check = factory.create(CheckConfig('check2', 'error'))
        assert isinstance(check, MyCheck2)
Пример #2
0
 def test_missing_pattern_returns_error(self):
     check = PRTitleCheck(CheckConfig('title', 'error', pattern=''))
     result = check.run({'title': 'My title'})
     assert result.status == STATUS_ERROR
     assert result.error_code == ERROR_INVALID_CONFIG
     assert (result.details['message'] ==
             'PR title regex pattern not defined or empty')
Пример #3
0
 def test_missing_branch_returns_success(self):
     check = BranchNameCheck(CheckConfig('branch_name', 'error'))
     result = check.run({'branch': None})
     assert result.status == STATUS_PASS
     assert result.details['message'] == (
         'Branch name not available, skipping branch name validation '
         '(could be a detached head)')
Пример #4
0
    def test_unknown_checks_failure(self, factory):
        """A check that has not been registered in the factory cannot be created."""
        factory.register('check1', MyCheck1)
        factory.register('check2', MyCheck2)

        check = factory.create(CheckConfig('invalid', 'error'))
        assert check is None
Пример #5
0
    def test_default_config(self):
        check = BranchNameCheck(CheckConfig('branch_name', 'error'))
        result = check.run({'branch': 'some-thing-3-yo'})
        assert result.success is True

        result = check.run({'branch': 'invalid##name'})
        assert result.success is False
        assert result.error_code == ERROR_INVALID_BRANCH_NAME
Пример #6
0
 def test_missing_pattern_returns_error(self):
     for pattern in ('', None):
         check = BranchNameCheck(
             CheckConfig('branch_name', 'error', pattern=pattern))
         result = check.run({'branch': 'something'})
         assert result.status == STATUS_ERROR
         assert result.error_code == ERROR_INVALID_CONFIG
         assert (result.details['message'] ==
                 'Branch name regex pattern not defined or empty')
Пример #7
0
    def test_default_config(self):
        check = PRTitleCheck(CheckConfig('whatever', 'error'))

        result = check.run({'title': 'Upper first letter - 3233'})
        assert result.success is True

        result = check.run({'title': 'ALL CAPS'})
        assert result.success is True

        result = check.run({'title': 'lowercase THEN CAPS'})
        assert result.success is False
        assert result.error_code == ERROR_INVALID_PR_TITLE
Пример #8
0
    def test_custom_config(self):
        check = BranchNameCheck(
            CheckConfig('branch_name', 'error', pattern='^[abc99]+$'))
        result = check.run({'branch': 'ab9c9bb9ca9aa'})
        assert result.success is True

        result = check.run({'branch': 'ab9c9bb9-ca9aa'})
        assert result.success is False
        assert result.error_code == ERROR_INVALID_BRANCH_NAME

        result = check.run({'branch': 'db9c9bb9ca9aa'})
        assert result.success is False
        assert result.error_code == ERROR_INVALID_BRANCH_NAME
Пример #9
0
    def test_custom_config(self):
        check = PRTitleCheck(
            CheckConfig('title', 'error', pattern='^[abc99]+$'))

        result = check.run({'title': 'ab9c9bb9ca9aa'})
        assert result.success is True

        result = check.run({'title': 'ab9c9bb9-ca9aa'})
        assert result.success is False
        assert result.error_code == ERROR_INVALID_PR_TITLE

        result = check.run({'title': 'db9c9bb9ca9aa'})
        assert result.success is False
        assert result.error_code == ERROR_INVALID_PR_TITLE
Пример #10
0
 def custom_check(self):
     options = {
         'subject': {
             'min_length': 2,
             'max_length': 5,
             'pattern': '^[a-z]+$'
         },
         'body': {
             'max_line_length': 10,
             'smart_require': {
                 'min_changes': 5,
                 'min_body_lines': 3
             },
         },
     }
     return CommitMessagesCheck(CheckConfig('whatever', 'error', **options))
Пример #11
0
 def test_missing_key_from_config_fails_with_error(self, custom_config):
     """If the content of a commit does not include required keys,
     the check should fail with an error."""
     del custom_config['subject']
     check = CommitMessagesCheck(
         CheckConfig('whatever', 'error', **custom_config))
     result = check.run(
         {'commits': [{
             'message': 'xxxxx',
             'sha': 'aa',
             'url': ''
         }]})
     assert result.success is False
     assert result.status is 'error'
     assert result.error_code is 'invalid_content'
     assert "Missing key: 'stats'" in result.details['message']
Пример #12
0
 def test_no_body_max_line_length_option_ignored(self, custom_config):
     """If the config does not include a body.max_line_length option,
     no upper limit should be rejected."""
     del custom_config['body']['max_line_length']
     check = CommitMessagesCheck(
         CheckConfig('whatever', 'error', **custom_config))
     result = check.run({
         'commits': [{
             'stats': {
                 'total': 2
             },
             'message': 'xxxxx\n\n{}'.format('A' * 1000),
             'sha': 'aa',
             'url': '',
         }]
     })
     assert result.success is True
Пример #13
0
 def test_no_subject_min_length_option_ignored(self, custom_config):
     """If the config does not include a subject.min_length option,
     no lower limit should be rejected."""
     del custom_config['subject']['min_length']
     check = CommitMessagesCheck(
         CheckConfig('whatever', 'error', **custom_config))
     result = check.run({
         'commits': [{
             'stats': {
                 'total': 2
             },
             'message': 'x' * 1,
             'sha': 'aa',
             'url': ''
         }]
     })
     assert result.success is True
Пример #14
0
 def test_no_subject_pattern_option_ignored(self, custom_config):
     """If the config does not include a subject.pattern option,
     no pattern should be rejected."""
     del custom_config['subject']['pattern']
     check = CommitMessagesCheck(
         CheckConfig('whatever', 'error', **custom_config))
     result = check.run({
         'commits': [{
             'stats': {
                 'total': 2
             },
             'message': 'A82%@$',
             'sha': 'aa',
             'url': ''
         }]
     })
     assert result.success is True
Пример #15
0
    def test_all(self):
        check = PRBodyExcludesCheck(
            CheckConfig('whatever', 'error', patterns=['forbidden', 'fruit']))

        result = check.run({'body': 'Something about something else'})
        assert result.success is True

        result = check.run({'body': 'I love eating fruit'})
        assert result.success is False
        assert result.error_code == ERROR_FORBIDDEN_PR_BODY_TEXT

        result = check.run({'body': 'This is forbidden'})
        assert result.success is False
        assert result.error_code == ERROR_FORBIDDEN_PR_BODY_TEXT

        result = check.run({'body': 'Fruit is forbidden here'})
        assert result.success is False
        assert result.error_code == ERROR_FORBIDDEN_PR_BODY_TEXT
Пример #16
0
 def test_no_body_smart_require_min_body_lines_option_ignored(
         self, custom_config):
     """If the config does not include a body.smart_require.min_changes option,
     no smart check should be performed."""
     del custom_config['body']['smart_require']['min_changes']
     check = CommitMessagesCheck(
         CheckConfig('whatever', 'error', **custom_config))
     result = check.run({
         'commits': [{
             'stats': {
                 'total': 2000
             },
             'message': 'xxxxx',
             'sha': 'aa',
             'url': '',
         }]
     })
     assert result.success is True
Пример #17
0
    def test_all(self):
        check = PRBodyChecklistCheck(CheckConfig('whatever', 'error'))

        result = check.run(
            {'body': 'This is something. \n- [x]\n- [x]\n\n* [x]'})
        assert result.success is True

        result = check.run({'body': 'This is something. \n- []'})
        assert result.success is True

        result = check.run(
            {'body': 'This is something. \n- [ ]\n- [x]\n\n* [x]'})
        assert result.success is False
        assert result.error_code == ERROR_UNFINISHED_CHECKLIST

        result = check.run(
            {'body': 'This is something. \n- [x]\n- [x]\n\n* [ ]'})
        assert result.success is False
        assert result.error_code == ERROR_UNFINISHED_CHECKLIST
Пример #18
0
    def test_all(self):
        check = PRBodyIncludesCheck(
            CheckConfig('whatever', 'error', patterns=['must-be', 'present']))

        result = check.run({'body': 'Things must-be present'})
        assert result.success is True

        result = check.run({'body': 'A good present is a must-be'})
        assert result.success is True

        result = check.run({'body': 'present must be'})
        assert result.success is False
        assert result.error_code == ERROR_MISSING_PR_BODY_TEXT

        result = check.run({'body': 'must-be pres-ent'})
        assert result.success is False
        assert result.error_code == ERROR_MISSING_PR_BODY_TEXT

        result = check.run({'body': 'totally unrelated'})
        assert result.success is False
        assert result.error_code == ERROR_MISSING_PR_BODY_TEXT
Пример #19
0
 def test_missing_title_returns_error(self):
     check = PRTitleCheck(CheckConfig('title', 'error'))
     result = check.run({})  # no 'title' entry
     assert result.status == STATUS_ERROR
     assert result.error_code == ERROR_INVALID_CONTENT
     assert result.details['message'] == 'PR title not defined or empty'
Пример #20
0
 def test_default_config_is_none(self):
     check = Check(CheckConfig('mytype', 'error'))
     assert check._default_config('anything') is None
Пример #21
0
 def test_check_type_property_returns_proper_value(self):
     check = Check(CheckConfig('mytype', 'error'))
     assert check.check_type == 'mytype'
Пример #22
0
 def default_check(self):
     return CommitMessagesCheck(CheckConfig('whatever', 'error'))
Пример #23
0
 def test_empty_branch_returns_error(self):
     check = BranchNameCheck(CheckConfig('branch_name', 'error'))
     result = check.run({'branch': ''})
     assert result.status == STATUS_ERROR
     assert result.error_code == ERROR_INVALID_CONTENT
     assert result.details['message'] == 'Branch name not defined or empty'