New _sessionget() method. get_token() refactored to use it.
authorMarek Marecki <triviuss@gmail.com>
Fri, 29 Mar 2013 10:10:14 +0000 (11:10 +0100)
committerMarek Marecki <triviuss@gmail.com>
Fri, 29 Mar 2013 10:10:14 +0000 (11:10 +0100)
diaspy/client.py
tests.py

index aae0681978c1d9d69c003028d9827b7b90a07889..e219bd0e698374f90afbb2a0526d6575d9cc62ea 100644 (file)
@@ -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,
index d64b235fdbb325aea7dc52d0e31d89a400bb4e72..72be51d0ae3ffb1daad97da17b681eb0757428b4 100644 (file)
--- 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'