2017-02-13 18:50:14 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from buildtrigger.triggerutil import TriggerStartException
|
2017-02-13 20:01:09 +00:00
|
|
|
from buildtrigger.test.bitbucketmock import get_bitbucket_trigger
|
2017-02-13 18:50:14 +00:00
|
|
|
from buildtrigger.test.githubmock import get_github_trigger
|
|
|
|
from endpoints.building import PreparedBuild
|
|
|
|
|
2017-02-13 22:42:37 +00:00
|
|
|
# Note: This test suite executes a common set of tests against all the trigger types specified
|
|
|
|
# in this fixture. Each trigger's mock is expected to return the same data for all of these calls.
|
2018-06-11 19:22:02 +00:00
|
|
|
@pytest.fixture(params=[get_github_trigger(), get_bitbucket_trigger()])
|
2017-02-13 18:50:14 +00:00
|
|
|
def githost_trigger(request):
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('run_parameters, expected_error, expected_message', [
|
|
|
|
# No branch or tag specified: use the commit of the default branch.
|
|
|
|
({}, None, None),
|
|
|
|
|
|
|
|
# Invalid branch.
|
|
|
|
({'refs': {'kind': 'branch', 'name': 'invalid'}}, TriggerStartException,
|
|
|
|
'Could not find branch in repository'),
|
|
|
|
|
|
|
|
# Invalid tag.
|
|
|
|
({'refs': {'kind': 'tag', 'name': 'invalid'}}, TriggerStartException,
|
|
|
|
'Could not find tag in repository'),
|
|
|
|
|
|
|
|
# Valid branch.
|
|
|
|
({'refs': {'kind': 'branch', 'name': 'master'}}, None, None),
|
|
|
|
|
|
|
|
# Valid tag.
|
|
|
|
({'refs': {'kind': 'tag', 'name': 'sometag'}}, None, None),
|
|
|
|
])
|
|
|
|
def test_manual_start(run_parameters, expected_error, expected_message, githost_trigger):
|
|
|
|
if expected_error is not None:
|
|
|
|
with pytest.raises(expected_error) as ipe:
|
|
|
|
githost_trigger.manual_start(run_parameters)
|
|
|
|
assert ipe.value.message == expected_message
|
|
|
|
else:
|
|
|
|
assert isinstance(githost_trigger.manual_start(run_parameters), PreparedBuild)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('name, expected', [
|
|
|
|
('refs', [
|
|
|
|
{'kind': 'branch', 'name': 'master'},
|
|
|
|
{'kind': 'branch', 'name': 'otherbranch'},
|
|
|
|
{'kind': 'tag', 'name': 'sometag'},
|
|
|
|
{'kind': 'tag', 'name': 'someothertag'},
|
|
|
|
]),
|
2017-02-13 20:01:09 +00:00
|
|
|
('tag_name', set(['sometag', 'someothertag'])),
|
|
|
|
('branch_name', set(['master', 'otherbranch'])),
|
2017-02-13 18:50:14 +00:00
|
|
|
('invalid', None)
|
|
|
|
])
|
|
|
|
def test_list_field_values(name, expected, githost_trigger):
|
2017-02-13 20:01:09 +00:00
|
|
|
if expected is None:
|
|
|
|
assert githost_trigger.list_field_values(name) is None
|
|
|
|
elif isinstance(expected, set):
|
|
|
|
assert set(githost_trigger.list_field_values(name)) == set(expected)
|
|
|
|
else:
|
|
|
|
assert githost_trigger.list_field_values(name) == expected
|
2017-02-13 18:50:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_build_source_namespaces(githost_trigger):
|
|
|
|
namespaces_expected = [
|
|
|
|
{
|
|
|
|
'personal': True,
|
|
|
|
'score': 1,
|
|
|
|
'avatar_url': 'avatarurl',
|
|
|
|
'id': 'knownuser',
|
2017-02-13 20:01:09 +00:00
|
|
|
'title': 'knownuser',
|
|
|
|
'url': 'https://bitbucket.org/knownuser',
|
2017-02-13 18:50:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'score': 2,
|
|
|
|
'title': 'someorg',
|
|
|
|
'personal': False,
|
2017-02-13 20:01:09 +00:00
|
|
|
'url': 'https://bitbucket.org/someorg',
|
2017-02-13 18:50:14 +00:00
|
|
|
'avatar_url': 'avatarurl',
|
|
|
|
'id': 'someorg'
|
|
|
|
}
|
|
|
|
]
|
2017-02-13 23:32:32 +00:00
|
|
|
|
|
|
|
found = githost_trigger.list_build_source_namespaces()
|
|
|
|
found.sort()
|
|
|
|
|
|
|
|
namespaces_expected.sort()
|
|
|
|
assert found == namespaces_expected
|
2017-02-13 18:50:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('namespace, expected', [
|
|
|
|
('', []),
|
|
|
|
('unknown', []),
|
|
|
|
|
|
|
|
('knownuser', [
|
|
|
|
{
|
2017-02-13 20:01:09 +00:00
|
|
|
'last_updated': 0, 'name': 'somerepo',
|
|
|
|
'url': 'https://bitbucket.org/knownuser/somerepo', 'private': True,
|
2017-02-13 18:50:14 +00:00
|
|
|
'full_name': 'knownuser/somerepo', 'has_admin_permissions': True,
|
|
|
|
'description': 'some somerepo repo'
|
|
|
|
}]),
|
|
|
|
|
|
|
|
('someorg', [
|
|
|
|
{
|
2017-02-13 20:01:09 +00:00
|
|
|
'last_updated': 0, 'name': 'somerepo',
|
|
|
|
'url': 'https://bitbucket.org/someorg/somerepo', 'private': True,
|
|
|
|
'full_name': 'someorg/somerepo', 'has_admin_permissions': False,
|
2017-02-13 18:50:14 +00:00
|
|
|
'description': 'some somerepo repo'
|
|
|
|
},
|
|
|
|
{
|
2017-02-13 20:01:09 +00:00
|
|
|
'last_updated': 0, 'name': 'anotherrepo',
|
|
|
|
'url': 'https://bitbucket.org/someorg/anotherrepo', 'private': False,
|
|
|
|
'full_name': 'someorg/anotherrepo', 'has_admin_permissions': False,
|
2017-02-13 18:50:14 +00:00
|
|
|
'description': 'some anotherrepo repo'
|
|
|
|
}]),
|
|
|
|
])
|
|
|
|
def test_list_build_sources_for_namespace(namespace, expected, githost_trigger):
|
|
|
|
assert githost_trigger.list_build_sources_for_namespace(namespace) == expected
|
|
|
|
|
|
|
|
|
2018-06-01 21:07:04 +00:00
|
|
|
def test_activate_and_deactivate(githost_trigger):
|
2017-02-13 23:04:41 +00:00
|
|
|
_, private_key = githost_trigger.activate('http://some/url')
|
2017-02-13 18:50:14 +00:00
|
|
|
assert 'private_key' in private_key
|
|
|
|
githost_trigger.deactivate()
|