Skip to content

Commit

Permalink
Add a way to create an object from raw data (Issue #144)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquev6 committed Mar 14, 2013
1 parent fa43e95 commit 3af543a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions github/MainClass.py
Expand Up @@ -278,3 +278,12 @@ def get_gitignore_template(self, name):
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)
7 changes: 7 additions & 0 deletions github/tests/RawData.py
Expand Up @@ -15,6 +15,8 @@

import Framework

import github.NamedUser

class RawData(Framework.TestCase):
jacquev6RawData = {
u'disk_usage': 13812,
Expand Down Expand Up @@ -80,3 +82,8 @@ def testNotYetCompletedObject(self):
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")

0 comments on commit 3af543a

Please sign in to comment.