From 12747613c5ec00deccf296b8619ad507f7050475 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 26 May 2012 10:44:20 +0100 Subject: [PATCH] Test Issue.getComments --- .../description.000.human_readable.json | 1 + .../description.001.normalized.json | 8 ++++++++ doc/ReferenceOfClasses.md | 1 + src/github/Repository.py | 11 ++++++++++- test/MilestonesAndIssues.py | 4 ++++ test/ReplayData/Issue.testComments.txt | 10 ++++++++++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/ReplayData/Issue.testComments.txt diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index c81844ad..e5ce46ec 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -1238,6 +1238,7 @@ { "name": "description", "type": "string" }, { "name": "fork", "type": "bool" }, { "name": "forks", "type": "integer" }, + { "name": "full_name", "type": "string" }, { "name": "git_url", "type": "string" }, { "name": "has_downloads", "type": "bool" }, { "name": "has_issues", "type": "bool" }, diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index 2d310cd5..f57f7e3b 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -7140,6 +7140,14 @@ }, "name": "forks" }, + { + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + }, + "name": "full_name" + }, { "type": { "simple": true, diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index c4fa8b4e..1980ab3b 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -944,6 +944,7 @@ Attributes * `description`: string * `fork`: bool * `forks`: integer +* `full_name`: string * `git_url`: string * `has_downloads`: bool * `has_issues`: bool diff --git a/src/github/Repository.py b/src/github/Repository.py index b254c5df..00ab36b6 100644 --- a/src/github/Repository.py +++ b/src/github/Repository.py @@ -63,6 +63,11 @@ class Repository( object ): self.__completeIfNeeded( self.__forks ) return self.__forks + @property + def full_name( self ): + self.__completeIfNeeded( self.__full_name ) + return self.__full_name + @property def git_url( self ): self.__completeIfNeeded( self.__git_url ) @@ -854,6 +859,7 @@ class Repository( object ): self.__description = None self.__fork = None self.__forks = None + self.__full_name = None self.__git_url = None self.__has_downloads = None self.__has_issues = None @@ -897,7 +903,7 @@ class Repository( object ): def __useAttributes( self, attributes ): # @todo Remove this debug weakness: we shall assume that github will add new attributes for attribute in attributes: - assert attribute in [ "clone_url", "created_at", "description", "fork", "forks", "git_url", "has_downloads", "has_issues", "has_wiki", "homepage", "html_url", "id", "language", "master_branch", "mirror_url", "name", "open_issues", "organization", "owner", "parent", "permissions", "private", "pushed_at", "size", "source", "ssh_url", "svn_url", "updated_at", "url", "watchers", ], attribute + assert attribute in [ "clone_url", "created_at", "description", "fork", "forks", "full_name", "git_url", "has_downloads", "has_issues", "has_wiki", "homepage", "html_url", "id", "language", "master_branch", "mirror_url", "name", "open_issues", "organization", "owner", "parent", "permissions", "private", "pushed_at", "size", "source", "ssh_url", "svn_url", "updated_at", "url", "watchers", ], attribute # @todo No need to check if attribute is in attributes when attribute is mandatory if "clone_url" in attributes and attributes[ "clone_url" ] is not None: assert isinstance( attributes[ "clone_url" ], ( str, unicode ) ) @@ -914,6 +920,9 @@ class Repository( object ): if "forks" in attributes and attributes[ "forks" ] is not None: assert isinstance( attributes[ "forks" ], int ) self.__forks = attributes[ "forks" ] + if "full_name" in attributes and attributes[ "full_name" ] is not None: + assert isinstance( attributes[ "full_name" ], ( str, unicode ) ) + self.__full_name = attributes[ "full_name" ] if "git_url" in attributes and attributes[ "git_url" ] is not None: assert isinstance( attributes[ "git_url" ], ( str, unicode ) ) self.__git_url = attributes[ "git_url" ] diff --git a/test/MilestonesAndIssues.py b/test/MilestonesAndIssues.py index e160c44e..a379bd7c 100644 --- a/test/MilestonesAndIssues.py +++ b/test/MilestonesAndIssues.py @@ -107,6 +107,10 @@ class Issue( Framework.TestCaseWithRepo ): comment = self.repo.get_issue( 28 ).get_comment( 5808311 ) comment.delete() + def testComments( self ): + comment = self.repo.get_issue( 24 ).get_comments()[ 0 ] + self.assertEqual( comment.user.login, "jacquev6" ) + def testEvents( self ): event = self.repo.get_issue( 28 ).get_events()[ 0 ] self.assertEqual( event.actor.login, "jacquev6" ) diff --git a/test/ReplayData/Issue.testComments.txt b/test/ReplayData/Issue.testComments.txt new file mode 100644 index 00000000..a9cf49f7 --- /dev/null +++ b/test/ReplayData/Issue.testComments.txt @@ -0,0 +1,10 @@ +GET /repos/jacquev6/PyGithub/issues/24 {'Authorization': 'Basic login_and_password_removed'} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('content-length', '2945'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"bd0bf26024bb20283dc017ee0099a60a"'), ('date', 'Sat, 26 May 2012 09:43:02 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"updated_at":"2012-05-04T19:23:57Z","body":"Thanks for PyGithub, it is easy to use and very complete. I just successfully used it to convert Trac tickets to Guthub issues.\r\n\r\nBut I had to learn the hard way that `create_issue()` expectes the milestone as number instead of a title. To track this down, I added the following `print` statement to `Requester.py`:\r\n\r\n```python\r\ndef __statusCheckedRequest( self, verb, url, parameters, input ):\r\n status, headers, output = self.__rawRequest( verb, url, parameters, input )\r\n if status < 200 or status >= 300:\r\n print output # <--- Added by me.\r\n raise UnknownGithubObject() # <--- sadly lacks any error details\r\n return headers, output\r\n```\r\n\r\nAs `output` already contains all the information needed (as JSON dump), it would be helpful if the exception raised here would include this information in the exception message.","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/24","comments":2,"milestone":{"closed_issues":2,"creator":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"url":"https://api.github.com/repos/jacquev6/PyGithub/milestones/2","number":2,"title":"Version 1.0: coherent public interface","due_on":"2012-06-04T07:00:00Z","open_issues":9,"created_at":"2012-03-08T12:22:28Z","state":"open","description":"Heavy rewrite to have:\r\n* a fully coherent public interface\r\n* usable stack-traces in case of exception\r\n* more explicit exceptions\r\n* more readable code (for library exploration, auto-completion in IDEs, etc.)\r\n\r\nSee working branch https://github.com/jacquev6/PyGithub/tree/topic/RewriteWithGeneratedCode","id":93547},"number":24,"closed_by":null,"assignee":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"closed_at":null,"title":"Improve error messages on broken requests","labels":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Public+interface","name":"Public interface","color":"d7e102"}],"created_at":"2012-04-30T20:01:20Z","state":"open","user":{"url":"https://api.github.com/users/roskakori","avatar_url":"https://secure.gravatar.com/avatar/b58d0f1ea06b8d5de5f02c53f747ac03?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b58d0f1ea06b8d5de5f02c53f747ac03","login":"roskakori","id":328726},"id":4356743,"pull_request":{"patch_url":null,"diff_url":null,"html_url":null},"html_url":"https://github.com/jacquev6/PyGithub/issues/24"} + +GET /repos/jacquev6/PyGithub/issues/24/comments {'Authorization': 'Basic login_and_password_removed'} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4984'), ('content-length', '1820'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"bab5fb77d873847d153979f7fcd7e0f1"'), ('date', 'Sat, 26 May 2012 09:43:03 GMT'), ('content-type', 'application/json; charset=utf-8')] +[{"user":{"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","url":"https://api.github.com/users/jacquev6","login":"jacquev6","id":327146},"updated_at":"2012-05-01T22:03:59Z","body":"Thank you for the suggestion. It's somehow related to https://github.com/jacquev6/PyGithub/issues/6, even if I have not described it in details.\r\n\r\nI'm currently doing a very deep rewrite, which will lead to much more readable stack traces in case of exceptions, and I will include more details about the error. I may also be able to detect type errors *before* sending the request to github.\r\n\r\nBy the way, I'm very glad to hear that you have solved a real-life use case using PyGithub :-)","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/comments/5449237","id":5449237,"created_at":"2012-05-01T22:03:59Z"},{"user":{"gravatar_id":"b58d0f1ea06b8d5de5f02c53f747ac03","avatar_url":"https://secure.gravatar.com/avatar/b58d0f1ea06b8d5de5f02c53f747ac03?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/roskakori","login":"roskakori","id":328726},"updated_at":"2012-05-04T19:23:57Z","body":"Good to hear you are already working on this in #6, so I suppose this can be tagged as duplicate and be closed.\r\n\r\nBTW, I cleaned up my script to convert Trac tickets to Github issues and uploaded it to PyPI: http://pypi.python.org/pypi/tratihubis/. It seems that at least some people find it useful, so hopefully it helps to popularize PyGithub a little.","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/comments/5518272","id":5518272,"created_at":"2012-05-04T19:23:57Z"}] +