You can now get list of languages in settings
authorMarek Marecki <marekjm@taistelu.com>
Thu, 8 Aug 2013 17:53:18 +0000 (19:53 +0200)
committerMarek Marecki <marekjm@taistelu.com>
Thu, 8 Aug 2013 17:53:18 +0000 (19:53 +0200)
diaspy/settings.py
tests.py

index 391caf8bce98e0125dacd72359c7598410e9c8c8..410b5e84da109a9d3f0eb51644b1728df80b108a 100644 (file)
@@ -1,12 +1,12 @@
+"""This module provides access to user's settings on Diaspora*.
+"""
+
+
 import json
 import re
 import urllib
 
 
-"""This module provides access to user's settings on Diaspora*.
-"""
-
-
 class Settings():
     """This object is used to get access to user's settings on
     Diaspora* and provides interface for downloading user's stuff.
@@ -34,11 +34,15 @@ class Settings():
         """Returns a list of tuples containing ('Language name', 'identifier').
         One of the Black Magic(tm) methods.
         """
-        select_start = '<select id="user_language" name="user[language]"')
+        select_start = '<select id="user_language" name="user[language]">'
         select_end = '</select>'
         languages = []
         request = self._connection.get('user/edit')
-        data = request.text[request.text.find(select_start):]
-        data = data[:data.find(select_end)]
-        print(data)
+        data = request.text[request.text.find(select_start)+len(select_start):]
+        data = data[:data.find(select_end)].split('\n')
+        for item in data:
+            name = item[item.find('>')+1:item.rfind('<')]
+            identifier = item[item.find('"')+1:]
+            identifier = identifier[:identifier.find('"')]
+            languages.append((name, identifier))
         return languages
index b7f500ff4a764e8d01837ef4aff735d81747a0cd..a45be30d5784e3af98a79fb2584f3a08ea9a8fd9 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -230,6 +230,12 @@ class NotificationsTests(unittest.TestCase):
         else:
             warnings.warn('test not sufficient: no unread notifications were found')
 
+
+class SettingsTests(unittest.TestCase):
+    def testGettingLanguages(self):
+        settings = diaspy.settings.Settings(test_connection)
+        self.assertIn(('English', 'en'), settings.getLanguages())
+
 if __name__ == '__main__': 
     print('Hello World!')
     print('It\'s testing time!')