Fixed bug in diaspy.models.Post.__str__, added logout() method to
authorMarek Marecki <triviuss@gmail.com>
Sun, 19 May 2013 19:15:49 +0000 (21:15 +0200)
committerMarek Marecki <triviuss@gmail.com>
Sun, 19 May 2013 19:15:49 +0000 (21:15 +0200)
Connection()

diaspy/connection.py
diaspy/models.py
diaspy/streams.py
tests.py

index 1ea41b6d56575147b6417ae2518eacaeab3f5c25..1fbba9fa443c29d67c13bf3dc6dcdf4c4cf4b8f1 100644 (file)
@@ -103,6 +103,12 @@ class Connection():
         if not self.username or not self.password: raise LoginError('password or username not specified')
         self._login()
 
+    def logout(self):
+        """Logs out from a pod.
+        When logged out you can't do anything.
+        """
+        self.get('users/sign_out')
+
     def podswitch(self, pod):
         """Switches pod from current to another one.
         """
index 5fc22b9ea61b0e05ff9de1b72f05b6f5ae6de6c8..c6a243e0048154be78d29956b8c2d82061cafdbc 100644 (file)
@@ -20,7 +20,7 @@ class Post:
     def __str__(self):
         """Returns text of a post.
         """
-        return self.get_data['text']
+        return self.get_data()['text']
 
     def get_data(self):
         """This function retrieves data of the post.
index dcfe90662d50e6b422b773bb4ae0660f45a97919..ab8d8cbb2d927813f38cb6aad9be2f8196ad0c4c 100644 (file)
@@ -222,6 +222,21 @@ class Aspects(Generic):
     _location = 'aspects.json'
     _id_regexp = re.compile(r'<a href="/aspects/[0-9]+/edit" rel="facebox"')
 
+    def getID(self, aspect):
+        """Returns id of an aspect of given name.
+        Returns -1 if aspect is not found.
+
+        :param aspect: aspect name (must be spelled exactly as when created)
+        :type aspect: str
+        :returns: int
+        """
+        id = -1
+        regexp = re.compile("a_id=[0-9]+'>\s+{0}".format(aspect))
+        result = regexp.search(self._connection.get('aspects').text)
+        if result is not None:
+            id = int(re.compile('[0-9]+').search(result.group(0)).group(0))
+        return id
+
     def filterByIDs(self, ids):
         self._location += '?{0}'.format(','.join(ids))
         self.fill()
@@ -261,7 +276,7 @@ class Aspects(Generic):
         """
         data = {'authenticity_token': self._connection.get_token()}
         request = self._connection.delete('aspects/{}'.format(aspect_id),
-                                   data=data)
+                                          data=data)
         if request.status_code not in [404, 500]:
             raise Exception('wrong status code: {0}'.format(request.status_code))
 
index 287696514bd28fd9b9890e7af43992589775438c..9d92adb9ff0a10673caf5920d3c402c7e79eaf80 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -121,6 +121,12 @@ class StreamTest(unittest.TestCase):
         aspects = diaspy.streams.Aspects(test_connection)
         test_aspect_id = aspects.add('diaspy-test')
 
+    def testAspectsGettingID(self):
+        aspects = diaspy.streams.Aspects(test_connection)
+        id = aspects.getID('Coding')
+        self.assertEqual(int, type(id))
+        self.assertNotEqual(-1, id)
+
     def testAspectsRemove(self):
         aspects = diaspy.streams.Aspects(test_connection)
         aspects.remove(test_aspect_id)