* `diaspy.people.User().handle()` now returns `diaspora_id` instead of `handle` wich...
authorCYBERDEViLNL <CYBERDEViLNL@github.com>
Mon, 5 Nov 2018 12:40:00 +0000 (13:40 +0100)
committerCYBERDEViLNL <CYBERDEViLNL@github.com>
Mon, 5 Nov 2018 12:40:00 +0000 (13:40 +0100)
* Apparently `/u/username.json` retuns 404 so `diaspy.people.User().fetchhandle()` now fetches data using `diaspy.people.User().fetchprofile()`.
* Some formatting fixes in `settings.py`
* `tests.py` should succeed now.

Changelog.markdown
diaspy/people.py
diaspy/settings.py
tests.py

index fd03c257f7dd0be39bd077196d74ca739d477b34..6b6020511e431b7a3ebc65acb77ab47dd504cf07 100644 (file)
@@ -48,6 +48,7 @@ Note: In this version indentation changed from spaces to tabs.
 * __upd__:  Update `diaspy.models.Post()` it's interaction data after liked,
 * __upd__:  `diaspy.connection.Connection()`'s `getUserData()` method will now set the `Connection()` object it's `self._userdata`,
 * __upd__:  Posts obtained by `diaspy.streams.Generic()` are now fetched once instead of twice,
+* __upd__:  `tests.py`,
 
 
 * __fix__:  Streams seemed to miss posts on `more()` method, should be fixed now. Also a new dependency: `dateutil`,
@@ -72,7 +73,8 @@ Note: In this version indentation changed from spaces to tabs.
 
 * __rem__:  `_obtain()` from `diaspy.streams.Outer()`, it was the same as `_obtain()` in `diaspy.streams.Generic()`,
 * __rem__:  `diaspy.models.Post()` its `update()` method since it is deprecated for a while now,
-* __rem__:  `backtime` parameter removed from `diaspy.streams.Generic.more()`.
+* __rem__:  `backtime` parameter removed from `diaspy.streams.Generic.more()`,
+* __rem__:  `protocol` parameter removed from `diaspy.people.User().fetchhandle()`.
 
 
 ----
index cebfb921307d4420e00949cb2cca7b7443eb73ce..c16cb169dbc76c1a7a5e19891276583715360eb7 100644 (file)
@@ -68,7 +68,7 @@ class User():
                self.stream = []
                self.data = {
                        'guid': guid,
-                       'handle': handle,
+                       'diaspora_id': handle,
                        'id': id,
                }
                self.photos = []
@@ -85,8 +85,7 @@ class User():
                return '{0} ({1})'.format(self.handle(), self.guid())
 
        def handle(self):
-               if 'handle' in self.data: return self['handle']
-               return self.data.get('diaspora_id', 'Unknown handle')
+               return self.data.get('diaspora_id', 'Unknown Diaspora ID')
 
        def guid(self):
                return self.data.get('guid', '<guid missing>')
@@ -103,7 +102,7 @@ class User():
                if fetch == 'posts':
                        if self.handle() and not self['guid']: self.fetchhandle()
                        else: self.fetchguid()
-               elif fetch == 'data' and self['handle']:
+               elif fetch == 'data' and self['diaspora_id']:
                        self.fetchprofile()
 
        def _finalize_data(self, data):
@@ -121,14 +120,12 @@ class User():
                """
                if request.status_code != 200: raise Exception('wrong error code: {0}'.format(request.status_code))
                data = request.json()
-               self.data = self._finalize_data(data)
+               self.data.update(self._finalize_data(data))
 
-       def fetchhandle(self, protocol='https'):
-               """Fetch user data and posts using Diaspora handle.
+       def fetchhandle(self):
+               """Fetch user data and posts using Diaspora ID (previously known as handle).
                """
-               pod, user = sephandle(self['handle'])
-               request = self._connection.get('{0}://{1}/u/{2}.json'.format(protocol, pod, user), direct=True)
-               self._postproc(request)
+               self.fetchprofile()
                self._fetchstream()
 
        def fetchguid(self, fetch_stream=True):
index 53d7ab5751198d54f651908226a3ecd5352f75ce..e0d47b4ffc331bcfbaa6327a81aa4736ca5ee5b5 100644 (file)
@@ -123,7 +123,7 @@ class Account():
                if BS4_SUPPORT:
                        soup = BeautifulSoup(request.text, 'lxml')
                        language = soup.find('select', {"id": "user_language"})
-                       return [(option.text, option['value']) for option in language.findAll('option')]
+                       return [(option['value'], option.text) for option in language.findAll('option')]
                else:
                        return self.language_option_regexp.findall(request.text)
 
@@ -262,7 +262,7 @@ class Profile():
                                else: month_option = -1
                        elif named_month:
                                month_option = month_option.text
-                       else: month_option = month_option['value']
+                       else: month_option = int(month_option['value'])
 
                        day = soup.find('select', {"id": "profile_date_day"})
                        day_option = day.find('option', selected=True)
index ea83a182e8c19644a2a294a33fb63fe72f72520e..d35e262d42d05ec3e1aa012ee82feb8286dc8d55 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -166,7 +166,7 @@ class UserTests(unittest.TestCase):
        def testGettingUserByHandlePosts(self):
                user = diaspy.people.User(test_connection, handle=testconf.diaspora_id)
                self.assertEqual(testconf.guid, user['guid'])
-               self.assertEqual(testconf.diaspora_id, user['handle'])
+               self.assertEqual(testconf.diaspora_id, user['diaspora_id'])
                self.assertEqual(testconf.diaspora_name, user['name'])
                self.assertIn('id', user.data)
                self.assertIn('avatar', user.data)
@@ -174,10 +174,10 @@ class UserTests(unittest.TestCase):
 
        def testGettingUserByGUID(self):
                user = diaspy.people.User(test_connection, guid=testconf.guid)
-               self.assertEqual(testconf.diaspora_id, user['handle'])
+               self.assertEqual(testconf.diaspora_id, user['diaspora_id'])
                self.assertEqual(testconf.diaspora_name, user['name'])
                self.assertIn('id', user.data)
-               self.assertIn('avatar', user.data)
+               self.assertIn('avatar', user.data['profile'])
                self.assertEqual(type(user.stream), diaspy.streams.Outer)
 
        def testReprMethod(self):