From 667937b437747df181cfeeab84fa74bcc5e7b118 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 19 May 2012 07:04:24 +0100 Subject: [PATCH] Test Hooks --- test/Framework.py | 2 +- test/Hook.py | 52 +++++++++++++++++++ test/IntegrationTest.py | 1 + test/ReplayData/Hook.setUp.txt | 10 ++++ .../Hook.testCreateWithAllParameters.txt | 5 ++ .../Hook.testCreateWithMinimalParameters.txt | 5 ++ test/ReplayData/Hook.testDelete.txt | 10 ++++ .../Hook.testEditWithAllParameters.txt | 25 +++++++++ .../Hook.testEditWithMinimalParameters.txt | 10 ++++ test/ReplayData/Hook.testTest.txt | 10 ++++ 10 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 test/Hook.py create mode 100644 test/ReplayData/Hook.setUp.txt create mode 100644 test/ReplayData/Hook.testCreateWithAllParameters.txt create mode 100644 test/ReplayData/Hook.testCreateWithMinimalParameters.txt create mode 100644 test/ReplayData/Hook.testDelete.txt create mode 100644 test/ReplayData/Hook.testEditWithAllParameters.txt create mode 100644 test/ReplayData/Hook.testEditWithMinimalParameters.txt create mode 100644 test/ReplayData/Hook.testTest.txt diff --git a/test/Framework.py b/test/Framework.py index 7fd04a51..47063d70 100644 --- a/test/Framework.py +++ b/test/Framework.py @@ -91,7 +91,7 @@ class TestCase( unittest.TestCase ): def __openFile( self, mode ): for ( _, _, functionName, _ ) in traceback.extract_stack(): - if functionName.startswith( "test" ) or functionName == "setUp" or functionName == "tearDown": + if functionName.startswith( "test" ) and functionName != "test" or functionName == "setUp" or functionName == "tearDown": fileName = os.path.join( os.path.dirname( __file__ ), "ReplayData", self.__class__.__name__ + "." + functionName + ".txt" ) if fileName != self.__fileName: self.__closeReplayFileIfNeeded() diff --git a/test/Hook.py b/test/Hook.py new file mode 100644 index 00000000..028f8b7c --- /dev/null +++ b/test/Hook.py @@ -0,0 +1,52 @@ +import Framework + +class Hook( Framework.TestCaseWithRepo ): + def testCreateWithMinimalParameters( self ): + ### @todo Implement https://api.github.com/hooks, which is not described, but refered by http://developer.github.com/v3/repos/hooks/#create-a-hook + hook = self.repo.create_hook( "web", { "url": "http://foobar.com" } ) + self.assertEqual( hook.active, True ) + self.assertEqual( hook.config, { "url": "http://foobar.com" } ) + self.assertEqual( hook.created_at, "2012-05-19T05:03:14Z" ) + self.assertEqual( hook.events, [ "push" ] ) + self.assertEqual( hook.id, 257967 ) + self.assertEqual( hook.last_response, { "status": "unused", "message": None, "code": None } ) + self.assertEqual( hook.name, "web" ) + self.assertEqual( hook.updated_at, "2012-05-19T05:03:14Z" ) + self.assertEqual( hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257967" ) + + def testEditWithMinimalParameters( self ): + hook = self.repo.get_hook( 257967 ) + hook.edit( "web", { "url": "http://foobar.com/hook" } ) + self.assertEqual( hook.config, { "url": "http://foobar.com/hook" } ) + self.assertEqual( hook.updated_at, "2012-05-19T05:08:16Z" ) + + def testDelete( self ): + hook = self.repo.get_hook( 257967 ) + hook.delete() + + def testCreateWithAllParameters( self ): + hook = self.repo.create_hook( "web", { "url": "http://foobar.com" }, [ "fork" ], False ) + self.assertEqual( hook.active, True ) # WTF + self.assertEqual( hook.config, { "url": "http://foobar.com" } ) + self.assertEqual( hook.created_at, "2012-05-19T06:01:45Z" ) + self.assertEqual( hook.events, [ "fork" ] ) + self.assertEqual( hook.id, 257993 ) + self.assertEqual( hook.last_response, { "status": "unused", "message": None, "code": None } ) + self.assertEqual( hook.name, "web" ) + self.assertEqual( hook.updated_at, "2012-05-19T06:01:45Z" ) + self.assertEqual( hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993" ) + + def testTest( self ): + hook = self.repo.get_hook( 257993 ) + hook.test() # This does not update attributes of hook + + def testEditWithAllParameters( self ): + hook = self.repo.get_hook( 257993 ) + hook.edit( "web", { "url": "http://foobar.com" }, events = [ "fork", "push" ] ) + self.assertEqual( hook.events, [ "fork", "push" ] ) + hook.edit( "web", { "url": "http://foobar.com" }, add_events = [ "push" ] ) + self.assertEqual( hook.events, [ "fork", "push" ] ) + hook.edit( "web", { "url": "http://foobar.com" }, remove_events = [ "fork" ] ) + self.assertEqual( hook.events, [ "push" ] ) + hook.edit( "web", { "url": "http://foobar.com" }, active = True ) + self.assertEqual( hook.active, True ) diff --git a/test/IntegrationTest.py b/test/IntegrationTest.py index df1fb954..50fd89fe 100644 --- a/test/IntegrationTest.py +++ b/test/IntegrationTest.py @@ -8,5 +8,6 @@ from Repository import * from Organization import * from MilestonesAndIssues import * from NamedUser import * +from Hook import * Framework.main() diff --git a/test/ReplayData/Hook.setUp.txt b/test/ReplayData/Hook.setUp.txt new file mode 100644 index 00000000..8b25e913 --- /dev/null +++ b/test/ReplayData/Hook.setUp.txt @@ -0,0 +1,10 @@ +GET /user {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4989'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1e23ec567c20df43998d10ca594a6751"'), ('date', 'Sat, 19 May 2012 05:08:59 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"type":"User","owned_private_repos":5,"blog":"http://vincent-jacques.net","company":"Criteo","url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","plan":{"private_repos":5,"collaborators":1,"name":"micro","space":614400},"followers":13,"public_repos":11,"hireable":false,"login":"jacquev6","collaborators":0,"public_gists":1,"email":"vincent@vincent-jacques.net","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","disk_usage":16768,"html_url":"https://github.com/jacquev6","name":"Vincent Jacques","bio":"","private_gists":5,"created_at":"2010-07-09T06:10:06Z","location":"Paris, France","id":327146,"total_private_repos":5,"following":24} + +GET /repos/jacquev6/PyGithub {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4988'), ('content-length', '1097'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"9980e3e204ce293ebdb8dc90ff290268"'), ('date', 'Sat, 19 May 2012 05:09:00 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"svn_url":"https://github.com/jacquev6/PyGithub","has_wiki":false,"has_issues":true,"updated_at":"2012-05-18T20:30:15Z","forks":2,"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"clone_url":"https://github.com/jacquev6/PyGithub.git","git_url":"git://github.com/jacquev6/PyGithub.git","open_issues":17,"fork":false,"ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-18T20:30:14Z","size":220,"private":false,"has_downloads":true,"watchers":13,"html_url":"https://github.com/jacquev6/PyGithub","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":327146},"name":"PyGithub","permissions":{"pull":true,"admin":true,"push":true},"language":"Python","description":"Python library implementing the full Github API v3","created_at":"2012-02-25T12:53:47Z","id":3544490} + diff --git a/test/ReplayData/Hook.testCreateWithAllParameters.txt b/test/ReplayData/Hook.testCreateWithAllParameters.txt new file mode 100644 index 00000000..3cb4cafc --- /dev/null +++ b/test/ReplayData/Hook.testCreateWithAllParameters.txt @@ -0,0 +1,5 @@ +POST /repos/jacquev6/PyGithub/hooks {} {"active": false, "config": {"url": "http://foobar.com"}, "name": "web", "events": ["fork"]} +201 +[('status', '201 Created'), ('x-ratelimit-remaining', '4997'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"c3b371e4de1a0ec350b3fcc0c458e0f9"'), ('date', 'Sat, 19 May 2012 06:01:45 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/hooks/257993')] +{"updated_at":"2012-05-19T06:01:45Z","last_response":{"status":"unused","message":null,"code":null},"events":["fork"],"url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","active":true,"name":"web","config":{"url":"http://foobar.com"},"id":257993,"created_at":"2012-05-19T06:01:45Z"} + diff --git a/test/ReplayData/Hook.testCreateWithMinimalParameters.txt b/test/ReplayData/Hook.testCreateWithMinimalParameters.txt new file mode 100644 index 00000000..7c6ffc93 --- /dev/null +++ b/test/ReplayData/Hook.testCreateWithMinimalParameters.txt @@ -0,0 +1,5 @@ +POST /repos/jacquev6/PyGithub/hooks {} {"config": {"url": "http://foobar.com"}, "name": "web"} +201 +[('status', '201 Created'), ('x-ratelimit-remaining', '4994'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"276d18854081948260c44cf645c54bd0"'), ('date', 'Sat, 19 May 2012 05:03:14 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/hooks/257967')] +{"updated_at":"2012-05-19T05:03:14Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257967","config":{"url":"http://foobar.com"},"last_response":{"status":"unused","message":null,"code":null},"active":true,"events":["push"],"name":"web","created_at":"2012-05-19T05:03:14Z","id":257967} + diff --git a/test/ReplayData/Hook.testDelete.txt b/test/ReplayData/Hook.testDelete.txt new file mode 100644 index 00000000..521203d7 --- /dev/null +++ b/test/ReplayData/Hook.testDelete.txt @@ -0,0 +1,10 @@ +GET /repos/jacquev6/PyGithub/hooks/257967 {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('content-length', '303'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"a686c4d4f706840e166ebafdfd05f41f"'), ('date', 'Sat, 19 May 2012 05:09:01 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T05:08:16Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257967","config":{"url":"http://foobar.com/hook"},"last_response":{"status":"unused","message":null,"code":null},"active":true,"events":["push"],"name":"web","created_at":"2012-05-19T05:03:14Z","id":257967} + +DELETE /repos/jacquev6/PyGithub/hooks/257967 {} null +204 +[('status', '204 No Content'), ('x-ratelimit-remaining', '4986'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d41d8cd98f00b204e9800998ecf8427e"'), ('date', 'Sat, 19 May 2012 05:09:01 GMT')] + + diff --git a/test/ReplayData/Hook.testEditWithAllParameters.txt b/test/ReplayData/Hook.testEditWithAllParameters.txt new file mode 100644 index 00000000..9e0979de --- /dev/null +++ b/test/ReplayData/Hook.testEditWithAllParameters.txt @@ -0,0 +1,25 @@ +GET /repos/jacquev6/PyGithub/hooks/257993 {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4988'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"73e795da2a2d325298007f3b78822b98"'), ('date', 'Sat, 19 May 2012 06:03:18 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T06:02:36Z","last_response":{"status":"unused","message":null,"code":null},"events":["push"],"url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","active":true,"name":"web","config":{"url":"http://foobar.com"},"id":257993,"created_at":"2012-05-19T06:01:45Z"} + +PATCH /repos/jacquev6/PyGithub/hooks/257993 {} {"config": {"url": "http://foobar.com"}, "name": "web", "events": ["fork", "push"]} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('content-length', '305'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"43f8b86dbc2f5bbfde20abb9d9142206"'), ('date', 'Sat, 19 May 2012 06:03:18 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T06:03:18Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","last_response":{"status":"unused","message":null,"code":null},"config":{"url":"http://foobar.com"},"active":true,"events":["fork","push"],"name":"web","created_at":"2012-05-19T06:01:45Z","id":257993} + +PATCH /repos/jacquev6/PyGithub/hooks/257993 {} {"config": {"url": "http://foobar.com"}, "name": "web", "add_events": ["push"]} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4986'), ('content-length', '305'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"f372cc9359ed1d3b3fb8d484a09b36d7"'), ('date', 'Sat, 19 May 2012 06:03:19 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T06:03:19Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","last_response":{"status":"unused","message":null,"code":null},"config":{"url":"http://foobar.com"},"active":true,"events":["fork","push"],"name":"web","created_at":"2012-05-19T06:01:45Z","id":257993} + +PATCH /repos/jacquev6/PyGithub/hooks/257993 {} {"remove_events": ["fork"], "config": {"url": "http://foobar.com"}, "name": "web"} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"223ecc83a014738547fd99c826e3f125"'), ('date', 'Sat, 19 May 2012 06:03:19 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T06:03:19Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","config":{"url":"http://foobar.com"},"active":true,"last_response":{"status":"unused","message":null,"code":null},"events":["push"],"name":"web","created_at":"2012-05-19T06:01:45Z","id":257993} + +PATCH /repos/jacquev6/PyGithub/hooks/257993 {} {"active": true, "config": {"url": "http://foobar.com"}, "name": "web"} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4984'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"711cf06c29a923c290e1af74dc3e019d"'), ('date', 'Sat, 19 May 2012 06:03:20 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T06:03:20Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","last_response":{"status":"unused","message":null,"code":null},"config":{"url":"http://foobar.com"},"active":true,"events":["push"],"name":"web","created_at":"2012-05-19T06:01:45Z","id":257993} + diff --git a/test/ReplayData/Hook.testEditWithMinimalParameters.txt b/test/ReplayData/Hook.testEditWithMinimalParameters.txt new file mode 100644 index 00000000..e2dc2678 --- /dev/null +++ b/test/ReplayData/Hook.testEditWithMinimalParameters.txt @@ -0,0 +1,10 @@ +GET /repos/jacquev6/PyGithub/hooks/257967 {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4991'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"7be10de17b101889781f9b1fde89d38f"'), ('date', 'Sat, 19 May 2012 05:08:16 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"last_response":{"status":"unused","message":null,"code":null},"updated_at":"2012-05-19T05:03:14Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257967","config":{"url":"http://foobar.com"},"active":true,"events":["push"],"name":"web","created_at":"2012-05-19T05:03:14Z","id":257967} + +PATCH /repos/jacquev6/PyGithub/hooks/257967 {} {"config": {"url": "http://foobar.com/hook"}, "name": "web"} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4990'), ('content-length', '303'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"8628a600a78bd5171c9e8d23b1ec22de"'), ('date', 'Sat, 19 May 2012 05:08:16 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"last_response":{"status":"unused","message":null,"code":null},"updated_at":"2012-05-19T05:08:16Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257967","config":{"url":"http://foobar.com/hook"},"active":true,"events":["push"],"name":"web","created_at":"2012-05-19T05:03:14Z","id":257967} + diff --git a/test/ReplayData/Hook.testTest.txt b/test/ReplayData/Hook.testTest.txt new file mode 100644 index 00000000..af4ec957 --- /dev/null +++ b/test/ReplayData/Hook.testTest.txt @@ -0,0 +1,10 @@ +GET /repos/jacquev6/PyGithub/hooks/257993 {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4981'), ('content-length', '298'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"f4a973ea4a9c930d4a89ea010190c734"'), ('date', 'Sat, 19 May 2012 06:04:06 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-19T06:03:20Z","url":"https://api.github.com/repos/jacquev6/PyGithub/hooks/257993","config":{"url":"http://foobar.com"},"active":true,"last_response":{"status":"unused","message":null,"code":null},"events":["push"],"name":"web","created_at":"2012-05-19T06:01:45Z","id":257993} + +POST /repos/jacquev6/PyGithub/hooks/257993/test {} null +204 +[('status', '204 No Content'), ('x-ratelimit-remaining', '4980'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d41d8cd98f00b204e9800998ecf8427e"'), ('date', 'Sat, 19 May 2012 06:04:06 GMT')] + +