aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/tests/resources/test_core.py
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-02-10 00:59:01 +0100
committerDavid Medina <davidmedina9@gmail.com>2012-02-10 00:59:01 +0100
commit46d535027b5247a9f1b242b4944e2ee8d65b4fad (patch)
treef303b79c167c3b94ab741594e93e5603a5dadfb6 /pygithub3/tests/resources/test_core.py
parentjson:dumps.loads mocked (diff)
downloadpython-github3-46d535027b5247a9f1b242b4944e2ee8d65b4fad.tar.xz
python-github3-46d535027b5247a9f1b242b4944e2ee8d65b4fad.zip
Resources tests
resources.core * Also detected and fixed memory bug
Diffstat (limited to 'pygithub3/tests/resources/test_core.py')
-rw-r--r--pygithub3/tests/resources/test_core.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/pygithub3/tests/resources/test_core.py b/pygithub3/tests/resources/test_core.py
new file mode 100644
index 0000000..276c92f
--- /dev/null
+++ b/pygithub3/tests/resources/test_core.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from unittest import TestCase
+from datetime import datetime
+
+from pygithub3.resources.base import Resource, Raw, json
+from pygithub3.tests.utils.resources import Nested, Simple, HasSimple
+
+simple_resource = dict(type='simple')
+has_simple = dict(type='has_simple', simple=simple_resource)
+github_return = dict(
+ id=1,
+ name='name_test',
+ date='2008-01-14T04:33:35Z',
+ simple=simple_resource,
+ list_collection=[has_simple] * 2,
+ items_collections=dict(arg1=has_simple, arg2=has_simple)
+ )
+
+
+class TestResourceMapping(TestCase):
+
+ def setUp(self):
+ self.r = Nested.loads(github_return)
+
+ def test_attrs_map(self):
+ self.assertEqual(self.r.id, 1)
+ self.assertEqual(self.r.name, 'name_test')
+ self.assertEqual(self.r.date, datetime(2008, 1, 14, 4, 33, 35))
+
+ def test_MAPS(self):
+ self.assertIsInstance(self.r.simple, Simple)
+ self.assertEqual(self.r.simple.type, 'simple')
+
+ def test_LIST_collection_map(self):
+ has_simple_objects = filter(lambda x: isinstance(x, HasSimple),
+ self.r.list_collection)
+ self.assertEqual(len(has_simple_objects), 2)
+ self.assertEqual(self.r.list_collection[0].type, 'has_simple')
+ self.assertEqual(self.r.list_collection[0].simple.type, 'simple')
+
+ def test_DICT_collection_map(self):
+ arg1_has_simple = self.r.items_collections['arg1']
+ self.assertEqual(arg1_has_simple.type, 'has_simple')
+ self.assertEqual(arg1_has_simple.simple.type, 'simple')
+
+
+class TestRawResource(TestCase):
+ """ Litle obvious :P """
+
+ def test_return_original_copy(self):
+ self.r = Raw.loads(github_return)
+ self.assertEqual(id(self.r), id(github_return))