Improvements in `User()`, new tests, updated information about tests
authorMarek Marecki <triviuss@gmail.com>
Fri, 3 May 2013 19:56:51 +0000 (21:56 +0200)
committerMarek Marecki <triviuss@gmail.com>
Fri, 3 May 2013 19:56:51 +0000 (21:56 +0200)
diaspy/people.py
testconf.md
tests.py

index f3756e313a120e4bb35c8f29b37528ff93fef5cf..fdb47be52fe87903d000bc0424a6363f0e51ceca 100644 (file)
@@ -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']))
index b527c4c2c157e8397f5b9489c1e09267bf4e4d73..5580c0abed6b7fe9e1bda1a5f30669b4a7345e95 100644 (file)
@@ -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'
index aee11f3e8312c03febeafb6315e53f59c55644c1..a37541374bf84a57a547e1c07841376a3e5d994c 100644 (file)
--- 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__':