From bab5cf69c72aeb4f33479cb68eefb37ecae309e9 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 11 Aug 2016 18:01:04 -0400 Subject: [PATCH] Add a test for a deleted ref for the Github trigger Fixes #1047 --- test/test_prepare_trigger.py | 28 ++- .../github_webhook_deletedcommit.json | 199 ++++++++++++++++++ 2 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 test/triggerjson/github_webhook_deletedcommit.json diff --git a/test/test_prepare_trigger.py b/test/test_prepare_trigger.py index f4e79f1cc..79cbe98f1 100644 --- a/test/test_prepare_trigger.py +++ b/test/test_prepare_trigger.py @@ -1,7 +1,7 @@ import unittest import json -from jsonschema import validate, ValidationError +from jsonschema import validate from buildtrigger.customhandler import custom_trigger_payload from buildtrigger.basehandler import METADATA_SCHEMA from buildtrigger.bitbuckethandler import get_transformed_webhook_payload as bb_webhook @@ -376,5 +376,29 @@ class TestPrepareTrigger(unittest.TestCase): self.assertSchema('gitlab_webhook', expected, gl_webhook, lookup_user=lookup_user) + def test_github_webhook_payload_deleted_commit(self): + expected = { + 'commit': u'456806b662cb903a0febbaed8344f3ed42f27bab', + 'commit_info': { + 'author': { + 'username': u'jakedt' + }, + 'committer': { + 'username': u'jakedt' + }, + 'date': u'2015-12-08T18:07:03-05:00', + 'message': (u'Merge pull request #1044 from jakedt/errerror\n\n' + + 'Assign the exception to a variable to log it'), + 'url': u'https://github.com/coreos-inc/quay/commit/456806b662cb903a0febbaed8344f3ed42f27bab' + }, + 'git_url': u'git@github.com:coreos-inc/quay.git', + 'ref': u'refs/heads/master', + } + + def lookup_user(_): + return None + + self.assertSchema('github_webhook_deletedcommit', expected, gh_webhook, lookup_user=lookup_user) + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/test/triggerjson/github_webhook_deletedcommit.json b/test/triggerjson/github_webhook_deletedcommit.json new file mode 100644 index 000000000..4e7cf3225 --- /dev/null +++ b/test/triggerjson/github_webhook_deletedcommit.json @@ -0,0 +1,199 @@ +{ + "ref": "refs/heads/master", + "before": "c7fa613b99d509c0d4fcbf946f0415b5f024150b", + "after": "456806b662cb903a0febbaed8344f3ed42f27bab", + "created": false, + "deleted": false, + "forced": false, + "base_ref": null, + "compare": "https://github.com/coreos-inc/quay/compare/c7fa613b99d5...456806b662cb", + "commits": [ + { + "id": "e00365b225ad7f454982e9198756cc1ab5dc4428", + "distinct": true, + "message": "Assign the exception to a variable to log it", + "timestamp": "2015-12-08T18:03:48-05:00", + "url": "https://github.com/coreos-inc/quay/commit/e00365b225ad7f454982e9198756cc1ab5dc4428", + "author": { + "name": "Jake Moshenko", + "email": "jake.moshenko@coreos.com", + "username": "jakedt" + }, + "committer": { + "name": "Jake Moshenko", + "email": "jake.moshenko@coreos.com", + "username": "jakedt" + }, + "added": [ + + ], + "removed": [ + + ], + "modified": [ + "storage/basestorage.py" + ] + }, + { + "id": "456806b662cb903a0febbaed8344f3ed42f27bab", + "distinct": true, + "message": "Merge pull request #1044 from jakedt/errerror\n\nAssign the exception to a variable to log it", + "timestamp": "2015-12-08T18:07:03-05:00", + "url": "https://github.com/coreos-inc/quay/commit/456806b662cb903a0febbaed8344f3ed42f27bab", + "author": { + "name": "Jake Moshenko", + "email": "jake.moshenko@coreos.com", + "username": "jakedt" + }, + "committer": { + "name": "Jake Moshenko", + "email": "jake.moshenko@coreos.com", + "username": "jakedt" + }, + "added": [ + + ], + "removed": [ + + ], + "modified": [ + "storage/basestorage.py" + ] + } + ], + "head_commit": { + "id": "456806b662cb903a0febbaed8344f3ed42f27bab", + "distinct": true, + "message": "Merge pull request #1044 from jakedt/errerror\n\nAssign the exception to a variable to log it", + "timestamp": "2015-12-08T18:07:03-05:00", + "url": "https://github.com/coreos-inc/quay/commit/456806b662cb903a0febbaed8344f3ed42f27bab", + "author": { + "name": "Jake Moshenko", + "email": "jake.moshenko@coreos.com", + "username": "jakedt" + }, + "committer": { + "name": "Jake Moshenko", + "email": "jake.moshenko@coreos.com", + "username": "jakedt" + }, + "added": [ + + ], + "removed": [ + + ], + "modified": [ + "storage/basestorage.py" + ] + }, + "repository": { + "id": 26143156, + "name": "quay", + "full_name": "coreos-inc/quay", + "owner": { + "name": "coreos-inc", + "email": null + }, + "private": true, + "html_url": "https://github.com/coreos-inc/quay", + "description": "Quay Registry", + "fork": false, + "url": "https://github.com/coreos-inc/quay", + "forks_url": "https://api.github.com/repos/coreos-inc/quay/forks", + "keys_url": "https://api.github.com/repos/coreos-inc/quay/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/coreos-inc/quay/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/coreos-inc/quay/teams", + "hooks_url": "https://api.github.com/repos/coreos-inc/quay/hooks", + "issue_events_url": "https://api.github.com/repos/coreos-inc/quay/issues/events{/number}", + "events_url": "https://api.github.com/repos/coreos-inc/quay/events", + "assignees_url": "https://api.github.com/repos/coreos-inc/quay/assignees{/user}", + "branches_url": "https://api.github.com/repos/coreos-inc/quay/branches{/branch}", + "tags_url": "https://api.github.com/repos/coreos-inc/quay/tags", + "blobs_url": "https://api.github.com/repos/coreos-inc/quay/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/coreos-inc/quay/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/coreos-inc/quay/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/coreos-inc/quay/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/coreos-inc/quay/statuses/{sha}", + "languages_url": "https://api.github.com/repos/coreos-inc/quay/languages", + "stargazers_url": "https://api.github.com/repos/coreos-inc/quay/stargazers", + "contributors_url": "https://api.github.com/repos/coreos-inc/quay/contributors", + "subscribers_url": "https://api.github.com/repos/coreos-inc/quay/subscribers", + "subscription_url": "https://api.github.com/repos/coreos-inc/quay/subscription", + "commits_url": "https://api.github.com/repos/coreos-inc/quay/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/coreos-inc/quay/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/coreos-inc/quay/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/coreos-inc/quay/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/coreos-inc/quay/contents/{+path}", + "compare_url": "https://api.github.com/repos/coreos-inc/quay/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/coreos-inc/quay/merges", + "archive_url": "https://api.github.com/repos/coreos-inc/quay/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/coreos-inc/quay/downloads", + "issues_url": "https://api.github.com/repos/coreos-inc/quay/issues{/number}", + "pulls_url": "https://api.github.com/repos/coreos-inc/quay/pulls{/number}", + "milestones_url": "https://api.github.com/repos/coreos-inc/quay/milestones{/number}", + "notifications_url": "https://api.github.com/repos/coreos-inc/quay/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/coreos-inc/quay/labels{/name}", + "releases_url": "https://api.github.com/repos/coreos-inc/quay/releases{/id}", + "created_at": 1415056063, + "updated_at": "2015-11-12T05:16:51Z", + "pushed_at": 1449616023, + "git_url": "git://github.com/coreos-inc/quay.git", + "ssh_url": "git@github.com:coreos-inc/quay.git", + "clone_url": "https://github.com/coreos-inc/quay.git", + "svn_url": "https://github.com/coreos-inc/quay", + "homepage": "", + "size": 183677, + "stargazers_count": 3, + "watchers_count": 3, + "language": "Python", + "has_issues": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 8, + "mirror_url": null, + "open_issues_count": 188, + "forks": 8, + "open_issues": 188, + "watchers": 3, + "default_branch": "master", + "stargazers": 3, + "master_branch": "master", + "organization": "coreos-inc" + }, + "pusher": { + "name": "jakedt", + "email": "jake.moshenko@coreos.com" + }, + "organization": { + "login": "coreos-inc", + "id": 5504624, + "url": "https://api.github.com/orgs/coreos-inc", + "repos_url": "https://api.github.com/orgs/coreos-inc/repos", + "events_url": "https://api.github.com/orgs/coreos-inc/events", + "members_url": "https://api.github.com/orgs/coreos-inc/members{/member}", + "public_members_url": "https://api.github.com/orgs/coreos-inc/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/5504624?v=3", + "description": null + }, + "sender": { + "login": "jakedt", + "id": 2183986, + "avatar_url": "https://avatars.githubusercontent.com/u/2183986?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/jakedt", + "html_url": "https://github.com/jakedt", + "followers_url": "https://api.github.com/users/jakedt/followers", + "following_url": "https://api.github.com/users/jakedt/following{/other_user}", + "gists_url": "https://api.github.com/users/jakedt/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jakedt/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jakedt/subscriptions", + "organizations_url": "https://api.github.com/users/jakedt/orgs", + "repos_url": "https://api.github.com/users/jakedt/repos", + "events_url": "https://api.github.com/users/jakedt/events{/privacy}", + "received_events_url": "https://api.github.com/users/jakedt/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file