From: Marek Marecki Date: Fri, 3 May 2013 19:56:51 +0000 (+0200) Subject: Improvements in `User()`, new tests, updated information about tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=141216dfccfcb662bcb5b381ade53bf858b45389;p=diaspy.git Improvements in `User()`, new tests, updated information about tests --- 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__':