From: Marek Marecki Date: Fri, 29 Mar 2013 11:28:26 +0000 (+0100) Subject: Removed unnecessary data obtaining from `get_*` methods X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=264336e214e219fba2a2fc92face37d9f20e0514;p=diaspy.git Removed unnecessary data obtaining from `get_*` methods --- diff --git a/diaspy/client.py b/diaspy/client.py index bf3ddd9..75eea3c 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -6,7 +6,6 @@ import diaspy.models class Client: """This is the client class to connect to Diaspora. - """ def __init__(self, pod, username, password): """ @@ -150,7 +149,6 @@ class Client: :returns: list -- list of Post objects. """ - data = {'authenticity_token': self.get_token()} r = self._sessionget('stream.json') if r.status_code != 200: @@ -164,7 +162,6 @@ class Client: :returns: list -- list of json formatted notifications """ - data = {'authenticity_token': self.get_token()} r = self._sessionget('notifications.json') if r.status_code != 200: @@ -179,7 +176,6 @@ class Client: :returns: list -- list of Post objects """ - data = {'authenticity_token': self.get_token()} r = self._sessionget('mentions.json') if r.status_code != 200: @@ -195,7 +191,6 @@ class Client: :returns: list -- list of Post objects """ - data = {'authenticity_token': self.get_token()} r = self._sessionget('tags/{0}.json'.format(tag)) if r.status_code != 200: @@ -204,6 +199,19 @@ class Client: tagged_posts = r.json() return [ diaspy.models.Post(str(post['id']), self) for post in tagged_posts ] + def get_mailbox(self): + """This functions returns a list of messages found in the conversation. + + :returns: list -- list of Conversation objects. + """ + r = self._sessionget('conversations.json') + + if r.status_code != 200: + raise Exception('wrong status code: {0}'.format(r.status_code)) + + mailbox = r.json() + return [ diaspy.conversations.Conversation(str(conversation['conversation']['id']), self) for conversation in mailbox ] + def add_user_to_aspect(self, user_id, aspect_id): """ this function adds a user to an aspect. @@ -264,7 +272,6 @@ class Client: def remove_aspect(self, aspect_id): """ This function adds a new aspect. """ - data = {'authenticity_token': self.get_token()} r = self.session.delete('{0}/aspects/{1}'.format(self.pod, aspect_id), @@ -273,22 +280,8 @@ class Client: if r.status_code != 404: raise Exception('wrong status code: {0}'.format(r.status_code)) - def get_mailbox(self): - """This functions returns a list of messages found in the conversation. - - :returns: list -- list of Conversation objects. - """ - data = {'authenticity_token': self.get_token()} - r = self._sessionget('conversations.json') - - if r.status_code != 200: - raise Exception('wrong status code: {0}'.format(r.status_code)) - - mailbox = r.json() - return [ diaspy.conversations.Conversation(str(conversation['conversation']['id']), self) for conversation in mailbox ] - def new_conversation(self, contacts, subject, text): - """ start a new conversation + """Start a new conversation. :param contacts: recipients ids, no guids, comma sperated. :type contacts: str @@ -296,9 +289,7 @@ class Client: :type subject: str :param text: text of the message. :type text: str - """ - data = {'contact_ids': contacts, 'conversation[subject]': subject, 'conversation[text]': text, diff --git a/testconf.py b/testconf.py index 8ad0abf..167b793 100644 --- a/testconf.py +++ b/testconf.py @@ -12,6 +12,6 @@ # Their values have to be valid. # __pod__ = 'https://pod.example.com' -__pod__ = '' -__username__ = '' -__passwd__ = '' +__pod__ = 'https://pod.orkz.net' +__username__ = 'marekjm' +__passwd__ = 'mAreKJmonDiASporA' diff --git a/tests.py b/tests.py index 070c6da..3b5a9a3 100644 --- a/tests.py +++ b/tests.py @@ -29,6 +29,23 @@ class ClientTests(unittest.TestCase): self.assertEqual(client._login_data['user[password]'], __passwd__) self.assertEqual(client._login_data['authenticity_token'], client.get_token()) + def testGettingUserInfo(self): + client = diaspy.client.Client(__pod__, __username__, __passwd__) + info = client.get_user_info() + self.assertEqual(dict, type(info)) + + def testGettingStream(self): + client = diaspy.client.Client(__pod__, __username__, __passwd__) + stream = client.get_stream() + self.assertEqual(list, type(stream)) + if stream: self.assertEqual(diaspy.models.Post, type(stream[0])) + + def testGettingNotifications(self): + client = diaspy.client.Client(__pod__, __username__, __passwd__) + notifications = client.get_notifications() + self.assertEqual(list, type(notifications)) + if notifications: self.assertEqual(dict, type(notifications[0])) + def testGettingTag(self): client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) tag = client.get_tag('foo')