From: Marek Marecki Date: Fri, 29 Mar 2013 11:50:28 +0000 (+0100) Subject: Small changes in test suite, preparation to refactor to _sessionpost() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e475a9d0ade020022c133ceeb105cb15ee6ddb1c;p=diaspy.git Small changes in test suite, preparation to refactor to _sessionpost() --- diff --git a/diaspy/client.py b/diaspy/client.py index 75eea3c..8c7eece 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -35,6 +35,28 @@ class Client: """ return self.session.get('{0}/{1}'.format(self.pod, string)) + def _sessionpost(self, string, data, headers={}, params={}): + """This method posts data to session. + Performs additional checks if needed. + + Example: + To post to 'foo' one should call `_sessionpost('foo', data={})`. + + :param string: URL to post without the pod's URL and slash eg. 'status_messages'. + :type string: str + :param data: Data to post. + :param headers: Headers. + :type headers: dict + :param params: Optional parameters. + :type params: dict + """ + string = '{0}/{1}'.format(self.pod, string) + if headers and params: r = self.session.post(string, data=data, headers=headers, params=params) + elif headers and not params: r = self.session.post(string, data=data, headers=headers) + elif not headers and params: r = self.session.post(string, data=data, params=params) + else: r = self.session.post(string, data=data) + return r + def get_token(self): """This function gets a token needed for authentication in most cases @@ -233,6 +255,20 @@ class Client: raise Exception('wrong status code: {0}'.format(r.status_code)) return r.json() + def add_aspect(self, aspect_name, visible=0): + """ This function adds a new aspect. + """ + + data = {'authenticity_token': self.get_token(), + 'aspect[name]': aspect_name, + 'aspect[contacts_visible]': visible} + + r = self.session.post('{0}/aspects'.format(self.pod), + data=data) + + if r.status_code != 200: + raise Exception('wrong status code: {0}'.format(r.status_code)) + def remove_user_from_aspect(self, user_id, aspect_id): """ this function removes a user from an aspect. @@ -255,20 +291,6 @@ class Client: return r.json() - def add_aspect(self, aspect_name, visible=0): - """ This function adds a new aspect. - """ - - data = {'authenticity_token': self.get_token(), - 'aspect[name]': aspect_name, - 'aspect[contacts_visible]': visible} - - r = self.session.post('{0}/aspects'.format(self.pod), - data=data) - - if r.status_code != 200: - raise Exception('wrong status code: {0}'.format(r.status_code)) - def remove_aspect(self, aspect_id): """ This function adds a new aspect. """ diff --git a/testconf.md b/testconf.md new file mode 100644 index 0000000..b527c4c --- /dev/null +++ b/testconf.md @@ -0,0 +1,15 @@ +## Configuration file for `diaspy` test suite (./tests.py) + +Developer/tester has to create their own `testconf.py` file +because it is appended to `.gitignore` to avoid accidental +posting of personal data (passsword for D*). + + +#### You have to set the variables yourself! +#### Their values have to be valid! + +Example file: + + __pod__ = 'https://pod.example.com' + __username__ = 'user' + __passwd__ = 'strong_password' diff --git a/testconf.py b/testconf.py deleted file mode 100644 index 8ad0abf..0000000 --- a/testconf.py +++ /dev/null @@ -1,17 +0,0 @@ -## Configuration file for diapsy's -## test suite (./tests.py) -## -## It is essential that a developer/tester fills -## the variables because thay are supplied empty -## by default - after first commit the `testconf.py` -## was added to .gitignore to avoid posting personal -## data of developer/tester. - - -# You have to set the varaiables yourself. -# Their values have to be valid. - -# __pod__ = 'https://pod.example.com' -__pod__ = '' -__username__ = '' -__passwd__ = ''