Skip to content

Commit b289022

Browse files
committed
Added converters test
1 parent c205c27 commit b289022

File tree

4 files changed

+92
-101
lines changed

4 files changed

+92
-101
lines changed

github3/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def _last_page(self, link):
2929

3030
return self.last
3131

32-
# TODO: reset iterators... multiple?
3332
def __iter__(self):
3433
return self
3534

github3/handlers/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ def _get_resources(self, resource, model=None, limit=None, **kwargs):
5353
""" Hander request to multiple resources """
5454

5555
resource = self._prefix_resource(resource)
56-
page_resources = Paginate(resource, self._gh.get, **kwargs)
5756
counter = 1
58-
for page in page_resources:
57+
for page in Paginate(resource, self._gh.get, **kwargs):
5958
for raw_resource in page:
6059
if limit and counter > limit: break
6160
counter += 1

github3/tests/gist_tests.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

github3/tests/test_converters.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from github3.converters import *
5+
from github3.models.base import BaseResource
6+
from unittest import TestCase
7+
from datetime import datetime
8+
9+
API_STUB = {
10+
'test_str': 'string', 'test_int': 1,
11+
'test_date': '2008-01-14T04:33:35Z', 'test_bool': True,
12+
'map': {'test_str': 'string'},
13+
'dict_map': {
14+
'map1': {
15+
'test_str': 'string',
16+
'test_int': 1
17+
},
18+
'map2': {
19+
'test_str': 'string',
20+
'test_int': 2
21+
},
22+
},
23+
'list_map': [
24+
{'test_str': 'string', 'test_int': 1},
25+
{'test_str': 'string', 'test_int': 2},
26+
]
27+
}
28+
29+
30+
class Model(BaseResource):
31+
32+
@classmethod
33+
def idl(self):
34+
return {
35+
'strs': ['test_str'],
36+
'ints': ['test_int'],
37+
'dates': ['test_date'],
38+
'bools': ['test_bool'],
39+
'maps': {'map': Model},
40+
'collection_maps': {
41+
'dict_map': Model,
42+
'list_map': Model,
43+
},
44+
}
45+
46+
47+
class TestModelizer(TestCase):
48+
49+
def setUp(self):
50+
model = Model
51+
self.modelizer = Modelizer()
52+
self.modelizer.inject(model)
53+
54+
def test_loads(self):
55+
parsed_model = self.modelizer.loads(API_STUB)
56+
self.assertEquals(parsed_model.test_str, 'string')
57+
self.assertEquals(parsed_model.test_int, 1)
58+
self.assertEquals(
59+
parsed_model.test_date,
60+
datetime(2008, 1, 14, 4, 33, 35))
61+
self.assertTrue(parsed_model.test_bool)
62+
self.assertTrue(isinstance(parsed_model.map, Model))
63+
self.assertEquals(parsed_model.map.test_str, 'string')
64+
self.assertTrue(isinstance(parsed_model.dict_map, dict))
65+
map1 = parsed_model.dict_map['map1']
66+
map2 = parsed_model.dict_map['map2']
67+
self.assertTrue(isinstance(map1, Model))
68+
self.assertTrue(isinstance(map2, Model))
69+
self.assertEquals(map1.test_str, 'string')
70+
self.assertEquals(map1.test_int, 1)
71+
self.assertEquals(map2.test_str, 'string')
72+
self.assertEquals(map2.test_int, 2)
73+
74+
list_map = parsed_model.list_map
75+
self.assertTrue(isinstance(list_map, list))
76+
self.assertEquals(list_map[0].test_str, 'string')
77+
self.assertEquals(list_map[0].test_int, 1)
78+
self.assertEquals(list_map[1].test_str, 'string')
79+
self.assertEquals(list_map[1].test_int, 2)
80+
81+
82+
class TestRawlizer(TestCase):
83+
84+
def setUp(self):
85+
model = Model
86+
self.rawlizer = Rawlizer()
87+
88+
# Trivial, I know it
89+
def test_loads(self):
90+
raw = self.rawlizer.loads(API_STUB)
91+
self.assertEquals(raw, API_STUB)

0 commit comments

Comments
 (0)