def __init__(self, connection):
self._connection = connection
self.data = {}
+ self.stream = []
def __getitem__(self, key):
return self.data[key]
"""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']))
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']))
#### 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'
'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__':