diff options
Diffstat (limited to 'pygithub3')
-rw-r--r-- | pygithub3/resources/base.py | 11 | ||||
-rw-r--r-- | pygithub3/tests/resources/test_core.py | 7 | ||||
-rw-r--r-- | pygithub3/tests/utils/resources.py | 4 |
3 files changed, 19 insertions, 3 deletions
diff --git a/pygithub3/resources/base.py b/pygithub3/resources/base.py index 183c9eb..255f4c1 100644 --- a/pygithub3/resources/base.py +++ b/pygithub3/resources/base.py @@ -39,6 +39,13 @@ class Resource(object): @classmethod def __load(self, raw_resource): + def self_resource(func): + def wrapper(resource, raw_resource): + if resource == 'self': + resource = self + return func(resource, raw_resource) + return wrapper + def parse_date(string_date): from datetime import datetime try: @@ -47,12 +54,12 @@ class Resource(object): date = None return date + @self_resource def parse_map(resource, raw_resource): - if resource == 'self': - return self.__load(raw_resource) if hasattr(raw_resource, 'items'): return resource.__load(raw_resource) + @self_resource def parse_collection_map(resource, raw_resources): # Dict of resources (Ex: Gist file) if hasattr(raw_resources, 'items'): diff --git a/pygithub3/tests/resources/test_core.py b/pygithub3/tests/resources/test_core.py index 1422667..9c05e2b 100644 --- a/pygithub3/tests/resources/test_core.py +++ b/pygithub3/tests/resources/test_core.py @@ -19,6 +19,8 @@ github_return = dict( ) github_return_nested = github_return.copy() github_return.update({'self_nested': github_return_nested}) +github_return.update({'self_nested_list': [github_return_nested] * 2}) +github_return.update({'self_nested_dict': dict(arg1=github_return_nested)}) class TestResourceMapping(TestCase): @@ -53,6 +55,11 @@ class TestResourceMapping(TestCase): self.assertIsInstance(self.r.list_collection[0], HasSimple) self.assertIsInstance(self.r.items_collections['arg1'], HasSimple) + def test_SELF_nested_in_collections(self): + self.assertIsInstance(self.r.self_nested_list[0], Nested) + self.assertIsInstance(self.r.self_nested_dict['arg1'], Nested) + + class TestRawResource(TestCase): """ Litle obvious :P """ diff --git a/pygithub3/tests/utils/resources.py b/pygithub3/tests/utils/resources.py index e03d47d..46a9d53 100644 --- a/pygithub3/tests/utils/resources.py +++ b/pygithub3/tests/utils/resources.py @@ -17,5 +17,7 @@ class Nested(Resource): _maps = {'simple': Simple, 'self_nested': 'self'} _collection_maps = { 'list_collection': HasSimple, - 'items_collections': HasSimple + 'items_collections': HasSimple, + 'self_nested_list': 'self', + 'self_nested_dict': 'self', } |