From 5a943ad0b255797cea79188bb346c670076062ce Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 12 May 2012 11:15:20 +0200 Subject: [PATCH] Test Organization attributes --- .../description.000.human_readable.json | 42 +++++----- .../description.001.normalized.json | 44 +++++------ doc/ReferenceOfClasses.md | 42 +++++----- src/github/Organization.py | 24 +++++- test/IntegrationTest.py | 1 + test/Organization.py | 78 +++++++++++++++++++ test/ReplayData/Organization.setUp.txt | 5 ++ .../Organization.testEditWithoutArguments.txt | 5 ++ 8 files changed, 176 insertions(+), 65 deletions(-) create mode 100644 test/Organization.py create mode 100644 test/ReplayData/Organization.setUp.txt create mode 100644 test/ReplayData/Organization.testEditWithoutArguments.txt diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json index 6f256a60..751654cc 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.000.human_readable.json @@ -955,30 +955,30 @@ ] }, "attributes": [ - { "name": "avatar_url", "type": "@todo" }, - { "name": "billing_email", "type": "@todo" }, - { "name": "blog", "type": "@todo" }, - { "name": "collaborators", "type": "@todo" }, - { "name": "company", "type": "@todo" }, - { "name": "created_at", "type": "@todo" }, - { "name": "disk_usage", "type": "@todo" }, - { "name": "email", "type": "@todo" }, - { "name": "followers", "type": "@todo" }, - { "name": "following", "type": "@todo" }, - { "name": "gravatar_id", "type": "@todo" }, - { "name": "html_url", "type": "@todo" }, - { "name": "id", "type": "@todo" }, + { "name": "avatar_url", "type": "string" }, + { "name": "billing_email", "type": "string" }, + { "name": "blog", "type": "string" }, + { "name": "collaborators", "type": "integer" }, + { "name": "company", "type": "string" }, + { "name": "created_at", "type": "string" }, + { "name": "disk_usage", "type": "integer" }, + { "name": "email", "type": "string" }, + { "name": "followers", "type": "integer" }, + { "name": "following", "type": "integer" }, + { "name": "gravatar_id", "type": "string" }, + { "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" } ], "collections": [ { diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json index c58d8c5c..699cabbe 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.001.normalized.json @@ -5217,7 +5217,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "avatar_url" }, @@ -5225,7 +5225,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "billing_email" }, @@ -5233,7 +5233,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "blog" }, @@ -5241,7 +5241,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "collaborators" }, @@ -5249,7 +5249,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "company" }, @@ -5257,7 +5257,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "created_at" }, @@ -5265,7 +5265,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "disk_usage" }, @@ -5273,7 +5273,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "email" }, @@ -5281,7 +5281,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "followers" }, @@ -5289,7 +5289,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "following" }, @@ -5297,7 +5297,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "gravatar_id" }, @@ -5305,7 +5305,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "html_url" }, @@ -5313,7 +5313,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "id" }, @@ -5345,15 +5345,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" }, @@ -5361,7 +5361,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "private_gists" }, @@ -5369,7 +5369,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "public_gists" }, @@ -5377,7 +5377,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "public_repos" }, @@ -5385,7 +5385,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "integer" }, "name": "total_private_repos" }, @@ -5393,7 +5393,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "type" }, @@ -5401,7 +5401,7 @@ "type": { "simple": true, "cardinality": "scalar", - "name": "@todo" + "name": "string" }, "name": "url" } diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index 6a1ce996..bf0586d7 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -704,30 +704,30 @@ Class `Organization` Attributes ---------- -* `avatar_url` -* `billing_email` -* `blog` -* `collaborators` -* `company` -* `created_at` -* `disk_usage` -* `email` -* `followers` -* `following` -* `gravatar_id` -* `html_url` -* `id` +* `avatar_url`: string +* `billing_email`: string +* `blog`: string +* `collaborators`: integer +* `company`: string +* `created_at`: string +* `disk_usage`: integer +* `email`: string +* `followers`: integer +* `following`: integer +* `gravatar_id`: string +* `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/Organization.py b/src/github/Organization.py index f83ff5ad..bdd1e1e0 100644 --- a/src/github/Organization.py +++ b/src/github/Organization.py @@ -3,6 +3,7 @@ import PaginatedList import Team +import Plan import Event import Repository import NamedUser @@ -382,30 +383,43 @@ class Organization( object ): def __useAttributes( self, attributes ): #@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 "billing_email" in attributes and attributes[ "billing_email" ] is not None: + assert isinstance( attributes[ "billing_email" ], ( str, unicode ) ) self.__billing_email = attributes[ "billing_email" ] 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 "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 "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 ) ) @@ -417,18 +431,26 @@ class Organization( 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" ], lazy = True ) 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 bd9e48ea..3a417b7c 100644 --- a/test/IntegrationTest.py +++ b/test/IntegrationTest.py @@ -5,5 +5,6 @@ import Framework from AuthenticatedUser import * from GitObjects import * from Repository import * +from Organization import * Framework.main() diff --git a/test/Organization.py b/test/Organization.py new file mode 100644 index 00000000..c9276c1b --- /dev/null +++ b/test/Organization.py @@ -0,0 +1,78 @@ +import Framework + +class Organization( Framework.TestCase ): + def setUp( self ): + Framework.TestCase.setUp( self ) + self.org = self.g.get_organization( "BeaverSoftware" ) + + def testAttributes( self ): + self.assertEqual( self.org.avatar_url, "https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png" ) + self.assertEqual( self.org.billing_email, "BeaverSoftware@vincent-jacques.net" ) + self.assertEqual( self.org.blog, None ) + self.assertEqual( self.org.collaborators, 0 ) + self.assertEqual( self.org.company, None ) + self.assertEqual( self.org.created_at, "2012-02-09T19:20:12Z" ) + self.assertEqual( self.org.disk_usage, 112 ) + self.assertEqual( self.org.email, None ) + self.assertEqual( self.org.followers, 0 ) + self.assertEqual( self.org.following, 0 ) + self.assertEqual( self.org.gravatar_id, None ) + self.assertEqual( self.org.html_url, "https://github.com/BeaverSoftware" ) + self.assertEqual( self.org.id, 1424031 ) + self.assertEqual( self.org.location, "Paris, France" ) + self.assertEqual( self.org.login, "BeaverSoftware" ) + self.assertEqual( self.org.name, None ) + self.assertEqual( self.org.owned_private_repos, 0 ) + self.assertEqual( self.org.plan.name, "free" ) + self.assertEqual( self.org.plan.private_repos, 0 ) + self.assertEqual( self.org.plan.space, 307200 ) + self.assertEqual( self.org.private_gists, 0 ) + self.assertEqual( self.org.public_gists, 0 ) + self.assertEqual( self.org.public_repos, 2 ) + self.assertEqual( self.org.total_private_repos, 0 ) + self.assertEqual( self.org.type, "Organization" ) + self.assertEqual( self.org.url, "https://api.github.com/orgs/BeaverSoftware" ) + + def testEditWithoutArguments( self ): + self.org.edit() + + def testEditWithAllArguments( self ): + # oldName = self.org.name + # newName = "Name edited by PyGithub" + + # oldEmail = self.org.email + # newEmail = "Email edited by PyGithub" + + # oldBlog = self.org.blog + # newBlog = "Blog edited by PyGithub" + + # oldCompany = self.org.company + # newCompany = "Company edited by PyGithub" + + # oldLocation = self.org.location + # newLocation = "Location edited by PyGithub" + + # oldHireable = self.org.hireable + # newHireable = not oldHireable + + # oldBio = self.org.bio + # newBio = "Bio edited by PyGithub" + + # self.org.edit( newName, newEmail, newBlog, newCompany, newLocation, newHireable, newBio ) + # self.assertEqual( self.org.name, newName ) + # self.assertEqual( self.org.email, newEmail ) + # self.assertEqual( self.org.blog, newBlog ) + # self.assertEqual( self.org.company, newCompany ) + # self.assertEqual( self.org.location, newLocation ) + # self.assertEqual( self.org.hireable, newHireable ) + # self.assertEqual( self.org.bio, newBio ) + + # self.org.edit( oldName, oldEmail, oldBlog, oldCompany, oldLocation, oldHireable, oldBio ) + # self.assertEqual( self.org.name, oldName ) + # self.assertEqual( self.org.email, oldEmail ) + # self.assertEqual( self.org.blog, oldBlog ) + # self.assertEqual( self.org.company, oldCompany ) + # self.assertEqual( self.org.location, oldLocation ) + # self.assertEqual( self.org.hireable, oldHireable ) + # self.assertEqual( self.org.bio, oldBio ) + pass diff --git a/test/ReplayData/Organization.setUp.txt b/test/ReplayData/Organization.setUp.txt new file mode 100644 index 00000000..1f13a67a --- /dev/null +++ b/test/ReplayData/Organization.setUp.txt @@ -0,0 +1,5 @@ +GET /orgs/BeaverSoftware {} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4997'), ('content-length', '716'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"bd349122929faf5f9be3e53d9ad41d08"'), ('date', 'Fri, 11 May 2012 09:07:56 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"type":"Organization","url":"https://api.github.com/orgs/BeaverSoftware","billing_email":"BeaverSoftware@vincent-jacques.net","disk_usage":112,"plan":{"private_repos":0,"space":307200,"name":"free"},"html_url":"https://github.com/BeaverSoftware","blog":null,"login":"BeaverSoftware","public_gists":0,"email":null,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","total_private_repos":0,"private_gists":0,"collaborators":0,"created_at":"2012-02-09T19:20:12Z","company":null,"location":"Paris, France","followers":0,"following":0,"name":null,"owned_private_repos":0,"id":1424031,"public_repos":2} + diff --git a/test/ReplayData/Organization.testEditWithoutArguments.txt b/test/ReplayData/Organization.testEditWithoutArguments.txt new file mode 100644 index 00000000..6c8a2a77 --- /dev/null +++ b/test/ReplayData/Organization.testEditWithoutArguments.txt @@ -0,0 +1,5 @@ +PATCH /orgs/BeaverSoftware {} {} +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4996'), ('content-length', '716'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"a9ca2dd89f69da85bebd949477894af0"'), ('date', 'Fri, 11 May 2012 09:07:56 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"owned_private_repos":0,"private_gists":0,"type":"Organization","following":0,"company":null,"html_url":"https://github.com/BeaverSoftware","blog":null,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","followers":0,"url":"https://api.github.com/orgs/BeaverSoftware","public_repos":2,"login":"BeaverSoftware","collaborators":0,"email":null,"disk_usage":112,"plan":{"private_repos":0,"space":307200,"name":"free"},"created_at":"2012-02-09T19:20:12Z","name":null,"total_private_repos":0,"billing_email":"BeaverSoftware@vincent-jacques.net","public_gists":0,"id":1424031,"location":"Paris, France"} +