mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 11:21:16 +00:00
Add a way to create an object from raw data (Issue #144)
This commit is contained in:
@@ -278,3 +278,12 @@ class Github(object):
|
||||
None
|
||||
)
|
||||
return GitignoreTemplate.GitignoreTemplate(self.__requester, attributes, completed=True)
|
||||
|
||||
def create_from_raw_data(self, klass, raw_data):
|
||||
"""
|
||||
Creates an object from raw_data previously obtained by myObject.raw_data
|
||||
:param klass: the class of the object to create
|
||||
:param raw_data: dict
|
||||
:rtype: instance of class ``klass``
|
||||
"""
|
||||
return klass(self.__requester, raw_data, completed=True)
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
import Framework
|
||||
|
||||
import github.NamedUser
|
||||
|
||||
class RawData(Framework.TestCase):
|
||||
jacquev6RawData = {
|
||||
u'disk_usage': 13812,
|
||||
@@ -80,3 +82,8 @@ class RawData(Framework.TestCase):
|
||||
def testNonCompletableObject(self):
|
||||
plan = self.g.get_user().plan
|
||||
self.assertEqual(plan.raw_data, RawData.planRawData)
|
||||
|
||||
def testCreateObjectFromRawData(self):
|
||||
user = self.g.create_from_raw_data(github.NamedUser.NamedUser, RawData.jacquev6RawData)
|
||||
self.assertEqual(user._CompletableGithubObject__completed, True)
|
||||
self.assertEqual(user.name, "Vincent Jacques")
|
||||
|
||||
Reference in New Issue
Block a user