One can now remove() aspects by their name, repr(Post) now returns more
authorMarek Marecki <triviuss@gmail.com>
Sun, 19 May 2013 19:31:57 +0000 (21:31 +0200)
committerMarek Marecki <triviuss@gmail.com>
Sun, 19 May 2013 19:31:57 +0000 (21:31 +0200)
detailed string, new tests

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

index c6a243e0048154be78d29956b8c2d82061cafdbc..bedd1ee2207485f44957f6e40fbe123ff444299a 100644 (file)
@@ -17,6 +17,12 @@ class Post:
         self._connection = connection
         self.post_id = post_id
 
+    def __repr__(self):
+        """Returns string containing more information then str().
+        """
+        data = self.get_data()
+        return '{0} ({1}): {2}'.format(data['author']['name'], data['author']['diaspora_id'], data['text'])
+
     def __str__(self):
         """Returns text of a post.
         """
index ab8d8cbb2d927813f38cb6aad9be2f8196ad0c4c..7c9b76743d6b6d2bb9afcaaad9420bdc29935b68 100644 (file)
@@ -266,14 +266,17 @@ class Aspects(Generic):
         else: id = self._getaid(request)
         return id
 
-    def remove(self, aspect_id):
+    def remove(self, aspect_id=0, name=''):
         """This method removes an aspect.
         500 is accepted because although the D* will
         go nuts it will remove the aspect anyway.
 
         :param aspect_id: id fo aspect to remove
         :type aspect_id: int
+        :param name: name of aspect to remove
+        :type name: str
         """
+        if not aspect_id and name: aspect_id = self.getID(name)
         data = {'authenticity_token': self._connection.get_token()}
         request = self._connection.delete('aspects/{}'.format(aspect_id),
                                           data=data)
index 9d92adb9ff0a10673caf5920d3c402c7e79eaf80..0cdaf0396e0c58b308507d6b10f60a2696c2e244 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -120,17 +120,22 @@ class StreamTest(unittest.TestCase):
     def testAspectsAdd(self):
         aspects = diaspy.streams.Aspects(test_connection)
         test_aspect_id = aspects.add('diaspy-test')
+        aspects.add('diaspy-test-false')
 
     def testAspectsGettingID(self):
         aspects = diaspy.streams.Aspects(test_connection)
-        id = aspects.getID('Coding')
+        id = aspects.getID('diaspy-test')
         self.assertEqual(int, type(id))
-        self.assertNotEqual(-1, id)
+        self.assertEqual(test_aspect_id, id)
 
-    def testAspectsRemove(self):
+    def testAspectsRemoveById(self):
         aspects = diaspy.streams.Aspects(test_connection)
         aspects.remove(test_aspect_id)
 
+    def testAspectsRemoveByName(self):
+        aspects = diaspy.streams.Aspects(test_connection)
+        aspects.remove(name='diaspy-test-false')
+
     def testActivity(self):
         activity = diaspy.streams.Activity(test_connection)
 
@@ -169,4 +174,14 @@ class UserTests(unittest.TestCase):
         self.assertEqual(type(user.stream), diaspy.streams.Outer)
 
 
+class PostTests(unittest.TestCase):
+    def testStringConversion(self):
+        s = diaspy.streams.Stream(test_connection)
+        print(str(s[0]))
+
+    def testRepr(self):
+        s = diaspy.streams.Stream(test_connection)
+        print(repr(s[0]))
+
+
 if __name__ == '__main__': unittest.main()