diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 05a503ed..06e47c82 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( "", SimpleScalarAttributes( "a", "a" ) ) + GithubObject( "", BasicAttributes( "a", "a" ) ) def testDuplicatedAttributeInTwoPolicies( self ): with self.assertRaises( BadGithubObjectException ): - GithubObject( "", SimpleScalarAttributes( "a" ), SimpleScalarAttributes( "a" ) ) + GithubObject( "", BasicAttributes( "a" ), BasicAttributes( "a" ) ) class TestCaseWithGithubTestObject( unittest.TestCase ): def setUp( self ): @@ -37,11 +37,11 @@ class TestCaseWithGithubTestObject( unittest.TestCase ): def expectStatusDelete( self, url ): return self.g.expect._statusRequest( "DELETE", url ) -class GithubObjectWithOnlySimpleScalarAttributes( TestCaseWithGithubTestObject ): +class GithubObjectWithOnlyBasicAttributes( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - SimpleScalarAttributes( "a1", "a2", "a3", "a4" ) + BasicAttributes( "a1", "a2", "a3", "a4" ) ) def testInterface( self ): @@ -78,7 +78,7 @@ class GithubObjectWithOtherBaseUrl( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/other/" + str( obj.a1 ) ), - SimpleScalarAttributes( "a1", "a2", "a3", "a4" ) + BasicAttributes( "a1", "a2", "a3", "a4" ) ) def testCompletion( self ): @@ -89,7 +89,7 @@ class EditableGithubObject( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - SimpleScalarAttributes( "a1", "a2", "a3", "a4" ), + BasicAttributes( "a1", "a2", "a3", "a4" ), Editable( [ "a1" ], [ "a2", "a4" ] ), ) @@ -154,7 +154,7 @@ class DeletableGithubObject( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - SimpleScalarAttributes( "a1", "a2", "a3", "a4" ), + BasicAttributes( "a1", "a2", "a3", "a4" ), Deletable(), ) @@ -162,18 +162,18 @@ class DeletableGithubObject( TestCaseWithGithubTestObject ): self.expectStatusDelete( "/test" ).andReturn( 204 ) self.o.delete() -class GithubObjectWithExtendedScalarAttribute( TestCaseWithGithubTestObject ): +class GithubObjectWithComplexAttribute( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - SimpleScalarAttributes( "id", "name", "desc" ) + BasicAttributes( "id", "name", "desc" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - SimpleScalarAttributes( "a1", "a2" ), - ExtendedScalarAttribute( "a3", ContainedObject ) + BasicAttributes( "a1", "a2" ), + ComplexAttribute( "a3", ContainedObject ) ) def testCompletion( self ): @@ -183,18 +183,18 @@ class GithubObjectWithExtendedScalarAttribute( TestCaseWithGithubTestObject ): self.expectDataGet( "/test/a3s/id1" ).andReturn( { "desc": "desc1" } ) self.assertEqual( self.o.a3.desc, "desc1" ) -class GithubObjectWithExtendedListAttribute( TestCaseWithGithubTestObject ): +class GithubObjectWithListOfReferences( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), - SimpleScalarAttributes( "id", "name" ) + BasicAttributes( "id", "name" ) ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - SimpleScalarAttributes( "a1", "a2" ), - ExtendedListAttribute( "a3s", ContainedObject ) + BasicAttributes( "a1", "a2" ), + ListOfReferences( "a3s", ContainedObject ) ) def testGetList( self ): @@ -205,19 +205,19 @@ class GithubObjectWithExtendedListAttribute( TestCaseWithGithubTestObject ): self.expectDataGet( "/test/a3s/id1" ).andReturn( { "name": "name1" } ) self.assertEqual( a3s[ 0 ].name, "name1" ) -class GithubObjectWithModifiableExtendedListAttribute( TestCaseWithGithubTestObject ): +class GithubObjectWithModifiableListOfReferences( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", BaseUrl( lambda obj: "/test/a3s/" + obj.id ), Identity( lambda obj: obj.id ), - SimpleScalarAttributes( "id", "name" ), + BasicAttributes( "id", "name" ), ) GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), - SimpleScalarAttributes( "a1", "a2" ), - ExtendedListAttribute( "a3s", ContainedObject, addable = True, removable = True, hasable = True ) + BasicAttributes( "a1", "a2" ), + ListOfReferences( "a3s", ContainedObject, addable = True, removable = True, hasable = True ) ) def testAddToList( self ): diff --git a/github/GithubObject.py b/github/GithubObject.py index 7cffff05..4f97f350 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -3,7 +3,7 @@ import itertools class BadGithubObjectException( Exception ): pass -class SimpleScalarAttributes: +class BasicAttributes: class AttributeDefinition: def __init__( self, attributeNames ): self.__attributeNames = attributeNames @@ -24,11 +24,11 @@ class SimpleScalarAttributes: self.__attributeNames = attributeNames def apply( self, cls ): - commonDefinition = SimpleScalarAttributes.AttributeDefinition( self.__attributeNames ) + commonDefinition = BasicAttributes.AttributeDefinition( self.__attributeNames ) for attributeName in self.__attributeNames: cls._addAttribute( attributeName, commonDefinition ) -class ExtendedListAttribute: +class ListOfReferences: def __init__( self, attributeName, type, addable = False, removable = False, hasable = False ): self.__attributeName = attributeName self.__type = type @@ -73,7 +73,7 @@ class ExtendedListAttribute: for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName ) ] -class ExtendedScalarAttribute: +class ComplexAttribute: class AttributeDefinition: def __init__( self, attributeName, type ): self.__attributeName = attributeName @@ -94,7 +94,7 @@ class ExtendedScalarAttribute: self.__type = type def apply( self, cls ): - cls._addAttribute( self.__attributeName, ExtendedScalarAttribute.AttributeDefinition( self.__attributeName, self.__type ) ) + cls._addAttribute( self.__attributeName, ComplexAttribute.AttributeDefinition( self.__attributeName, self.__type ) ) class Editable: def __init__( self, mandatoryParameters, optionalParameters ): diff --git a/github/GithubObjects.py b/github/GithubObjects.py index e54ffd56..a4a84ccd 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -4,7 +4,7 @@ AuthenticatedUser = GithubObject( "AuthenticatedUser", BaseUrl( lambda obj: "/user" ), Identity( lambda obj: obj.login ), - SimpleScalarAttributes( + BasicAttributes( "login", "id", "avatar_url", "gravatar_id", "url", "name", "company", "blog", "location", "email", "hireable", "bio", "public_repos", "public_gists", "followers", "following", "html_url", "created_at", @@ -18,7 +18,7 @@ NamedUser = GithubObject( "NamedUser", BaseUrl( lambda obj: "/users/" + obj.login ), Identity( lambda obj: obj.login ), - SimpleScalarAttributes( + BasicAttributes( "login", "id", "avatar_url", "gravatar_id", "url", "name", "company", "blog", "location", "email", "hireable", "bio", "public_repos", "public_gists", "followers", "following", "html_url", "created_at", @@ -28,17 +28,17 @@ NamedUser = GithubObject( ), ) -AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "followers", NamedUser ) ) -NamedUser._addAttributePolicy( ExtendedListAttribute( "followers", NamedUser ) ) +AuthenticatedUser._addAttributePolicy( ListOfReferences( "followers", NamedUser ) ) +NamedUser._addAttributePolicy( ListOfReferences( "followers", NamedUser ) ) -AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "following", NamedUser, addable = True, removable = True, hasable = True ) ) -NamedUser._addAttributePolicy( ExtendedListAttribute( "following", NamedUser ) ) +AuthenticatedUser._addAttributePolicy( ListOfReferences( "following", NamedUser, addable = True, removable = True, hasable = True ) ) +NamedUser._addAttributePolicy( ListOfReferences( "following", NamedUser ) ) Organization = GithubObject( "Organization", BaseUrl( lambda obj: "/orgs/" + obj.login ), Identity( lambda obj: obj.login ), - SimpleScalarAttributes( + BasicAttributes( "login", "id", "url", "avatar_url", "name", "company", "blog", "location", "email", "public_repos", "public_gists", "followers", "following", "html_url", "created_at", "type", @@ -46,19 +46,19 @@ Organization = GithubObject( "disk_usage", "collaborators", "billing_email", "plan", "private_gists", "total_private_repos", "owned_private_repos", ), - ExtendedListAttribute( "public_members", NamedUser, addable = True, removable = True, hasable = True ), - ExtendedListAttribute( "members", NamedUser, removable = True, hasable = True ), + ListOfReferences( "public_members", NamedUser, addable = True, removable = True, hasable = True ), + ListOfReferences( "members", NamedUser, removable = True, hasable = True ), Editable( [], [ "billing_email", "blog", "company", "email", "location", "name" ] ), ) -AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "orgs", Organization ) ) -NamedUser._addAttributePolicy( ExtendedListAttribute( "orgs", Organization ) ) +AuthenticatedUser._addAttributePolicy( ListOfReferences( "orgs", Organization ) ) +NamedUser._addAttributePolicy( ListOfReferences( "orgs", Organization ) ) Repository = GithubObject( "Repository", BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ), Identity( lambda obj: obj.owner.login + "/" + obj.name ), - SimpleScalarAttributes( + BasicAttributes( "url", "html_url", "clone_url", "git_url", "ssh_url", "svn_url", "name", "description", "homepage", "language", "private", "fork", "forks", "watchers", "size", "master_branch", "open_issues", @@ -67,19 +67,19 @@ Repository = GithubObject( # Not documented "mirror_url", "updated_at", "id", ), - ExtendedScalarAttribute( "owner", NamedUser ), - ExtendedListAttribute( "collaborators", NamedUser, addable = True, removable = True, hasable = True ), - ExtendedListAttribute( "contributors", NamedUser ), - ExtendedListAttribute( "watchers", NamedUser ), + ComplexAttribute( "owner", NamedUser ), + ListOfReferences( "collaborators", NamedUser, addable = True, removable = True, hasable = True ), + ListOfReferences( "contributors", NamedUser ), + ListOfReferences( "watchers", NamedUser ), Editable( [ "name" ], [ "description", "homepage", "public", "has_issues", "has_wiki", "has_downloads" ] ), ) -Repository._addAttributePolicy( ExtendedScalarAttribute( "parent", Repository ) ) -Repository._addAttributePolicy( ExtendedScalarAttribute( "source", Repository ) ) -Repository._addAttributePolicy( ExtendedListAttribute( "forks", Repository ) ) +Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) ) +Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) ) +Repository._addAttributePolicy( ListOfReferences( "forks", Repository ) ) -AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "repos", Repository ) ) -NamedUser._addAttributePolicy( ExtendedListAttribute( "repos", Repository ) ) -Organization._addAttributePolicy( ExtendedListAttribute( "repos", Repository ) ) +AuthenticatedUser._addAttributePolicy( ListOfReferences( "repos", Repository ) ) +NamedUser._addAttributePolicy( ListOfReferences( "repos", Repository ) ) +Organization._addAttributePolicy( ListOfReferences( "repos", Repository ) ) -AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "watched", Repository, addable = True, removable = True, hasable = True ) ) -NamedUser._addAttributePolicy( ExtendedListAttribute( "watched", Repository ) ) +AuthenticatedUser._addAttributePolicy( ListOfReferences( "watched", Repository, addable = True, removable = True, hasable = True ) ) +NamedUser._addAttributePolicy( ListOfReferences( "watched", Repository ) )