From: Marek Marecki Date: Sun, 19 May 2013 19:15:49 +0000 (+0200) Subject: Fixed bug in diaspy.models.Post.__str__, added logout() method to X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=63cc182dabca8a947fc0424402f8b166a2da0bff;p=diaspy.git Fixed bug in diaspy.models.Post.__str__, added logout() method to Connection() --- diff --git a/diaspy/connection.py b/diaspy/connection.py index 1ea41b6..1fbba9f 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -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. """ diff --git a/diaspy/models.py b/diaspy/models.py index 5fc22b9..c6a243e 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -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. diff --git a/diaspy/streams.py b/diaspy/streams.py index dcfe906..ab8d8cb 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -222,6 +222,21 @@ class Aspects(Generic): _location = 'aspects.json' _id_regexp = re.compile(r'\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)) diff --git a/tests.py b/tests.py index 2876965..9d92adb 100644 --- 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)