From d88b0f9424db740667fdadcce6cac2eba0c262e6 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Fri, 29 Mar 2013 11:10:14 +0100 Subject: [PATCH] New _sessionget() method. get_token() refactored to use it. --- diaspy/client.py | 17 +++++++++++++---- tests.py | 6 ------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/diaspy/client.py b/diaspy/client.py index aae0681..e219bd0 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -24,13 +24,24 @@ class Client: self._setlogindata(username, password) self._login() + def _sessionget(self, string): + """This method gets data from session. + Performs additional checks if needed. + + Example: + To obtain 'foo' from pod one should call `_sessionget('foo')`. + + :param string: URL to get without the pod's URL and slash eg. 'stream'. + :type string: str + """ + return self.session.get('{0}/{1}'.format(self.pod, string)) + def get_token(self): """This function gets a token needed for authentication in most cases :returns: string -- token used to authenticate - """ - r = self.session.get('{0}/stream'.format(self.pod)) + r = self._sessionget('stream') token = self._token_regex.search(r.text).group(1) return token @@ -40,8 +51,6 @@ class Client: .. note:: It should be called before _login() function. """ - #r = self.session.get(self.pod + '/users/sign_in') - #token = self._token_regex.search(r.text).group(1) self._username, self._password = username, password self._login_data = { 'user[username]': self._username, diff --git a/tests.py b/tests.py index d64b235..72be51d 100644 --- a/tests.py +++ b/tests.py @@ -31,12 +31,6 @@ class ClientTests(unittest.TestCase): self.assertEqual(client._login_data['user[password]'], 'testpassword') self.assertEqual(client._login_data['authenticity_token'], client.get_token()) - def testPreparationOfPostData(self): - """This test checks correctness of data set for posting. - """ - - - if __name__ == '__main__': __passwd__ = getpass.getpass(prompt='Password used for testing: ') if __passwd__ == '': __passwd__ = 'testpassword' -- 2.25.1