From 141216dfccfcb662bcb5b381ade53bf858b45389 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Fri, 3 May 2013 21:56:51 +0200 Subject: [PATCH] Improvements in `User()`, new tests, updated information about tests --- diaspy/people.py | 13 +++++++++++-- testconf.md | 4 +++- tests.py | 20 +++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/diaspy/people.py b/diaspy/people.py index f3756e3..fdb47be 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -11,6 +11,7 @@ class User: def __init__(self, connection): self._connection = connection self.data = {} + self.stream = [] def __getitem__(self, key): return self.data[key] @@ -32,7 +33,11 @@ class User: """Get user data using handle. """ pod, user = self._sephandle(diaspora_id) - request = self._connection.session.get('{0}://{1}/u/{2}.json'.format(protocol, pod, user)).json() + request = self._connection.session.get('{0}://{1}/u/{2}.json'.format(protocol, pod, user)) + if request.status_code != 200: + raise Exception('wrong error code: {0}'.format()) + else: + request = request.json() data = request[0]['author'] self.data = data self.stream = Outer(self._connection, location='people/{0}.json'.format(self.data['guid'])) @@ -40,7 +45,11 @@ class User: def _getguid(self, guid): """Get user data using guid. """ - request = self._connection.get('people/{0}.json'.format(guid)).json() + request = self._connection.get('people/{0}.json'.format(guid)) + if request.status_code != 200: + raise Exception('wrong error code: {0}'.format()) + else: + request = request.json() data = request[0]['author'] self.data = data self.stream = Outer(self._connection, location='people/{0}.json'.format(self.data['guid'])) diff --git a/testconf.md b/testconf.md index b527c4c..5580c0a 100644 --- a/testconf.md +++ b/testconf.md @@ -8,8 +8,10 @@ posting of personal data (passsword for D*). #### You have to set the variables yourself! #### Their values have to be valid! -Example file: +Template file: __pod__ = 'https://pod.example.com' __username__ = 'user' __passwd__ = 'strong_password' + diaspora_id = 'user@pod.example.com' + guid = '12345678abcdefgh' diff --git a/tests.py b/tests.py index aee11f3..a375413 100644 --- a/tests.py +++ b/tests.py @@ -129,7 +129,25 @@ class UserTests(unittest.TestCase): 'user0@pod300 example.com', ] for h in handles: - self.assertRaises(Exception, user._sephandle, handle) + self.assertRaises(Exception, user._sephandle, h) + + def testGettingUserByHandle(self): + user = diaspy.people.User(test_connection) + user.fetchhandle(testconf.diaspora_id) + self.assertEqual(testconf.guid, user['guid']) + self.assertEqual(testconf.name, user['name']) + self.assertIn('id', user.data) + self.assertIn('avatar', user.data) + self.assertEqual(type(user.stream), diaspy.streams.Outer) + + def testGettingUserByGUID(self): + user = diaspy.people.User(test_connection) + user.fetchguid(testconf.guid) + self.assertEqual(testconf.diaspora_id, user['diaspora_id']) + self.assertEqual(testconf.name, user['name']) + self.assertIn('id', user.data) + self.assertIn('avatar', user.data) + self.assertEqual(type(user.stream), diaspy.streams.Outer) if __name__ == '__main__': -- 2.25.1