Add unit testing of bitbucket trigger handler

This commit is contained in:
Joseph Schorr 2017-02-13 15:01:09 -05:00
parent ba301b401b
commit 497c90e7ea
7 changed files with 217 additions and 51 deletions

View file

@ -1,13 +1,11 @@
import pytest
from buildtrigger.triggerutil import TriggerStartException
from buildtrigger.test.bitbucketmock import get_bitbucket_trigger
from buildtrigger.test.githubmock import get_github_trigger
from endpoints.building import PreparedBuild
def github_trigger():
return get_github_trigger()
@pytest.fixture(params=[github_trigger()])
@pytest.fixture(params=[get_github_trigger(), get_bitbucket_trigger()])
def githost_trigger(request):
return request.param
@ -38,14 +36,6 @@ def test_manual_start(run_parameters, expected_error, expected_message, githost_
assert isinstance(githost_trigger.manual_start(run_parameters), PreparedBuild)
@pytest.mark.parametrize('username, expected_response', [
('unknownuser', None),
('knownuser', {'html_url': 'htmlurl', 'avatar_url': 'avatarurl'}),
])
def test_lookup_user(username, expected_response, githost_trigger):
assert githost_trigger.lookup_user(username) == expected_response
@pytest.mark.parametrize('name, expected', [
('refs', [
{'kind': 'branch', 'name': 'master'},
@ -53,16 +43,17 @@ def test_lookup_user(username, expected_response, githost_trigger):
{'kind': 'tag', 'name': 'sometag'},
{'kind': 'tag', 'name': 'someothertag'},
]),
('tag_name', ['sometag', 'someothertag']),
('branch_name', ['master', 'otherbranch']),
('tag_name', set(['sometag', 'someothertag'])),
('branch_name', set(['master', 'otherbranch'])),
('invalid', None)
])
def test_list_field_values(name, expected, githost_trigger):
assert githost_trigger.list_field_values(name) == expected
def test_list_build_subdirs(githost_trigger):
assert githost_trigger.list_build_subdirs() == ['', 'somesubdir']
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
def test_list_build_source_namespaces(githost_trigger):
@ -72,13 +63,14 @@ def test_list_build_source_namespaces(githost_trigger):
'score': 1,
'avatar_url': 'avatarurl',
'id': 'knownuser',
'title': 'knownuser'
'title': 'knownuser',
'url': 'https://bitbucket.org/knownuser',
},
{
'score': 2,
'title': 'someorg',
'personal': False,
'url': 'htmlurl',
'url': 'https://bitbucket.org/someorg',
'avatar_url': 'avatarurl',
'id': 'someorg'
}
@ -92,20 +84,23 @@ def test_list_build_source_namespaces(githost_trigger):
('knownuser', [
{
'last_updated': 0, 'name': 'somerepo', 'url': 'http://some/url', 'private': True,
'last_updated': 0, 'name': 'somerepo',
'url': 'https://bitbucket.org/knownuser/somerepo', 'private': True,
'full_name': 'knownuser/somerepo', 'has_admin_permissions': True,
'description': 'some somerepo repo'
}]),
('someorg', [
{
'last_updated': 0, 'name': 'somerepo', 'url': 'http://some/url',
'private': True, 'full_name': 'someorg/somerepo', 'has_admin_permissions': False,
'last_updated': 0, 'name': 'somerepo',
'url': 'https://bitbucket.org/someorg/somerepo', 'private': True,
'full_name': 'someorg/somerepo', 'has_admin_permissions': False,
'description': 'some somerepo repo'
},
{
'last_updated': 0, 'name': 'anotherrepo', 'url': 'http://some/url',
'private': False, 'full_name': 'someorg/anotherrepo', 'has_admin_permissions': False,
'last_updated': 0, 'name': 'anotherrepo',
'url': 'https://bitbucket.org/someorg/anotherrepo', 'private': False,
'full_name': 'someorg/anotherrepo', 'has_admin_permissions': False,
'description': 'some anotherrepo repo'
}]),
])
@ -117,7 +112,6 @@ def test_list_build_sources_for_namespace(namespace, expected, githost_trigger):
def test_activate(githost_trigger):
config, private_key = githost_trigger.activate('http://some/url')
assert 'deploy_key_id' in config
assert 'hook_id' in config
assert 'private_key' in private_key