Move trigger tests into pytest
Note that we split the tests between endpoints/building and buildtrigger
This commit is contained in:
parent
a5dc885fc6
commit
306e79e493
3 changed files with 79 additions and 104 deletions
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from data import model
|
||||
from buildtrigger.triggerutil import raise_if_skipped_build, SkipRequestException
|
||||
from endpoints.building import (start_build, PreparedBuild, MaximumBuildsQueuedException,
|
||||
BuildTriggerDisabledException)
|
||||
|
||||
|
@ -41,3 +42,56 @@ def test_start_build_disabled_trigger(app):
|
|||
|
||||
with pytest.raises(BuildTriggerDisabledException):
|
||||
start_build(trigger.repository, build)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ref, expected_tags', [
|
||||
('ref/heads/somebranch', ['somebranch']),
|
||||
('ref/heads/master', ['master', 'latest']),
|
||||
|
||||
('ref/tags/somebranch', ['somebranch']),
|
||||
('ref/tags/master', ['master', 'latest']),
|
||||
|
||||
('ref/heads/slash/branch', ['slash_branch']),
|
||||
('ref/tags/slash/tag', ['slash_tag']),
|
||||
|
||||
('ref/heads/foobar#2', ['foobar_2']),
|
||||
])
|
||||
def test_tags_for_ref(ref, expected_tags):
|
||||
prepared = PreparedBuild()
|
||||
prepared.tags_from_ref(ref, default_branch='master')
|
||||
assert set(prepared._tags) == set(expected_tags)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('metadata, config', [
|
||||
({}, {}),
|
||||
pytest.param({'ref': 'ref/heads/master'}, {'branchtag_regex': 'nothing'}, id='branchtag regex'),
|
||||
pytest.param({
|
||||
'ref': 'ref/heads/master',
|
||||
'commit_info': {
|
||||
'message': '[skip build]',
|
||||
},
|
||||
}, {}, id='commit message'),
|
||||
])
|
||||
def test_skip(metadata, config):
|
||||
prepared = PreparedBuild()
|
||||
prepared.metadata = metadata
|
||||
config = config
|
||||
|
||||
with pytest.raises(SkipRequestException):
|
||||
raise_if_skipped_build(prepared, config)
|
||||
|
||||
|
||||
def test_does_not_skip():
|
||||
prepared = PreparedBuild()
|
||||
prepared.metadata = {
|
||||
'ref': 'ref/heads/master',
|
||||
'commit_info': {
|
||||
'message': 'some cool message',
|
||||
},
|
||||
}
|
||||
|
||||
config = {
|
||||
'branchtag_regex': '(master)|(heads/master)',
|
||||
}
|
||||
|
||||
raise_if_skipped_build(prepared, config)
|
||||
|
|
Reference in a new issue