diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 03cba3fd..676bc5de 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -6,11 +6,11 @@ from GithubObject import * class GithubObjectTestCase( unittest.TestCase ): def testDuplicatedAttributeInOnePolicy( self ): with self.assertRaises( BadGithubObjectException ): - GithubObject( "", BasicAttributes( "a", "a" ) ) + GithubObject( "", InternalSimpleAttributes( "a", "a" ) ) def testDuplicatedAttributeInTwoPolicies( self ): with self.assertRaises( BadGithubObjectException ): - GithubObject( "", BasicAttributes( "a" ), BasicAttributes( "a" ) ) + GithubObject( "", InternalSimpleAttributes( "a" ), InternalSimpleAttributes( "a" ) ) class TestCaseWithGithubTestObject( unittest.TestCase ): def setUp( self ): @@ -43,11 +43,11 @@ class TestCaseWithGithubTestObject( unittest.TestCase ): def expectStatusDelete( self, url ): return self.g.expect._statusRequest( "DELETE", url, None, None ) -class GithubObjectWithOnlyBasicAttributes( TestCaseWithGithubTestObject ): +class GithubObjectWithOnlyInternalSimpleAttributes( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2", "a3", "a4" ) + InternalSimpleAttributes( "a1", "a2", "a3", "a4" ) ) def testInterface( self ): @@ -84,7 +84,7 @@ class GithubObjectWithOtherBaseUrl( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/other/" + str( obj.a1 ) ), - BasicAttributes( "a1", "a2", "a3", "a4" ) + InternalSimpleAttributes( "a1", "a2", "a3", "a4" ) ) def testCompletion( self ): @@ -95,7 +95,7 @@ class EditableGithubObject( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2", "a3", "a4" ), + InternalSimpleAttributes( "a1", "a2", "a3", "a4" ), Editable( [ "a1" ], [ "a2", "a4" ] ), ) @@ -168,7 +168,7 @@ class DeletableGithubObject( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2", "a3", "a4" ), + InternalSimpleAttributes( "a1", "a2", "a3", "a4" ), Deletable(), ) @@ -176,18 +176,18 @@ class DeletableGithubObject( TestCaseWithGithubTestObject ): self.expectStatusDelete( "/test" ).andReturn( 204 ) self.o.delete() -class GithubObjectWithComplexAttribute( TestCaseWithGithubTestObject ): +class GithubObjectWithInternalObjectAttribute( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - BasicAttributes( "id", "name", "desc" ) + InternalSimpleAttributes( "id", "name", "desc" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), - ComplexAttribute( "a3", ContainedObject ) + InternalSimpleAttributes( "a1", "a2" ), + InternalObjectAttribute( "a3", ContainedObject ) ) def testCompletion( self ): @@ -205,13 +205,13 @@ class GithubObjectWithListGetableList( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ListGetable( [], [ "type" ] ) ) ) @@ -233,13 +233,13 @@ class GithubObjectWithElementAddableList( TestCaseWithGithubTestObject ): "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - BasicAttributes( "id", "name" ), + InternalSimpleAttributes( "id", "name" ), ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ElementAddable() ) ) @@ -253,13 +253,13 @@ class GithubObjectWithElementRemovableList( TestCaseWithGithubTestObject ): "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - BasicAttributes( "id", "name" ), + InternalSimpleAttributes( "id", "name" ), ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ElementRemovable() ) ) @@ -273,13 +273,13 @@ class GithubObjectWithElementHasableList( TestCaseWithGithubTestObject ): "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - BasicAttributes( "id", "name" ), + InternalSimpleAttributes( "id", "name" ), ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ElementHasable() ) ) @@ -295,13 +295,13 @@ class GithubObjectWithElementCreatableList( TestCaseWithGithubTestObject ): "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - BasicAttributes( "id", "name" ), + InternalSimpleAttributes( "id", "name" ), ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ElementCreatable( "a3", [ "name" ], [ "p1", "p2" ] ) ) ) @@ -334,13 +334,13 @@ class GithubObjectWithListAddableList( TestCaseWithGithubTestObject ): "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ListAddable() ) ) @@ -353,13 +353,13 @@ class GithubObjectWithListSetableList( TestCaseWithGithubTestObject ): "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ListSetable() ) ) @@ -371,13 +371,13 @@ class GithubObjectWithListDeletableList( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ListDeletable() ) ) @@ -389,13 +389,13 @@ class GithubObjectWithElementGetableList( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ListAttribute( "a3s", ContainedObject, ElementGetable( "a3", lambda obj, id: { "id": id } ) ) ) @@ -407,13 +407,13 @@ class GithubObjectWithObjectGetter( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), ObjectGetter( "a3", ContainedObject, lambda obj, id : { "id": id } ) ) @@ -428,7 +428,7 @@ class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a1", "a2" ), + InternalSimpleAttributes( "a1", "a2" ), MethodFromCallable( "myMethod", myCallable ) ) @@ -438,19 +438,19 @@ class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ): self.assertEqual( self.o.myMethod( mock.object, 42 ), 72 ) mock.tearDown() -class GithubObjectWithSeveralBasicAttributesAndComplexAttributes( TestCaseWithGithubTestObject ): +class GithubObjectWithSeveralInternalSimpleAttributesAndInternalObjectAttributes( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - BasicAttributes( "id", "name" ) + InternalSimpleAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - BasicAttributes( "a2", "a4" ), - BasicAttributes( "a1", "a3" ), - ComplexAttribute( "a5", ContainedObject ), + InternalSimpleAttributes( "a2", "a4" ), + InternalSimpleAttributes( "a1", "a3" ), + InternalObjectAttribute( "a5", ContainedObject ), ) def testCompletionInOneCall_1( self ): diff --git a/github/GithubObject.py b/github/GithubObject.py index d54a22a6..9142ad1a 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -11,7 +11,7 @@ class SimpleTypePolicy: def create( self, obj, rawValue ): return rawValue -class GithubObjectTypePolicy: +class ObjectTypePolicy: def __init__( self, type ): self.__type = type @@ -52,14 +52,14 @@ class SeveralAttributes: for attributePolicy in self.__attributePolicies: attributePolicy.apply( cls ) -def BasicAttribute( attributeName ): +def InternalSimpleAttribute( attributeName ): return InternalAttribute( attributeName, SimpleTypePolicy() ) -def BasicAttributes( *attributeNames ): - return SeveralAttributes( [ BasicAttribute( attributeName ) for attributeName in attributeNames ] ) +def InternalSimpleAttributes( *attributeNames ): + return SeveralAttributes( [ InternalSimpleAttribute( attributeName ) for attributeName in attributeNames ] ) -def ComplexAttribute( attributeName, type ): - return InternalAttribute( attributeName, GithubObjectTypePolicy( type ) ) +def InternalObjectAttribute( attributeName, type ): + return InternalAttribute( attributeName, ObjectTypePolicy( type ) ) class BaseUrl( AttributeFromCallable ): def __init__( self, baseUrl ): diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 9ec6f746..03cb6109 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -7,7 +7,7 @@ AuthenticatedUser = GithubObject( "AuthenticatedUser", BaseUrl( lambda obj: "/user" ), Identity( lambda obj: obj.login ), - BasicAttributes( + InternalSimpleAttributes( "login", "id", "avatar_url", "gravatar_id", "url", "name", "company", "blog", "location", "email", "hireable", "bio", "public_repos", "public_gists", "followers", "following", "html_url", "created_at", @@ -21,7 +21,7 @@ NamedUser = GithubObject( "NamedUser", BaseUrl( lambda obj: "/users/" + obj.login ), Identity( lambda obj: obj.login ), - BasicAttributes( + InternalSimpleAttributes( "login", "id", "avatar_url", "gravatar_id", "url", "name", "company", "blog", "location", "email", "hireable", "bio", "public_repos", "public_gists", "followers", "following", "html_url", "created_at", @@ -44,7 +44,7 @@ Organization = GithubObject( "Organization", BaseUrl( lambda obj: "/orgs/" + obj.login ), Identity( lambda obj: obj.login ), - BasicAttributes( + InternalSimpleAttributes( "login", "id", "url", "avatar_url", "name", "company", "blog", "location", "email", "public_repos", "public_gists", "followers", "following", "html_url", "created_at", "type", @@ -63,7 +63,7 @@ NamedUser._addAttributePolicy( ListAttribute( "orgs", Organization, ListGetable( GitRef = GithubObject( "GitRef", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/" + obj.ref ), - BasicAttributes( + InternalSimpleAttributes( "ref", "url", "object", ### @todo Structure "_repo", ### Ugly hack @@ -74,7 +74,7 @@ GitRef = GithubObject( GitCommit = GithubObject( "GitCommit", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/commits/" + obj.sha ), - BasicAttributes( + InternalSimpleAttributes( "sha", "url", "message", "author", ### @todo Structure "committer", ### @todo Structure @@ -87,7 +87,7 @@ GitCommit = GithubObject( GitTree = GithubObject( "GitTree", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/trees/" + obj.sha ), - BasicAttributes( + InternalSimpleAttributes( "sha", "url", "tree", ### @todo Structure "_repo", ### Ugly hack @@ -97,7 +97,7 @@ GitTree = GithubObject( GitBlob = GithubObject( "GitBlob", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/blobs/" + obj.sha ), - BasicAttributes( + InternalSimpleAttributes( "sha", "size", "url", "content", "encoding", "_repo", ### Ugly hack @@ -107,7 +107,7 @@ GitBlob = GithubObject( GitTag = GithubObject( "GitTag", BaseUrl( lambda obj: obj._repo._baseUrl + "/git/tags/" + obj.sha ), - BasicAttributes( + InternalSimpleAttributes( "tag", "sha", "url", "message", "tagger", ### @todo Structure @@ -120,7 +120,7 @@ Label = GithubObject( "Label", BaseUrl( lambda obj: obj._repo._baseUrl + "/labels/" + obj._identity ), Identity( lambda obj: urllib.quote( obj.name ) ), - BasicAttributes( + InternalSimpleAttributes( "url", "name", "color", "_repo", ### Ugly hack ), @@ -131,12 +131,12 @@ Label = GithubObject( Milestone = GithubObject( "Milestone", BaseUrl( lambda obj: obj._repo._baseUrl + "/milestones/" + str( obj.number ) ), - BasicAttributes( + InternalSimpleAttributes( "url", "number", "state", "title", "description", "open_issues", "closed_issues", "created_at", "due_on", "_repo", ### Ugly hack ), - ComplexAttribute( "creator", NamedUser ), + InternalObjectAttribute( "creator", NamedUser ), Editable( [ "title" ], [ "state", "description", "due_on" ] ), Deletable(), ListAttribute( "labels", Label, ListGetable( [], [], lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj._repo }.iteritems() ) ) ) ), @@ -145,11 +145,11 @@ Milestone = GithubObject( IssueComment = GithubObject( "IssueComment", BaseUrl( lambda obj: obj._repo._baseUrl + "/issues/comment" + str( obj.id ) ), - BasicAttributes( + InternalSimpleAttributes( "url", "body", "created_at", "updated_at", "id", "_repo", ### Ugly hack ), - ComplexAttribute( "user", NamedUser ), + InternalObjectAttribute( "user", NamedUser ), Editable( [ "body" ], [] ), Deletable(), ) @@ -157,15 +157,15 @@ IssueComment = GithubObject( Issue = GithubObject( "Issue", BaseUrl( lambda obj: obj._repo._baseUrl + "/issues/" + str( obj.number ) ), - BasicAttributes( + InternalSimpleAttributes( "url", "html_url", "number", "state", "title", "body", "labels", "comments", "closed_at", "created_at", "updated_at", "id", "closed_by", "pull_request", ### @todo Structure "_repo", ### Ugly hack ), - ComplexAttribute( "user", NamedUser ), - ComplexAttribute( "assignee", NamedUser ), - ComplexAttribute( "milestone", Milestone ), + InternalObjectAttribute( "user", NamedUser ), + InternalObjectAttribute( "assignee", NamedUser ), + InternalObjectAttribute( "milestone", Milestone ), Editable( [], [ "title", "body", "assignee", "state", "milestone", "labels" ] ), ListAttribute( "labels", Label, ListGetable( [], [], lambda obj, attributes: dict( itertools.chain( attributes.iteritems(), { "_repo": obj._repo }.iteritems() ) ) ), @@ -186,7 +186,7 @@ Repository = GithubObject( "Repository", BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ), Identity( lambda obj: obj.owner.login + "/" + obj.name ), - BasicAttributes( + InternalSimpleAttributes( "url", "html_url", "clone_url", "git_url", "ssh_url", "svn_url", "name", "description", "homepage", "language", "private", "fork", "forks", "watchers", "size", "master_branch", "open_issues", @@ -195,7 +195,7 @@ Repository = GithubObject( # Not documented "mirror_url", "updated_at", "id", ), - ComplexAttribute( "owner", NamedUser ), + InternalObjectAttribute( "owner", NamedUser ), ListAttribute( "collaborators", NamedUser, ListGetable( [], [] ), ElementAddable(), ElementRemovable(), ElementHasable() ), ListAttribute( "contributors", NamedUser, ListGetable( [], [] ) ), ListAttribute( "watchers", NamedUser, ListGetable( [], [] ) ), @@ -237,8 +237,8 @@ Repository = GithubObject( ElementCreatable( "issue", [ "title" ], [ "body", "assignee", "milestone", "labels", ], __modifyAttributesForObjectsReferingRepo ) ), ) -Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) ) -Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) ) +Repository._addAttributePolicy( InternalObjectAttribute( "parent", Repository ) ) +Repository._addAttributePolicy( InternalObjectAttribute( "source", Repository ) ) Repository._addAttributePolicy( ListAttribute( "forks", Repository, ListGetable( [], [] ) ) ) __repoElementCreatable = ElementCreatable( "repo", [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] ) @@ -264,7 +264,7 @@ Team = GithubObject( "Team", BaseUrl( lambda obj: "/teams/" + str( obj.id ) ), Identity( lambda obj: str( obj.id ) ), - BasicAttributes( + InternalSimpleAttributes( "url", "name", "id", "permission", "members_count", "repos_count", ), Editable( [ "name" ], [ "permission" ] ),