From: Marek Marecki Date: Sun, 19 May 2013 19:31:57 +0000 (+0200) Subject: One can now remove() aspects by their name, repr(Post) now returns more X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1467ec154211a54f3b141a37a6cf75324c76ec65;p=diaspy.git One can now remove() aspects by their name, repr(Post) now returns more detailed string, new tests --- diff --git a/diaspy/models.py b/diaspy/models.py index c6a243e..bedd1ee 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -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. """ diff --git a/diaspy/streams.py b/diaspy/streams.py index ab8d8cb..7c9b767 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -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) diff --git a/tests.py b/tests.py index 9d92adb..0cdaf03 100644 --- 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()