From 3af543a1fed27b3a39200da02a91ef2513f5482f Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Thu, 14 Mar 2013 12:32:46 +0100 Subject: [PATCH] Add a way to create an object from raw data (Issue #144) --- github/MainClass.py | 9 +++++++++ github/tests/RawData.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/github/MainClass.py b/github/MainClass.py index cf38e7a2..5760c3c9 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -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) diff --git a/github/tests/RawData.py b/github/tests/RawData.py index cd81dd35..53b8e470 100644 --- a/github/tests/RawData.py +++ b/github/tests/RawData.py @@ -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")