From f0430bb535865ba08745218d9e84d53f9c7a3d84 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Fri, 4 May 2012 16:28:12 +0200 Subject: [PATCH] Restore some tests and explain why others are failing --- .../GithubObject.MethodBody.DoRequest.py | 12 ++- .../GithubObject.MethodBody.UseResult.py | 8 ++ IntegrationTest.py | 93 +++++++++-------- .../description.000.human_readable.json | 30 +++++- .../description.001.normalized.json | 99 +++++++++++++++++++ JsonDescriptionOfGithubApiV3/normalize.py | 32 +++++- .../MergePullRequest.txt | 2 +- github/Github.py | 20 ++-- github/GithubObjects/AuthenticatedUser.py | 17 +++- github/GithubObjects/Hook.py | 7 +- github/GithubObjects/Issue.py | 8 +- github/GithubObjects/PullRequest.py | 15 ++- 12 files changed, 274 insertions(+), 69 deletions(-) diff --git a/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py b/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py index 59fb0235..197261a9 100644 --- a/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py +++ b/CodeGenerator/templates/GithubObject.MethodBody.DoRequest.py @@ -1,13 +1,17 @@ {% if method.request.post_parameters %} + {% if method.variadic_parameter %} + post_parameters = {{ method.variadic_parameter.name }}s + {% else %} post_parameters = { - {% for parameter in method.mandatory_parameters %} + {% for parameter in method.mandatory_parameters %} "{{ parameter.name }}": {{ parameter.name }}, - {% endfor %} + {% endfor %} } - {% for parameter in method.optional_parameters %} + {% for parameter in method.optional_parameters %} if {{ parameter.name }} is not DefaultValueForOptionalParameters: post_parameters[ "{{ parameter.name }}" ] = {{ parameter.name }} - {% endfor %} + {% endfor %} + {% endif %} {% endif %} status, headers, data = self.__requester.request( diff --git a/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py b/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py index 6ef07acc..667fba13 100644 --- a/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py +++ b/CodeGenerator/templates/GithubObject.MethodBody.UseResult.py @@ -4,10 +4,18 @@ {% if method.type.simple %} +{% if method.type.cardinality == "scalar" %} + {% if method.type.name == "bool" %} return status == 204 {% endif %} +{% endif %} + +{% if method.type.cardinality == "list" %} + return data +{% endif %} + {% else %} {% if method.type.cardinality == "scalar" %} diff --git a/IntegrationTest.py b/IntegrationTest.py index d1b2ba51..818b09bb 100644 --- a/IntegrationTest.py +++ b/IntegrationTest.py @@ -335,6 +335,7 @@ class IntegrationTest: t.delete() self.printList( "Teams", o.get_teams(), lambda t: t.name ) + # @todo Restore correct pagination # def testEvents( self ): # self.printList( "User events", self.g.get_user( self.cobayeUser ).get_events(), lambda e: e.type ) # self.printList( "User public events", self.g.get_user( self.cobayeUser ).get_public_events(), lambda e: e.type ) @@ -354,16 +355,17 @@ class IntegrationTest: # self.printList( "Issue events", self.g.get_user().get_repo( "TestPyGithub" ).get_issue( 23 ).get_events(), lambda e: e.event ) - # def testFollow( self ): - # cobaye = self.g.get_user( self.cobayeUser ) - # u = self.g.get_user() - # u.remove_from_following( cobaye ) - # assert not u.has_in_following( cobaye ) - # u.add_to_following( cobaye ) - # assert u.has_in_following( cobaye ) - # self.printList( "Following", u.get_following(), lambda f: f.login ) - # self.printList( "Followers", u.get_followers(), lambda f: f.login ) + def testFollow( self ): + cobaye = self.g.get_user( self.cobayeUser ) + u = self.g.get_user() + u.remove_from_following( cobaye ) + assert not u.has_in_following( cobaye ) + u.add_to_following( cobaye ) + assert u.has_in_following( cobaye ) + self.printList( "Following", u.get_following(), lambda f: f.login ) + self.printList( "Followers", u.get_followers(), lambda f: f.login ) + # @todo custom url /gists instead of /user/gists # def testGists( self ): # u = self.g.get_user() # self.printList( "Gists", u.get_gists(), lambda g: g.description ) @@ -399,6 +401,7 @@ class IntegrationTest: # def testGistsAll( self ): # self.printList( "Gists", self.g.get_gists(), lambda g: g.description ) + # @todo custom url/repos/BeaverSoftware/TestPyGithub/git/refs/heads/master instead of /repos/BeaverSoftware/TestPyGithub/git_refs/refs/heads/master # def testGitObjects( self ): # o = self.g.get_organization( self.cobayeOrganization ) # r = o.get_repo( "TestPyGithub" ) @@ -433,22 +436,22 @@ class IntegrationTest: # blob = r.create_git_blob( "This blob was also created by PyGithub", encoding = "latin1" ) # tree = r.create_git_tree( [ { "path": "new.bar", "mode": "100644", "type": "blob", "sha": blob.sha } ], base_tree = masterTree.sha ) - # def testHooks( self ): - # u = self.g.get_user() - # r = u.get_repo( "TestPyGithub" ) + def testHooks( self ): + u = self.g.get_user() + r = u.get_repo( "TestPyGithub" ) - # self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) - # h = r.create_hook( "web", { "url": "http://www.invalid.org" } ) - # self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) - # h.edit( "web", { "url": "http://www.postbin.org/w5cgjr" } ) - # self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) + self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) + h = r.create_hook( "web", { "url": "http://www.invalid.org" } ) + self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) + h.edit( "web", { "url": "http://www.postbin.org/w5cgjr" } ) + self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) - # sameHook = r.get_hook( h.id ) + sameHook = r.get_hook( h.id ) - # h.test() + h.test() - # h.delete() - # self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) + h.delete() + self.printList( "Hooks", r.get_hooks(), lambda h: h.name + str( h.config ) ) # def testIssuesAndMilestones( self ): # u = self.g.get_user() @@ -505,9 +508,11 @@ class IntegrationTest: # m.delete() # self.printList( "Milestones", r.get_milestones(), lambda m: m.title ) + # @todo custom url /issues instead of /user/issues # def testIssuesForAuthenticatedUser( self ): # self.printList( "Issues", self.g.get_user().get_issues(), lambda i: i.title ) + # @todo custom url /user/keys instead of /users/jacquev6/keys # def testKeys( self ): # u = self.g.get_user() # self.printList( "Keys", u.get_keys(), lambda k: k.title ) @@ -519,12 +524,12 @@ class IntegrationTest: # k.delete() # self.printList( "Keys", u.get_keys(), lambda k: k.title ) - # def testMergePullRequest( self ): - # r = self.g.get_user().get_repo( "TestPyGithub" ) - # p = r.get_pull( 26 ) - # assert not p.is_merged() - # p.merge() - # assert p.is_merged() + def testMergePullRequest( self ): + r = self.g.get_user().get_repo( "TestPyGithub" ) + p = r.get_pull( 26 ) + assert not p.is_merged() + p.merge() + assert p.is_merged() def testNamedUserDetails( self ): u = self.g.get_user( "jacquev6" ) @@ -540,6 +545,7 @@ class IntegrationTest: o = self.g.get_organization( "github" ) print o.login, "(" + o.name + ") is in", o.location + # @todo Two versions of Repository.create_pull # def testPullRequest( self ): # r = self.g.get_user().get_repo( "TestPyGithub" ) # self.printList( "Pull requests", r.get_pulls(), lambda p: p.title ) @@ -562,10 +568,12 @@ class IntegrationTest: # p2.edit( state = "closed" ) # self.printList( "Pull requests", r.get_pulls(), lambda p: p.title ) + # @todo Repository.compare # def testRepositoryCompare( self ): # r = self.g.get_user().get_repo( "PyGithub" ) # print str( r.compare( "master", "develop" ) )[ :100 ] + # @todo Repository.get_languages # def testRepositoryDetails( self ): # r1 = self.g.get_user().get_repo( "PyGithub" ) # r2 = self.g.get_user().get_repo( "TestPyGithub" ) @@ -581,6 +589,7 @@ class IntegrationTest: # r3 = self.g.get_organization( "BeaverSoftware" ).get_repo( "TestPyGithub" ) # self.printList( "Teams", r3.get_teams(), lambda t: t.name ) + # @todo Custom url # def testRepositoryKeys( self ): # r = self.g.get_user().get_repo( "TestPyGithub" ) # self.printList( "Keys", r.get_keys(), lambda k: k.title ) @@ -592,22 +601,22 @@ class IntegrationTest: # sameKey.delete() # self.printList( "Keys", r.get_keys(), lambda k: k.title ) - # def testWatch( self ): - # r = self.g.get_user( "jacquev6" ).get_repo( "PyGithub" ) - # u = self.g.get_user() - # u.remove_from_watched( r ) - # assert not u.has_in_watched( r ) - # u.add_to_watched( r ) - # assert u.has_in_watched( r ) - # self.printList( "Watched", u.get_watched(), lambda r: r.name ) + def testWatch( self ): + r = self.g.get_user( "jacquev6" ).get_repo( "PyGithub" ) + u = self.g.get_user() + u.remove_from_watched( r ) + assert not u.has_in_watched( r ) + u.add_to_watched( r ) + assert u.has_in_watched( r ) + self.printList( "Watched", u.get_watched(), lambda r: r.name ) - # def testEmails( self ): - # u = self.g.get_user() - # self.printList( "Emails", u.get_emails() ) - # u.add_to_emails( "ab@xxx.com", "cd@xxx.com" ) - # self.printList( "Emails", u.get_emails() ) - # u.remove_from_emails( "ab@xxx.com", "cd@xxx.com" ) - # self.printList( "Emails", u.get_emails() ) + def testEmails( self ): + u = self.g.get_user() + self.printList( "Emails", u.get_emails() ) + u.add_to_emails( "ab@xxx.com", "cd@xxx.com" ) + self.printList( "Emails", u.get_emails() ) + u.remove_from_emails( "ab@xxx.com", "cd@xxx.com" ) + self.printList( "Emails", u.get_emails() ) def printList( self, title, iterable, f = lambda x: x ): print title + ":", ", ".join( str( f( x ) ) for x in iterable[ :10 ] ), "..." if len( iterable ) > 10 else "" diff --git a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index d50db4cc..37b89d9a 100644 --- a/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -522,7 +522,15 @@ { "name": [ "test" ], "group": "testing", - "type": "void" + "type": "void", + "request": { + "verb": "POST", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/test" } + ], + "information": "status" + } } ] }, @@ -974,7 +982,15 @@ { "name": [ "is", "merged" ], "type": "bool", - "group": "merging" + "group": "merging", + "request": { + "verb": "GET", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/merge" } + ], + "information": "status" + } }, { "name": [ "merge" ], @@ -982,7 +998,15 @@ "group": "merging", "optional_parameters": [ { "name": "commit_message", "type": "string" } - ] + ], + "request": { + "verb": "PUT", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/merge" } + ], + "information": "status" + } } ] }, diff --git a/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/JsonDescriptionOfGithubApiV3/description.001.normalized.json index f2bb11a6..fb6705bc 100644 --- a/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -814,6 +814,23 @@ "name": "email" }, "optional_parameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/emails" + } + ], + "information": "status", + "post_parameters": true, + "verb": "POST" + }, "type": { "simple": true, "cardinality": "scalar", @@ -869,6 +886,23 @@ "name": "email" }, "optional_parameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/emails" + } + ], + "information": "status", + "post_parameters": true, + "verb": "DELETE" + }, "type": { "simple": true, "cardinality": "scalar", @@ -3272,6 +3306,22 @@ "name": [ "test" ], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/test" + } + ], + "information": "status", + "verb": "POST" + }, "optional_parameters": [], "type": { "simple": true, @@ -3665,6 +3715,23 @@ "name": "label" }, "optional_parameters": [], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/labels" + } + ], + "information": "status", + "post_parameters": true, + "verb": "POST" + }, "type": { "simple": true, "cardinality": "scalar", @@ -6235,6 +6302,22 @@ "is", "merged" ], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/merge" + } + ], + "information": "status", + "verb": "GET" + }, "optional_parameters": [], "type": { "simple": true, @@ -6249,6 +6332,22 @@ "name": [ "merge" ], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/merge" + } + ], + "information": "status", + "verb": "PUT" + }, "optional_parameters": [ { "type": { diff --git a/JsonDescriptionOfGithubApiV3/normalize.py b/JsonDescriptionOfGithubApiV3/normalize.py index 6f367560..01570ba6 100644 --- a/JsonDescriptionOfGithubApiV3/normalize.py +++ b/JsonDescriptionOfGithubApiV3/normalize.py @@ -129,7 +129,20 @@ class Collection: ) ) if "add_several_elements" in desc: assert desc[ "add_several_elements" ] is True - self.methods.append( Function( { "name": [ "add", "to" ] + name, "type": "void", "group": desc[ "name" ], "variadic_parameter": { "name": desc[ "singular_name" ], "type": desc[ "type" ] } } ) ) + self.methods.append( Function( + { "name": [ "add", "to" ] + name, "type": "void", "group": desc[ "name" ], "variadic_parameter": { "name": desc[ "singular_name" ], "type": desc[ "type" ] } }, + { + "request": { + "verb": "POST", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/" + desc[ "name" ] }, + ], + "information": "status", + "post_parameters": True + } + } + ) ) if "create_element" in desc: self.methods.append( Function( desc[ "create_element" ], @@ -223,10 +236,23 @@ class Collection: "information": "status", } } - ) ) + ) ) if "remove_several_elements" in desc: assert desc[ "remove_several_elements" ] is True - self.methods.append( Function( { "name": [ "remove", "from" ] + name, "type": "void", "group": desc[ "name" ], "variadic_parameter": { "name": desc[ "singular_name" ], "type": desc[ "type" ] } } ) ) + self.methods.append( Function( + { "name": [ "remove", "from" ] + name, "type": "void", "group": desc[ "name" ], "variadic_parameter": { "name": desc[ "singular_name" ], "type": desc[ "type" ] } }, + { + "request": { + "verb": "DELETE", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/" + desc[ "name" ] }, + ], + "information": "status", + "post_parameters": True + } + } + ) ) if "set_list" in desc: assert desc[ "set_list" ] is True self.methods.append( Function( { "name": [ "set" ] + name, "type": "void", "group": desc[ "name" ], "variadic_parameter": { "name": desc[ "singular_name" ], "type": desc[ "type" ] } } ) ) diff --git a/ReplayDataForIntegrationTest/MergePullRequest.txt b/ReplayDataForIntegrationTest/MergePullRequest.txt index 5fb50bcb..b9daba4c 100644 --- a/ReplayDataForIntegrationTest/MergePullRequest.txt +++ b/ReplayDataForIntegrationTest/MergePullRequest.txt @@ -18,7 +18,7 @@ GET /repos/jacquev6/TestPyGithub/pulls/26/merge {} null [('status', '404 Not Found'), ('x-ratelimit-remaining', '4978'), ('content-length', '23'), ('server', 'nginx/1.0.12'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"e66a7a6c91e2c26803f3f49feb7a883f"'), ('date', 'Mon, 12 Mar 2012 21:04:50 GMT'), ('content-type', 'application/json; charset=utf-8')] {"message":"Not Found"} -PUT /repos/jacquev6/TestPyGithub/pulls/26/merge {} {} +PUT /repos/jacquev6/TestPyGithub/pulls/26/merge {} null 200 [('status', '200 OK'), ('x-ratelimit-remaining', '4977'), ('content-length', '109'), ('server', 'nginx/1.0.12'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"6a9d69e558b3ab1b3747a666517b02c5"'), ('date', 'Mon, 12 Mar 2012 21:04:51 GMT'), ('content-type', 'application/json; charset=utf-8')] {"merged":true,"message":"Pull Request successfully merged","sha":"5098a3636ee911fcc01391c7d8ae0afbc1966aee"} diff --git a/github/Github.py b/github/Github.py index 158160bb..f7fe4f67 100644 --- a/github/Github.py +++ b/github/Github.py @@ -11,7 +11,7 @@ class Github: def get_user( self, login = None ): if login is None: attributes = { - "url": "https://api.github.com/user", + "url": "https://api.github.com/user", # @todo Erf, this url is replaced by /users/login when __complete is called... # "login": self.__login # @todo ? } return GithubObjects.AuthenticatedUser.AuthenticatedUser( self.__requester, attributes, lazy = True ) @@ -29,13 +29,13 @@ class Github: } return GithubObjects.Organization.Organization( self.__requester, attributes, lazy = False ) - # def get_gist( self, id ): - # return GithubObjects.Gist.Gist( self.__requester, { "id": id }, lazy = False ) + def get_gist( self, id ): + return GithubObjects.Gist.Gist( self.__requester, { "id": id }, lazy = False ) - # def get_gists( self ): - # status, headers, data = self.__requester.request( "GET", "/gists/public", None, None ) - # return [ - # GithubObjects.Gist.Gist( self.__requester, attributes, lazy = True ) - # for attributes - # in data - # ] + def get_gists( self ): + status, headers, data = self.__requester.request( "GET", "/gists/public", None, None ) + return [ + GithubObjects.Gist.Gist( self.__requester, attributes, lazy = True ) + for attributes + in data + ] diff --git a/github/GithubObjects/AuthenticatedUser.py b/github/GithubObjects/AuthenticatedUser.py index 7801b80f..44983b65 100644 --- a/github/GithubObjects/AuthenticatedUser.py +++ b/github/GithubObjects/AuthenticatedUser.py @@ -150,7 +150,13 @@ class AuthenticatedUser( object ): return self.__url def add_to_emails( self, *emails ): - pass + post_parameters = emails + status, headers, data = self.__requester.request( + "POST", + str( self.url ) + "/emails", + None, + post_parameters + ) def add_to_following( self, following ): status, headers, data = self.__requester.request( @@ -301,6 +307,7 @@ class AuthenticatedUser( object ): None, None ) + return data def get_events( self ): status, headers, data = self.__requester.request( @@ -453,7 +460,13 @@ class AuthenticatedUser( object ): return status == 204 def remove_from_emails( self, *emails ): - pass + post_parameters = emails + status, headers, data = self.__requester.request( + "DELETE", + str( self.url ) + "/emails", + None, + post_parameters + ) def remove_from_following( self, following ): status, headers, data = self.__requester.request( diff --git a/github/GithubObjects/Hook.py b/github/GithubObjects/Hook.py index 7f93b1be..e99133c6 100644 --- a/github/GithubObjects/Hook.py +++ b/github/GithubObjects/Hook.py @@ -91,7 +91,12 @@ class Hook( object ): self.__useAttributes( data ) def test( self ): - pass + status, headers, data = self.__requester.request( + "POST", + str( self.url ) + "/test", + None, + None + ) def __initAttributes( self ): self.__active = None diff --git a/github/GithubObjects/Issue.py b/github/GithubObjects/Issue.py index 42c217d7..052e2e4e 100644 --- a/github/GithubObjects/Issue.py +++ b/github/GithubObjects/Issue.py @@ -107,7 +107,13 @@ class Issue( object ): return self.__user def add_to_labels( self, *labels ): - pass + post_parameters = labels + status, headers, data = self.__requester.request( + "POST", + str( self.url ) + "/labels", + None, + post_parameters + ) def create_comment( self, body ): post_parameters = { diff --git a/github/GithubObjects/PullRequest.py b/github/GithubObjects/PullRequest.py index 2ffad59f..681c6d36 100644 --- a/github/GithubObjects/PullRequest.py +++ b/github/GithubObjects/PullRequest.py @@ -213,10 +213,21 @@ class PullRequest( object ): ] def is_merged( self ): - pass + status, headers, data = self.__requester.request( + "GET", + str( self.url ) + "/merge", + None, + None + ) + return status == 204 def merge( self, commit_message = DefaultValueForOptionalParameters ): - pass + status, headers, data = self.__requester.request( + "PUT", + str( self.url ) + "/merge", + None, + None + ) def __initAttributes( self ): self.__additions = None