From 55779ebbb4d8848ca7a2cf6ffbeb029239dbfdf2 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Fri, 18 May 2012 20:56:30 +0100 Subject: [PATCH] Test attributes of NamedUser --- .../description.000.human_readable.json | 44 ++++++------- .../description.001.normalized.json | 46 +++++++------- doc/ReferenceOfClasses.md | 44 ++++++------- src/github/NamedUser.py | 29 ++++++++- test/IntegrationTest.py | 1 + test/NamedUser.py | 61 +++++++++++++++++++ test/ReplayData/NamedUser.setUp.txt | 5 ++ .../NamedUser.testAttributesOfOtherUser.txt | 5 ++ .../NamedUser.testAttributesOfSelf.txt | 5 ++ 9 files changed, 170 insertions(+), 70 deletions(-) create mode 100644 test/NamedUser.py create mode 100644 test/ReplayData/NamedUser.setUp.txt create mode 100644 test/ReplayData/NamedUser.testAttributesOfOtherUser.txt create mode 100644 test/ReplayData/NamedUser.testAttributesOfSelf.txt diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index e775de75..e42c7b0f 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -838,32 +838,32 @@ "name": "NamedUser", "isCompletable": true, "attributes": [ - { "name": "avatar_url", "type": "@todo" }, - { "name": "bio", "type": "@todo" }, - { "name": "blog", "type": "@todo" }, - { "name": "collaborators", "type": "@todo" }, - { "name": "company", "type": "@todo" }, - { "name": "contributions", "type": "@todo" }, - { "name": "created_at", "type": "@todo" }, - { "name": "disk_usage", "type": "@todo" }, - { "name": "email", "type": "@todo" }, + { "name": "avatar_url", "type": "string" }, + { "name": "bio", "type": "string" }, + { "name": "blog", "type": "string" }, + { "name": "collaborators", "type": "integer" }, + { "name": "company", "type": "string" }, + { "name": "contributions", "type": "integer" }, + { "name": "created_at", "type": "string" }, + { "name": "disk_usage", "type": "integer" }, + { "name": "email", "type": "string" }, { "name": "followers", "type": "integer" }, - { "name": "following", "type": "@todo" }, - { "name": "gravatar_id", "type": "@todo" }, - { "name": "hireable", "type": "@todo" }, - { "name": "html_url", "type": "@todo" }, - { "name": "id", "type": "@todo" }, + { "name": "following", "type": "integer" }, + { "name": "gravatar_id", "type": "string" }, + { "name": "hireable", "type": "bool" }, + { "name": "html_url", "type": "string" }, + { "name": "id", "type": "integer" }, { "name": "location", "type": "string" }, { "name": "login", "type": "string" }, { "name": "name", "type": "string" }, - { "name": "owned_private_repos", "type": "@todo" }, - { "name": "plan", "type": "@todo" }, - { "name": "private_gists", "type": "@todo" }, - { "name": "public_gists", "type": "@todo" }, - { "name": "public_repos", "type": "@todo" }, - { "name": "total_private_repos", "type": "@todo" }, - { "name": "type", "type": "@todo" }, - { "name": "url", "type": "@todo" } + { "name": "owned_private_repos", "type": "integer" }, + { "name": "plan", "type": "Plan" }, + { "name": "private_gists", "type": "integer" }, + { "name": "public_gists", "type": "integer" }, + { "name": "public_repos", "type": "integer" }, + { "name": "total_private_repos", "type": "integer" }, + { "name": "type", "type": "string" }, + { "name": "url", "type": "string" } ], "identity": [ { "type": "attribute", "value": [ "login" ] } ], "collections": [ diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index 8130c6ad..46736a5f 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -4653,7 +4653,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "avatar_url" }, @@ -4661,7 +4661,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "bio" }, @@ -4669,7 +4669,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "blog" }, @@ -4677,7 +4677,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "collaborators" }, @@ -4685,7 +4685,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "company" }, @@ -4693,7 +4693,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "contributions" }, @@ -4701,7 +4701,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "created_at" }, @@ -4709,7 +4709,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "disk_usage" }, @@ -4717,7 +4717,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "email" }, @@ -4733,7 +4733,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "following" }, @@ -4741,7 +4741,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "gravatar_id" }, @@ -4749,7 +4749,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "bool" }, "name": "hireable" }, @@ -4757,7 +4757,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "html_url" }, @@ -4765,7 +4765,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "id" }, @@ -4797,15 +4797,15 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "owned_private_repos" }, { "type": { - "simple": true, + "simple": false, "cardinality": "scalar", - "name": "@todo" + "name": "Plan" }, "name": "plan" }, @@ -4813,7 +4813,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "private_gists" }, @@ -4821,7 +4821,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "public_gists" }, @@ -4829,7 +4829,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "public_repos" }, @@ -4837,7 +4837,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "total_private_repos" }, @@ -4845,7 +4845,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "type" }, @@ -4853,7 +4853,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "url" } diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index be55306e..c3c2fa2d 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -647,32 +647,32 @@ Class `NamedUser` Attributes ---------- -* `avatar_url` -* `bio` -* `blog` -* `collaborators` -* `company` -* `contributions` -* `created_at` -* `disk_usage` -* `email` +* `avatar_url`: string +* `bio`: string +* `blog`: string +* `collaborators`: integer +* `company`: string +* `contributions`: integer +* `created_at`: string +* `disk_usage`: integer +* `email`: string * `followers`: integer -* `following` -* `gravatar_id` -* `hireable` -* `html_url` -* `id` +* `following`: integer +* `gravatar_id`: string +* `hireable`: bool +* `html_url`: string +* `id`: integer * `location`: string * `login`: string * `name`: string -* `owned_private_repos` -* `plan` -* `private_gists` -* `public_gists` -* `public_repos` -* `total_private_repos` -* `type` -* `url` +* `owned_private_repos`: integer +* `plan`: `Plan` +* `private_gists`: integer +* `public_gists`: integer +* `public_repos`: integer +* `total_private_repos`: integer +* `type`: string +* `url`: string Events ------ diff --git a/src/github/NamedUser.py b/src/github/NamedUser.py index 36678ec8..052be681 100644 --- a/src/github/NamedUser.py +++ b/src/github/NamedUser.py @@ -3,11 +3,12 @@ import PaginatedList from GithubObject import * -import Organization import Gist -import Event import Repository import NamedUser +import Plan +import Organization +import Event class NamedUser( object ): def __init__( self, requester, attributes, completion ): @@ -365,35 +366,49 @@ class NamedUser( object ): assert attribute in [ "avatar_url", "bio", "blog", "collaborators", "company", "contributions", "created_at", "disk_usage", "email", "followers", "following", "gravatar_id", "hireable", "html_url", "id", "location", "login", "name", "owned_private_repos", "plan", "private_gists", "public_gists", "public_repos", "total_private_repos", "type", "url", ], attribute # @todo No need to check if attribute is in attributes when attribute is mandatory if "avatar_url" in attributes and attributes[ "avatar_url" ] is not None: + assert isinstance( attributes[ "avatar_url" ], ( str, unicode ) ) self.__avatar_url = attributes[ "avatar_url" ] if "bio" in attributes and attributes[ "bio" ] is not None: + assert isinstance( attributes[ "bio" ], ( str, unicode ) ) self.__bio = attributes[ "bio" ] if "blog" in attributes and attributes[ "blog" ] is not None: + assert isinstance( attributes[ "blog" ], ( str, unicode ) ) self.__blog = attributes[ "blog" ] if "collaborators" in attributes and attributes[ "collaborators" ] is not None: + assert isinstance( attributes[ "collaborators" ], int ) self.__collaborators = attributes[ "collaborators" ] if "company" in attributes and attributes[ "company" ] is not None: + assert isinstance( attributes[ "company" ], ( str, unicode ) ) self.__company = attributes[ "company" ] if "contributions" in attributes and attributes[ "contributions" ] is not None: + assert isinstance( attributes[ "contributions" ], int ) self.__contributions = attributes[ "contributions" ] if "created_at" in attributes and attributes[ "created_at" ] is not None: + assert isinstance( attributes[ "created_at" ], ( str, unicode ) ) self.__created_at = attributes[ "created_at" ] if "disk_usage" in attributes and attributes[ "disk_usage" ] is not None: + assert isinstance( attributes[ "disk_usage" ], int ) self.__disk_usage = attributes[ "disk_usage" ] if "email" in attributes and attributes[ "email" ] is not None: + assert isinstance( attributes[ "email" ], ( str, unicode ) ) self.__email = attributes[ "email" ] if "followers" in attributes and attributes[ "followers" ] is not None: assert isinstance( attributes[ "followers" ], int ) self.__followers = attributes[ "followers" ] if "following" in attributes and attributes[ "following" ] is not None: + assert isinstance( attributes[ "following" ], int ) self.__following = attributes[ "following" ] if "gravatar_id" in attributes and attributes[ "gravatar_id" ] is not None: + assert isinstance( attributes[ "gravatar_id" ], ( str, unicode ) ) self.__gravatar_id = attributes[ "gravatar_id" ] if "hireable" in attributes and attributes[ "hireable" ] is not None: + assert isinstance( attributes[ "hireable" ], bool ) self.__hireable = attributes[ "hireable" ] if "html_url" in attributes and attributes[ "html_url" ] is not None: + assert isinstance( attributes[ "html_url" ], ( str, unicode ) ) self.__html_url = attributes[ "html_url" ] if "id" in attributes and attributes[ "id" ] is not None: + assert isinstance( attributes[ "id" ], int ) self.__id = attributes[ "id" ] if "location" in attributes and attributes[ "location" ] is not None: assert isinstance( attributes[ "location" ], ( str, unicode ) ) @@ -405,18 +420,26 @@ class NamedUser( object ): assert isinstance( attributes[ "name" ], ( str, unicode ) ) self.__name = attributes[ "name" ] if "owned_private_repos" in attributes and attributes[ "owned_private_repos" ] is not None: + assert isinstance( attributes[ "owned_private_repos" ], int ) self.__owned_private_repos = attributes[ "owned_private_repos" ] if "plan" in attributes and attributes[ "plan" ] is not None: - self.__plan = attributes[ "plan" ] + assert isinstance( attributes[ "plan" ], dict ) + self.__plan = Plan.Plan( self.__requester, attributes[ "plan" ], completion = LazyCompletion ) if "private_gists" in attributes and attributes[ "private_gists" ] is not None: + assert isinstance( attributes[ "private_gists" ], int ) self.__private_gists = attributes[ "private_gists" ] if "public_gists" in attributes and attributes[ "public_gists" ] is not None: + assert isinstance( attributes[ "public_gists" ], int ) self.__public_gists = attributes[ "public_gists" ] if "public_repos" in attributes and attributes[ "public_repos" ] is not None: + assert isinstance( attributes[ "public_repos" ], int ) self.__public_repos = attributes[ "public_repos" ] if "total_private_repos" in attributes and attributes[ "total_private_repos" ] is not None: + assert isinstance( attributes[ "total_private_repos" ], int ) self.__total_private_repos = attributes[ "total_private_repos" ] if "type" in attributes and attributes[ "type" ] is not None: + assert isinstance( attributes[ "type" ], ( str, unicode ) ) self.__type = attributes[ "type" ] if "url" in attributes and attributes[ "url" ] is not None: + assert isinstance( attributes[ "url" ], ( str, unicode ) ) self.__url = attributes[ "url" ] diff --git a/test/IntegrationTest.py b/test/IntegrationTest.py index 0fe8fbb2..df1fb954 100644 --- a/test/IntegrationTest.py +++ b/test/IntegrationTest.py @@ -7,5 +7,6 @@ from GitObjects import * from Repository import * from Organization import * from MilestonesAndIssues import * +from NamedUser import * Framework.main() diff --git a/test/NamedUser.py b/test/NamedUser.py new file mode 100644 index 00000000..fc7a138c --- /dev/null +++ b/test/NamedUser.py @@ -0,0 +1,61 @@ +import Framework + +class NamedUser( Framework.TestCase ): + def testAttributesOfOtherUser( self ): + user = self.g.get_user( "nvie" ) + self.assertEqual( user.avatar_url, "https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" ) + self.assertEqual( user.bio, None ) + self.assertEqual( user.blog, "http://nvie.com" ) + self.assertEqual( user.collaborators, None ) + self.assertEqual( user.company, "3rd Cloud" ) + self.assertEqual( user.created_at, "2009-05-12T21:19:38Z" ) + self.assertEqual( user.disk_usage, None ) + self.assertEqual( user.email, "vincent@3rdcloud.com" ) + self.assertEqual( user.followers, 296 ) + self.assertEqual( user.following, 41 ) + self.assertEqual( user.gravatar_id, "c5a7f21b46df698f3db31c37ed0cf55a" ) + self.assertEqual( user.hireable, False ) + self.assertEqual( user.html_url, "https://github.com/nvie" ) + self.assertEqual( user.id, 83844 ) + self.assertEqual( user.location, "Netherlands" ) + self.assertEqual( user.login, "nvie" ) + self.assertEqual( user.name, "Vincent Driessen" ) + self.assertEqual( user.owned_private_repos, None ) + self.assertEqual( user.plan, None ) + self.assertEqual( user.private_gists, None ) + self.assertEqual( user.public_gists, 16 ) + self.assertEqual( user.public_repos, 61 ) + self.assertEqual( user.total_private_repos, None ) + self.assertEqual( user.type, "User" ) + self.assertEqual( user.url, "https://api.github.com/users/nvie" ) + + def testAttributesOfSelf( self ): + user = self.g.get_user( "jacquev6" ) + self.assertEqual( user.avatar_url, "https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" ) + self.assertEqual( user.bio, "" ) + self.assertEqual( user.blog, "http://vincent-jacques.net" ) + self.assertEqual( user.collaborators, 0 ) + self.assertEqual( user.company, "Criteo" ) + self.assertEqual( user.created_at, "2010-07-09T06:10:06Z" ) + self.assertEqual( user.disk_usage, 16852 ) + self.assertEqual( user.email, "vincent@vincent-jacques.net" ) + self.assertEqual( user.followers, 13 ) + self.assertEqual( user.following, 24 ) + self.assertEqual( user.gravatar_id, "b68de5ae38616c296fa345d2b9df2225" ) + self.assertEqual( user.hireable, False ) + self.assertEqual( user.html_url, "https://github.com/jacquev6" ) + self.assertEqual( user.id, 327146 ) + self.assertEqual( user.location, "Paris, France" ) + self.assertEqual( user.login, "jacquev6" ) + self.assertEqual( user.name, "Vincent Jacques" ) + self.assertEqual( user.owned_private_repos, 5 ) + self.assertEqual( user.plan.name, "micro" ) + self.assertEqual( user.plan.collaborators, 1 ) + self.assertEqual( user.plan.space, 614400 ) + self.assertEqual( user.plan.private_repos, 5 ) + self.assertEqual( user.private_gists, 5 ) + self.assertEqual( user.public_gists, 1 ) + self.assertEqual( user.public_repos, 11 ) + self.assertEqual( user.total_private_repos, 5 ) + self.assertEqual( user.type, "User" ) + self.assertEqual( user.url, "https://api.github.com/users/jacquev6" ) diff --git a/test/ReplayData/NamedUser.setUp.txt b/test/ReplayData/NamedUser.setUp.txt new file mode 100644 index 00000000..39cc3693 --- /dev/null +++ b/test/ReplayData/NamedUser.setUp.txt @@ -0,0 +1,5 @@ +GET /users/nvie {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4995'), ('content-length', '598'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"bcaad5c484c725472be0af398e4eed6f"'), ('date', 'Fri, 18 May 2012 19:42:01 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"type":"User","bio":null,"public_gists":16,"company":"3rd Cloud","url":"https://api.github.com/users/nvie","gravatar_id":"c5a7f21b46df698f3db31c37ed0cf55a","public_repos":61,"followers":296,"login":"nvie","blog":"http://nvie.com","email":"vincent@3rdcloud.com","html_url":"https://github.com/nvie","name":"Vincent Driessen","created_at":"2009-05-12T21:19:38Z","location":"Netherlands","avatar_url":"https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":83844,"following":41,"hireable":false} + diff --git a/test/ReplayData/NamedUser.testAttributesOfOtherUser.txt b/test/ReplayData/NamedUser.testAttributesOfOtherUser.txt new file mode 100644 index 00000000..9a007da0 --- /dev/null +++ b/test/ReplayData/NamedUser.testAttributesOfOtherUser.txt @@ -0,0 +1,5 @@ +GET /users/nvie {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('content-length', '598'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"66a516a2007fb7df8bbb3f9cc7cb2da8"'), ('date', 'Fri, 18 May 2012 19:46:37 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"public_gists":16,"type":"User","hireable":false,"company":"3rd Cloud","url":"https://api.github.com/users/nvie","gravatar_id":"c5a7f21b46df698f3db31c37ed0cf55a","bio":null,"followers":296,"blog":"http://nvie.com","avatar_url":"https://secure.gravatar.com/avatar/c5a7f21b46df698f3db31c37ed0cf55a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"nvie","email":"vincent@3rdcloud.com","public_repos":61,"html_url":"https://github.com/nvie","name":"Vincent Driessen","created_at":"2009-05-12T21:19:38Z","location":"Netherlands","id":83844,"following":41} + diff --git a/test/ReplayData/NamedUser.testAttributesOfSelf.txt b/test/ReplayData/NamedUser.testAttributesOfSelf.txt new file mode 100644 index 00000000..aec165bd --- /dev/null +++ b/test/ReplayData/NamedUser.testAttributesOfSelf.txt @@ -0,0 +1,5 @@ +GET /users/jacquev6 {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4993'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"77d7c9fc30183d925c68c4f8db7aac64"'), ('date', 'Fri, 18 May 2012 19:46:37 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"private_gists":5,"type":"User","owned_private_repos":5,"followers":13,"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","disk_usage":16852,"public_repos":11,"following":24,"blog":"http://vincent-jacques.net","hireable":false,"collaborators":0,"url":"https://api.github.com/users/jacquev6","name":"Vincent Jacques","company":"Criteo","bio":"","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","public_gists":1,"html_url":"https://github.com/jacquev6","email":"vincent@vincent-jacques.net","id":327146,"total_private_repos":5,"plan":{"private_repos":5,"collaborators":1,"name":"micro","space":614400},"created_at":"2010-07-09T06:10:06Z"} +