aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-02-11 19:29:25 +0100
committerDavid Medina <davidmedina9@gmail.com>2012-02-11 21:44:10 +0100
commit7ac46101c007190294156e66a795b6e3a5cd898f (patch)
tree696166f8e10387c29d7e4971832e3b11c440f928 /pygithub3
parentEmail pattern to requests.emails (diff)
downloadpython-github3-7ac46101c007190294156e66a795b6e3a5cd898f.tar.xz
python-github3-7ac46101c007190294156e66a795b6e3a5cd898f.zip
Services.users tests completed
services.users.user services.users.emails services.users.keys services.users.followers
Diffstat (limited to 'pygithub3')
-rw-r--r--pygithub3/requests/__init__.py8
-rw-r--r--pygithub3/tests/requests/test_core.py11
-rw-r--r--pygithub3/tests/services/test_users.py27
3 files changed, 37 insertions, 9 deletions
diff --git a/pygithub3/requests/__init__.py b/pygithub3/requests/__init__.py
index a734895..b369565 100644
--- a/pygithub3/requests/__init__.py
+++ b/pygithub3/requests/__init__.py
@@ -23,12 +23,12 @@ class Body(object):
self.required = required
def dumps(self):
- if not self.content:
- return None
+ if not self.schema:
+ return self.content or None
return json.dumps(self.parse())
def parse(self):
- if self.schema and not hasattr(self.content, 'items'):
+ if not hasattr(self.content, 'items'):
raise ValidationError("'%s' needs a content dictionary"
% self.__class__.__name__)
parsed = {key: self.content[key] for key in self.schema
@@ -40,7 +40,7 @@ class Body(object):
if not parsed[attr_required]:
raise ValidationError("'%s' attribute can't be empty" %
attr_required)
- return parsed or self.content
+ return parsed
class Request(object):
diff --git a/pygithub3/tests/requests/test_core.py b/pygithub3/tests/requests/test_core.py
index a46c1d9..68663c0 100644
--- a/pygithub3/tests/requests/test_core.py
+++ b/pygithub3/tests/requests/test_core.py
@@ -70,12 +70,17 @@ class TestRequest(TestCase):
self.assertIsNone(request.get_body())
-class TestRequestBody(TestCase):
+class TestRequestBodyWithSchema(TestCase):
def setUp(self):
valid_body = dict(schema=('arg1', 'arg2'), required=('arg1', ))
self.b = Body({}, **valid_body)
+ def test_with_body_empty_and_schema_permissive(self):
+ self.b.schema = ('arg1', 'arg2', '...')
+ self.b.required = ()
+ self.assertEqual(self.b.dumps(), {})
+
def test_with_required(self):
self.b.content = dict(arg1='arg1')
self.assertEqual(self.b.dumps(), dict(arg1='arg1'))
@@ -88,9 +93,9 @@ class TestRequestBody(TestCase):
self.b.content = 'invalid'
self.assertRaises(ValidationError, self.b.dumps)
- def test_without_body(self):
+ def test_with_body_as_None(self):
self.b.content = None
- self.assertIsNone(self.b.dumps())
+ self.assertRaises(ValidationError, self.b.dumps)
def test_only_valid_keys(self):
self.b.content = dict(arg1='arg1', arg2='arg2', fake='test')
diff --git a/pygithub3/tests/services/test_users.py b/pygithub3/tests/services/test_users.py
index f61d60c..0438f99 100644
--- a/pygithub3/tests/services/test_users.py
+++ b/pygithub3/tests/services/test_users.py
@@ -79,12 +79,15 @@ class TestEmailsService(TestCase):
self.assertEqual(client_request.call_args[1],
dict(data=('test@xample.com', )))
- def test_DELETE(self, request_method):
+ def test_DELETE_with_emails(self, request_method):
request_method.return_value = mock_response('delete')
self.es.delete('email_must_be_founded') # or 404 raises
self.assertEqual(request_method.call_args[0],
('delete', _('user/emails')))
+ def test_DELETE_without_emails(self, request_method):
+ self.assertRaises(ValidationError, self.es.delete)
+
@patch.object(requests.sessions.Session, 'request')
class TestFollowersService(TestCase):
@@ -166,5 +169,25 @@ class TestKeysService(TestCase):
self.assertEqual(request_method.call_args[0],
('get', _('user/keys/1')))
- def test_ADD(self, request_method):
+ def test_ADD_with_required(self, request_method):
request_method.return_value = mock_response('post')
+ self.ks.add({'key': 'ssh-rsa ...', 'title': 'test'})
+ self.assertEqual(request_method.call_args[0], ('post', _('user/keys')))
+
+ def test_ADD_without_required(self, request_method):
+ self.assertRaises(ValidationError, self.ks.add, {})
+
+ def test_UPDATE_with_required(self, request_method):
+ request_method.return_value = mock_response('patch')
+ self.ks.update(1, {'key': 'ssh-rsa ...', 'title': 'test'})
+ self.assertEqual(request_method.call_args[0],
+ ('patch', _('user/keys/1')))
+
+ def test_UPDATE_without_required(self, request_method):
+ self.assertRaises(ValidationError, self.ks.update, 1, {})
+
+ def test_DELETE(self, request_method):
+ request_method.return_value = mock_response('delete')
+ self.ks.delete(1)
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('user/keys/1')))