aboutsummaryrefslogtreecommitdiffstats
path: root/github3
diff options
context:
space:
mode:
Diffstat (limited to 'github3')
-rw-r--r--github3/converters.py12
-rw-r--r--github3/models/base.py3
-rw-r--r--github3/models/user.py13
-rw-r--r--github3/tests/converters_test.py7
-rw-r--r--github3/tests/fixtures.py9
5 files changed, 32 insertions, 12 deletions
diff --git a/github3/converters.py b/github3/converters.py
index 05e3435..58eb6b5 100644
--- a/github3/converters.py
+++ b/github3/converters.py
@@ -75,24 +75,24 @@ class Modelizer(Converter):
idl = self.model.idl()
attrs.update(
{attr: raw_resource[attr] for attr in idl.get('strs',())
- if raw_resource.get(attr)})
+ if attr in raw_resource})
attrs.update(
{attr: raw_resource[attr] for attr in idl.get('ints',())
- if raw_resource.get(attr)})
+ if attr in raw_resource})
attrs.update(
{attr: self._parse_date(raw_resource[attr])
- for attr in idl.get('dates',()) if raw_resource.get(attr)})
+ for attr in idl.get('dates',()) if attr in raw_resource})
attrs.update(
{attr: raw_resource[attr] for attr in idl.get('bools',())
- if raw_resource.get(attr)})
+ if attr in raw_resource})
attrs.update(
{attr: self._parse_map(model, raw_resource[attr])
for attr, model in idl.get('maps',{}).items()
- if raw_resource.get(attr)})
+ if attr in raw_resource})
attrs.update(
{attr: self._parse_collection_map(model, raw_resource[attr])
for attr, model in idl.get('collection_maps',{}).items()
- if raw_resource.get(attr)})
+ if attr in raw_resource})
return self.model(attrs)
diff --git a/github3/models/base.py b/github3/models/base.py
index df0c82b..bd07650 100644
--- a/github3/models/base.py
+++ b/github3/models/base.py
@@ -14,6 +14,9 @@ class BaseResource(object):
setattr(self, attr, value)
super(BaseResource, self).__init__()
+ def __len__(self):
+ return len(self.__dict__)
+
@classmethod
def idl(self):
raise NotImplementedError('Each model need subcass that method')
diff --git a/github3/models/user.py b/github3/models/user.py
index 7ec7999..e2d82b6 100644
--- a/github3/models/user.py
+++ b/github3/models/user.py
@@ -5,6 +5,7 @@
from .base import BaseResource
+
class Plan(BaseResource):
"""Github Plan object model."""
@@ -18,6 +19,7 @@ class Plan(BaseResource):
def __repr__(self):
return '<Plan %s>' % self.name
+
class Key(BaseResource):
"""Github Key object model."""
@@ -31,20 +33,23 @@ class Key(BaseResource):
def __repr__(self):
return '<Key %s>' % self.title
+
class User(BaseResource):
"""Github User object model."""
@classmethod
def idl(self):
return {
- 'strs': ['login','avatar_url', 'url', 'name', 'company', 'blog',
- 'location', 'email', 'bio', 'html_url', 'type'],
+ 'strs': [
+ 'login', 'avatar_url', 'gravatar_id', 'url', 'name',
+ 'company', 'blog', 'location', 'email', 'bio', 'html_url',
+ 'type'],
'ints': [
'id', 'public_repos', 'public_gists', 'followers', 'following',
'total_private_repos', 'owned_private_repos', 'private_gists',
'disk_usage', 'collaborators'],
'maps': {'plan': Plan},
- 'dates': ['created_at',],
+ 'dates': ['created_at', ],
'bools': ['hireable', ],
}
@@ -54,6 +59,7 @@ class User(BaseResource):
#def handler(self):
# return self._gh.user_handler(self.login, force=True)
+
class AuthUser(User):
"""Github Authenticated User object model."""
@@ -62,4 +68,3 @@ class AuthUser(User):
def __repr__(self):
return '<AuthUser %s>' % self.login
-
diff --git a/github3/tests/converters_test.py b/github3/tests/converters_test.py
index 315477c..66eedc3 100644
--- a/github3/tests/converters_test.py
+++ b/github3/tests/converters_test.py
@@ -7,8 +7,10 @@ from unittest import TestCase
from datetime import datetime
API_STUB = {
- 'test_str': 'string', 'test_int': 1,
- 'test_date': '2008-01-14T04:33:35Z', 'test_bool': True,
+ 'test_str': 'string',
+ 'test_int': 1,
+ 'test_date': '2008-01-14T04:33:35Z',
+ 'test_bool': True,
'map': {'test_str': 'string'},
'dict_map': {
'map1': {
@@ -55,6 +57,7 @@ class TestModelizer(TestCase):
def test_loads(self):
parsed_model = self.modelizer.loads(API_STUB)
+ self.assertEquals(len(parsed_model), len(API_STUB))
self.assertEquals(parsed_model.test_str, 'string')
self.assertEquals(parsed_model.test_int, 1)
self.assertEquals(
diff --git a/github3/tests/fixtures.py b/github3/tests/fixtures.py
index 469b00a..02086f8 100644
--- a/github3/tests/fixtures.py
+++ b/github3/tests/fixtures.py
@@ -5,6 +5,7 @@ GET_USER = {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat",
"name": "monalisa octocat",
"company": "GitHub",
@@ -24,24 +25,29 @@ GET_USER = {
GET_LINK = '<https://api.github.com/gists/public?page=2>; rel="next", \
<https://api.github.com/gists/public?page=5>; rel="last"'
+
GET_RESOURCES = [
{'login': 'octocat'},
{'login': 'octocat'}
]
+
GET_SHORT_USERS = [
{
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
{
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
]
+
GET_SHORT_ORGS = [
{
"login": "github",
@@ -63,6 +69,7 @@ GET_SHORT_REPOS = [
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"name": "Hello-World",
@@ -80,6 +87,7 @@ GET_SHORT_REPOS = [
"created_at": "2011-01-26T19:01:12Z"
}
]
+
GET_SHORT_GISTS = [
{
"url": "https://api.github.com/gists/1",
@@ -90,6 +98,7 @@ GET_SHORT_GISTS = [
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"files": {