Merge pull request #545 from coreos-inc/githubtriggerschemafix
Trigger schema fixes and tests
This commit is contained in:
commit
a0b191ffa1
3 changed files with 186 additions and 56 deletions
|
@ -56,7 +56,6 @@ GITHUB_WEBHOOK_PAYLOAD_SCHEMA = {
|
|||
'type': 'string'
|
||||
},
|
||||
},
|
||||
'required': ['username'],
|
||||
},
|
||||
'committer': {
|
||||
'type': 'object',
|
||||
|
@ -71,7 +70,6 @@ GITHUB_WEBHOOK_PAYLOAD_SCHEMA = {
|
|||
'type': 'string'
|
||||
},
|
||||
},
|
||||
'required': ['username'],
|
||||
},
|
||||
},
|
||||
'required': ['id', 'url', 'message', 'timestamp'],
|
||||
|
|
|
@ -9,10 +9,19 @@ from buildtrigger.githubhandler import get_transformed_webhook_payload as gh_web
|
|||
from buildtrigger.gitlabhandler import get_transformed_webhook_payload as gl_webhook
|
||||
|
||||
class TestPrepareTrigger(unittest.TestCase):
|
||||
def test_bitbucket_customer_payload_noauthor(self):
|
||||
with open('test/triggerjson/bitbucket_customer_example_noauthor.json') as f:
|
||||
def assertSchema(self, filename, expected, processor, *args, **kwargs):
|
||||
with open('test/triggerjson/%s.json' % filename) as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
nargs = [payload]
|
||||
nargs.extend(args)
|
||||
|
||||
created = processor(*nargs, **kwargs)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
|
||||
|
||||
def test_bitbucket_customer_payload_noauthor(self):
|
||||
expected = {
|
||||
"commit": "a0ec139843b2bb281ab21a433266ddc498e605dc",
|
||||
"ref": "refs/heads/master",
|
||||
|
@ -29,15 +38,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
created = bb_webhook(payload)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('bitbucket_customer_example_noauthor', expected, bb_webhook)
|
||||
|
||||
|
||||
def test_bitbucket_customer_payload_tag(self):
|
||||
with open('test/triggerjson/bitbucket_customer_example_tag.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
"commit": "a0ec139843b2bb281ab21a433266ddc498e605dc",
|
||||
"ref": "refs/tags/0.1.2",
|
||||
|
@ -54,15 +58,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
created = bb_webhook(payload)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('bitbucket_customer_example_tag', expected, bb_webhook)
|
||||
|
||||
|
||||
def test_bitbucket_commit(self):
|
||||
with open('test/triggerjson/bitbucket_commit.json') as f:
|
||||
commit = json.loads(f.read())
|
||||
|
||||
ref = 'refs/heads/somebranch'
|
||||
default_branch = 'somebranch'
|
||||
repository_name = 'foo/bar'
|
||||
|
@ -92,15 +91,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
}
|
||||
}
|
||||
|
||||
created = bb_commit(commit, ref, default_branch, repository_name, lookup_author)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
|
||||
self.assertSchema('bitbucket_commit', expected, bb_commit, ref, default_branch,
|
||||
repository_name, lookup_author)
|
||||
|
||||
def test_bitbucket_webhook_payload(self):
|
||||
with open('test/triggerjson/bitbucket_webhook.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
"commit": u"af64ae7188685f8424040b4735ad12941b980d75",
|
||||
"ref": u"refs/heads/master",
|
||||
|
@ -122,15 +116,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
created = bb_webhook(payload)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('bitbucket_webhook', expected, bb_webhook)
|
||||
|
||||
|
||||
def test_github_webhook_payload(self):
|
||||
with open('test/triggerjson/github_webhook.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
'commit': u'410f4cdf8ff09b87f245b13845e8497f90b90a4c',
|
||||
'ref': u'refs/heads/master',
|
||||
|
@ -148,15 +137,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
created = gh_webhook(payload)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('github_webhook', expected, gh_webhook)
|
||||
|
||||
|
||||
def test_github_webhook_payload_with_lookup(self):
|
||||
with open('test/triggerjson/github_webhook.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
'commit': u'410f4cdf8ff09b87f245b13845e8497f90b90a4c',
|
||||
'ref': u'refs/heads/master',
|
||||
|
@ -184,15 +168,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
'avatar_url': 'http://some/avatar/url'
|
||||
}
|
||||
|
||||
created = gh_webhook(payload, lookup_user=lookup_user)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('github_webhook', expected, gh_webhook, lookup_user=lookup_user)
|
||||
|
||||
|
||||
def test_gitlab_webhook_payload(self):
|
||||
with open('test/triggerjson/gitlab_webhook.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
'commit': u'fb88379ee45de28a0a4590fddcbd8eff8b36026e',
|
||||
'ref': u'refs/heads/master',
|
||||
|
@ -204,15 +183,25 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
created = gl_webhook(payload)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('gitlab_webhook', expected, gl_webhook)
|
||||
|
||||
|
||||
def test_github_webhook_payload_known_issue(self):
|
||||
expected = {
|
||||
"commit": "118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"ref": "refs/heads/master",
|
||||
"git_url": "git@github.com:silas/docker-test.git",
|
||||
"commit_info": {
|
||||
"url": "https://github.com/silas/docker-test/commit/118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"date": "2015-09-25T14:55:11-04:00",
|
||||
"message": "Fail",
|
||||
},
|
||||
}
|
||||
|
||||
self.assertSchema('github_webhook_noname', expected, gh_webhook)
|
||||
|
||||
|
||||
def test_github_webhook_payload_missing_fields(self):
|
||||
with open('test/triggerjson/github_webhook_missing.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
'commit': u'410f4cdf8ff09b87f245b13845e8497f90b90a4c',
|
||||
'ref': u'refs/heads/master',
|
||||
|
@ -224,15 +213,10 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
created = gh_webhook(payload)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('github_webhook_missing', expected, gh_webhook)
|
||||
|
||||
|
||||
def test_gitlab_webhook_payload_with_lookup(self):
|
||||
with open('test/triggerjson/gitlab_webhook.json') as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
expected = {
|
||||
'commit': u'fb88379ee45de28a0a4590fddcbd8eff8b36026e',
|
||||
'ref': u'refs/heads/master',
|
||||
|
@ -256,9 +240,8 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
'avatar_url': 'http://some/avatar/url',
|
||||
}
|
||||
|
||||
created = gl_webhook(payload, lookup_user=lookup_user)
|
||||
self.assertEquals(expected, created)
|
||||
validate(created, METADATA_SCHEMA)
|
||||
self.assertSchema('gitlab_webhook', expected, gl_webhook, lookup_user=lookup_user)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
149
test/triggerjson/github_webhook_noname.json
Normal file
149
test/triggerjson/github_webhook_noname.json
Normal file
|
@ -0,0 +1,149 @@
|
|||
{
|
||||
"ref": "refs/heads/master",
|
||||
"before": "9716b516939221dc754a056e0f9ddf599e71d4b8",
|
||||
"after": "118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"created": false,
|
||||
"deleted": false,
|
||||
"forced": false,
|
||||
"base_ref": null,
|
||||
"compare": "https://github.com/silas/docker-test/compare/9716b5169392...118b07121695",
|
||||
"commits": [
|
||||
{
|
||||
"id": "118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"distinct": true,
|
||||
"message": "Fail",
|
||||
"timestamp": "2015-09-25T14:55:11-04:00",
|
||||
"url": "https://github.com/silas/docker-test/commit/118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"author": {
|
||||
"name": "Silas Sewell",
|
||||
"email": "silas@sewell-fail.org"
|
||||
},
|
||||
"committer": {
|
||||
"name": "Silas Sewell",
|
||||
"email": "silas@sewell-fail.org"
|
||||
},
|
||||
"added": [],
|
||||
"removed": [],
|
||||
"modified": [
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
],
|
||||
"head_commit": {
|
||||
"id": "118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"distinct": true,
|
||||
"message": "Fail",
|
||||
"timestamp": "2015-09-25T14:55:11-04:00",
|
||||
"url": "https://github.com/silas/docker-test/commit/118b07121695d9f2e40a5ff264fdcc2917680870",
|
||||
"author": {
|
||||
"name": "Silas Sewell",
|
||||
"email": "silas@sewell-fail.org"
|
||||
},
|
||||
"committer": {
|
||||
"name": "Silas Sewell",
|
||||
"email": "silas@sewell-fail.org"
|
||||
},
|
||||
"added": [],
|
||||
"removed": [],
|
||||
"modified": [
|
||||
"README.md"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"id": 42467431,
|
||||
"name": "docker-test",
|
||||
"full_name": "silas/docker-test",
|
||||
"owner": {
|
||||
"name": "silas",
|
||||
"email": "silas@sewell.org"
|
||||
},
|
||||
"private": false,
|
||||
"html_url": "https://github.com/silas/docker-test",
|
||||
"description": "",
|
||||
"fork": false,
|
||||
"url": "https://github.com/silas/docker-test",
|
||||
"forks_url": "https://api.github.com/repos/silas/docker-test/forks",
|
||||
"keys_url": "https://api.github.com/repos/silas/docker-test/keys{/key_id}",
|
||||
"collaborators_url": "https://api.github.com/repos/silas/docker-test/collaborators{/collaborator}",
|
||||
"teams_url": "https://api.github.com/repos/silas/docker-test/teams",
|
||||
"hooks_url": "https://api.github.com/repos/silas/docker-test/hooks",
|
||||
"issue_events_url": "https://api.github.com/repos/silas/docker-test/issues/events{/number}",
|
||||
"events_url": "https://api.github.com/repos/silas/docker-test/events",
|
||||
"assignees_url": "https://api.github.com/repos/silas/docker-test/assignees{/user}",
|
||||
"branches_url": "https://api.github.com/repos/silas/docker-test/branches{/branch}",
|
||||
"tags_url": "https://api.github.com/repos/silas/docker-test/tags",
|
||||
"blobs_url": "https://api.github.com/repos/silas/docker-test/git/blobs{/sha}",
|
||||
"git_tags_url": "https://api.github.com/repos/silas/docker-test/git/tags{/sha}",
|
||||
"git_refs_url": "https://api.github.com/repos/silas/docker-test/git/refs{/sha}",
|
||||
"trees_url": "https://api.github.com/repos/silas/docker-test/git/trees{/sha}",
|
||||
"statuses_url": "https://api.github.com/repos/silas/docker-test/statuses/{sha}",
|
||||
"languages_url": "https://api.github.com/repos/silas/docker-test/languages",
|
||||
"stargazers_url": "https://api.github.com/repos/silas/docker-test/stargazers",
|
||||
"contributors_url": "https://api.github.com/repos/silas/docker-test/contributors",
|
||||
"subscribers_url": "https://api.github.com/repos/silas/docker-test/subscribers",
|
||||
"subscription_url": "https://api.github.com/repos/silas/docker-test/subscription",
|
||||
"commits_url": "https://api.github.com/repos/silas/docker-test/commits{/sha}",
|
||||
"git_commits_url": "https://api.github.com/repos/silas/docker-test/git/commits{/sha}",
|
||||
"comments_url": "https://api.github.com/repos/silas/docker-test/comments{/number}",
|
||||
"issue_comment_url": "https://api.github.com/repos/silas/docker-test/issues/comments{/number}",
|
||||
"contents_url": "https://api.github.com/repos/silas/docker-test/contents/{+path}",
|
||||
"compare_url": "https://api.github.com/repos/silas/docker-test/compare/{base}...{head}",
|
||||
"merges_url": "https://api.github.com/repos/silas/docker-test/merges",
|
||||
"archive_url": "https://api.github.com/repos/silas/docker-test/{archive_format}{/ref}",
|
||||
"downloads_url": "https://api.github.com/repos/silas/docker-test/downloads",
|
||||
"issues_url": "https://api.github.com/repos/silas/docker-test/issues{/number}",
|
||||
"pulls_url": "https://api.github.com/repos/silas/docker-test/pulls{/number}",
|
||||
"milestones_url": "https://api.github.com/repos/silas/docker-test/milestones{/number}",
|
||||
"notifications_url": "https://api.github.com/repos/silas/docker-test/notifications{?since,all,participating}",
|
||||
"labels_url": "https://api.github.com/repos/silas/docker-test/labels{/name}",
|
||||
"releases_url": "https://api.github.com/repos/silas/docker-test/releases{/id}",
|
||||
"created_at": 1442254053,
|
||||
"updated_at": "2015-09-14T18:07:33Z",
|
||||
"pushed_at": 1443207315,
|
||||
"git_url": "git://github.com/silas/docker-test.git",
|
||||
"ssh_url": "git@github.com:silas/docker-test.git",
|
||||
"clone_url": "https://github.com/silas/docker-test.git",
|
||||
"svn_url": "https://github.com/silas/docker-test",
|
||||
"homepage": null,
|
||||
"size": 108,
|
||||
"stargazers_count": 0,
|
||||
"watchers_count": 0,
|
||||
"language": null,
|
||||
"has_issues": true,
|
||||
"has_downloads": true,
|
||||
"has_wiki": true,
|
||||
"has_pages": false,
|
||||
"forks_count": 0,
|
||||
"mirror_url": null,
|
||||
"open_issues_count": 0,
|
||||
"forks": 0,
|
||||
"open_issues": 0,
|
||||
"watchers": 0,
|
||||
"default_branch": "master",
|
||||
"stargazers": 0,
|
||||
"master_branch": "master"
|
||||
},
|
||||
"pusher": {
|
||||
"name": "silas",
|
||||
"email": "silas@sewell.org"
|
||||
},
|
||||
"sender": {
|
||||
"login": "silas",
|
||||
"id": 18528,
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/18528?v=3",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/silas",
|
||||
"html_url": "https://github.com/silas",
|
||||
"followers_url": "https://api.github.com/users/silas/followers",
|
||||
"following_url": "https://api.github.com/users/silas/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/silas/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/silas/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/silas/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/silas/orgs",
|
||||
"repos_url": "https://api.github.com/users/silas/repos",
|
||||
"events_url": "https://api.github.com/users/silas/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/silas/received_events",
|
||||
"type": "User",
|
||||
"site_admin": false
|
||||
}
|
||||
}
|
Reference in a new issue