From 72c34a840d1492a62683f081bd00d286b28cef0f Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 19 May 2012 11:19:13 +0100 Subject: [PATCH] Test labels (new special case in Repository.get_label...) --- .../description.000.human_readable.json | 1 - .../description.001.normalized.json | 2 +- src/github/Label.py | 20 ------------- src/github/Repository.py | 4 ++- test/MilestonesAndIssues.py | 30 +++++++++++++++++++ test/ReplayData/Label.setUp.txt | 10 +++++++ test/ReplayData/Label.testAttributes.txt | 5 ++++ test/ReplayData/Label.testCreate.txt | 5 ++++ test/ReplayData/Label.testDelete.txt | 10 +++++++ test/ReplayData/Label.testEdit.txt | 10 +++++++ .../Label.testGetLabelWithSillyName.txt | 5 ++++ 11 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 test/ReplayData/Label.setUp.txt create mode 100644 test/ReplayData/Label.testAttributes.txt create mode 100644 test/ReplayData/Label.testCreate.txt create mode 100644 test/ReplayData/Label.testDelete.txt create mode 100644 test/ReplayData/Label.testEdit.txt create mode 100644 test/ReplayData/Label.testGetLabelWithSillyName.txt diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index a62379a2..03e7ebbf 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -793,7 +793,6 @@ }, { "name": "Label", - "isCompletable": true, "edit": { "mandatoryParameters": [ { "name": "name", "type": "@todo" }, diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index 19701610..785e74b5 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -4413,7 +4413,7 @@ "name": "url" } ], - "isCompletable": true, + "isCompletable": false, "name": "Label", "methods": [ { diff --git a/src/github/Label.py b/src/github/Label.py index 5c36bd34..3b62c894 100644 --- a/src/github/Label.py +++ b/src/github/Label.py @@ -9,23 +9,17 @@ class Label( object ): self.__requester = requester self.__initAttributes() self.__useAttributes( attributes ) - self.__completed = completion != LazyCompletion - if completion == ImmediateCompletion: - self.__complete() @property def color( self ): - self.__completeIfNeeded( self.__color ) return self.__color @property def name( self ): - self.__completeIfNeeded( self.__name ) return self.__name @property def url( self ): - self.__completeIfNeeded( self.__url ) return self.__url def delete( self ): @@ -54,20 +48,6 @@ class Label( object ): self.__name = None self.__url = None - def __completeIfNeeded( self, testedAttribute ): - if not self.__completed and testedAttribute is None: - self.__complete() - - def __complete( self ): - status, headers, data = self.__requester.request( - "GET", - self.__url, - None, - None - ) - self.__useAttributes( data ) - self.__completed = True - def __useAttributes( self, attributes ): # @todo Remove this debug weakness: we shall assume that github will add new attributes for attribute in attributes: diff --git a/src/github/Repository.py b/src/github/Repository.py index c5323c4d..b254c5df 100644 --- a/src/github/Repository.py +++ b/src/github/Repository.py @@ -1,6 +1,8 @@ # WARNING: this file is generated automaticaly. # Do not modify it manually, your work would be lost. +import urllib + import PaginatedList from GithubObject import * import Branch @@ -693,7 +695,7 @@ class Repository( object ): def get_label( self, name ): status, headers, data = self.__requester.request( "GET", - str( self.url ) + "/labels" + "/" + str( name ), + str( self.url ) + "/labels" + "/" + urllib.quote( name ), None, None ) diff --git a/test/MilestonesAndIssues.py b/test/MilestonesAndIssues.py index 4bca72ad..9a049735 100644 --- a/test/MilestonesAndIssues.py +++ b/test/MilestonesAndIssues.py @@ -36,3 +36,33 @@ class Issue( Framework.TestCaseWithRepo ): self.assertEqual( issue.updated_at, "2012-03-12T20:46:35Z" ) self.assertEqual( issue.url, "https://api.github.com/repos/jacquev6/PyGithub/issues/1" ) self.assertEqual( issue.user.login, "jacquev6" ) + +class Label( Framework.TestCaseWithRepo ): + def testAttributes( self ): + label = self.repo.get_label( "Bug" ) + self.assertEqual( label.color, "e10c02" ) + self.assertEqual( label.name, "Bug" ) + self.assertEqual( label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Bug" ) + + def testCreate( self ): + label = self.repo.create_label( "Label with silly name % * + created by PyGithub", "00ff00" ) + self.assertEqual( label.color, "00ff00" ) + self.assertEqual( label.name, "Label with silly name % * + created by PyGithub" ) + self.assertEqual( label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub" ) + + def testGetLabelWithSillyName( self ): + label = self.repo.get_label( "Label with silly name % * + created by PyGithub" ) + self.assertEqual( label.color, "00ff00" ) + self.assertEqual( label.name, "Label with silly name % * + created by PyGithub" ) + self.assertEqual( label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub" ) + + def testEdit( self ): + label = self.repo.get_label( "Label with silly name % * + created by PyGithub" ) + label.edit( "LabelEditedByPyGithub", "0000ff" ) + self.assertEqual( label.color, "0000ff" ) + self.assertEqual( label.name, "LabelEditedByPyGithub" ) + self.assertEqual( label.url, "https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub" ) + + def testDelete( self ): + label = self.repo.get_label( "LabelEditedByPyGithub" ) + label.delete() diff --git a/test/ReplayData/Label.setUp.txt b/test/ReplayData/Label.setUp.txt new file mode 100644 index 00000000..c06423ef --- /dev/null +++ b/test/ReplayData/Label.setUp.txt @@ -0,0 +1,10 @@ +GET /user {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4964'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"708be4e44b32b617fad893a7eb4aed93"'), ('date', 'Sat, 19 May 2012 10:17:52 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"type":"User","public_gists":1,"company":"Criteo","blog":"http://vincent-jacques.net","url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","total_private_repos":5,"private_gists":5,"collaborators":0,"plan":{"private_repos":5,"collaborators":1,"name":"micro","space":614400},"public_repos":11,"followers":13,"owned_private_repos":5,"hireable":false,"login":"jacquev6","email":"vincent@vincent-jacques.net","bio":"","disk_usage":16768,"html_url":"https://github.com/jacquev6","name":"Vincent Jacques","created_at":"2010-07-09T06:10:06Z","location":"Paris, France","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":327146,"following":24} + +GET /repos/jacquev6/PyGithub {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4963'), ('content-length', '1097'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1da4fc53170e51b749ed7930a5fe947c"'), ('date', 'Sat, 19 May 2012 10:17:52 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","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","mirror_url":null,"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","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jacquev6","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/Label.testAttributes.txt b/test/ReplayData/Label.testAttributes.txt new file mode 100644 index 00000000..6e1607e6 --- /dev/null +++ b/test/ReplayData/Label.testAttributes.txt @@ -0,0 +1,5 @@ +GET /repos/jacquev6/PyGithub/labels/Bug {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('content-length', '97'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"fe2e942523eecb156d100829a6347516"'), ('date', 'Sat, 19 May 2012 09:40:37 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Bug","name":"Bug","color":"e10c02"} + diff --git a/test/ReplayData/Label.testCreate.txt b/test/ReplayData/Label.testCreate.txt new file mode 100644 index 00000000..a4d05377 --- /dev/null +++ b/test/ReplayData/Label.testCreate.txt @@ -0,0 +1,5 @@ +POST /repos/jacquev6/PyGithub/labels {} {"color": "00ff00", "name": "Label with silly name % * + created by PyGithub"} +201 +[('status', '201 Created'), ('x-ratelimit-remaining', '4969'), ('content-length', '191'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"92b623552b1bac3f019d03c920305acd"'), ('date', 'Sat, 19 May 2012 10:17:36 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub","name":"Label with silly name % * + created by PyGithub","color":"00ff00"} + diff --git a/test/ReplayData/Label.testDelete.txt b/test/ReplayData/Label.testDelete.txt new file mode 100644 index 00000000..949a2e64 --- /dev/null +++ b/test/ReplayData/Label.testDelete.txt @@ -0,0 +1,10 @@ +GET /repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4962'), ('content-length', '133'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"57435796bd4f14b84ad92105669cfab1"'), ('date', 'Sat, 19 May 2012 10:17:53 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub","name":"LabelEditedByPyGithub","color":"0000ff"} + +DELETE /repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub {} null +204 +[('status', '204 No Content'), ('x-ratelimit-remaining', '4961'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d41d8cd98f00b204e9800998ecf8427e"'), ('date', 'Sat, 19 May 2012 10:17:53 GMT')] + + diff --git a/test/ReplayData/Label.testEdit.txt b/test/ReplayData/Label.testEdit.txt new file mode 100644 index 00000000..6a845aee --- /dev/null +++ b/test/ReplayData/Label.testEdit.txt @@ -0,0 +1,10 @@ +GET /repos/jacquev6/PyGithub/labels/Label%20with%20silly%20name%20%25%20%2A%20%2B%20created%20by%20PyGithub {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4966'), ('content-length', '191'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"92b623552b1bac3f019d03c920305acd"'), ('date', 'Sat, 19 May 2012 10:17:43 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub","name":"Label with silly name % * + created by PyGithub","color":"00ff00"} + +PATCH /repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub {} {"color": "0000ff", "name": "LabelEditedByPyGithub"} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4965'), ('content-length', '133'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"57435796bd4f14b84ad92105669cfab1"'), ('date', 'Sat, 19 May 2012 10:17:44 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/LabelEditedByPyGithub","name":"LabelEditedByPyGithub","color":"0000ff"} + diff --git a/test/ReplayData/Label.testGetLabelWithSillyName.txt b/test/ReplayData/Label.testGetLabelWithSillyName.txt new file mode 100644 index 00000000..264ab69a --- /dev/null +++ b/test/ReplayData/Label.testGetLabelWithSillyName.txt @@ -0,0 +1,5 @@ +GET /repos/jacquev6/PyGithub/labels/Label%20with%20silly%20name%20%25%20%2A%20%2B%20created%20by%20PyGithub {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4983'), ('content-length', '191'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"92b623552b1bac3f019d03c920305acd"'), ('date', 'Sat, 19 May 2012 10:12:54 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Label+with+silly+name+%25+%2A+%2B+created+by+PyGithub","name":"Label with silly name % * + created by PyGithub","color":"00ff00"} +