diff --git a/cloudant/account.py b/cloudant/account.py index b53f4f6..580b218 100644 --- a/cloudant/account.py +++ b/cloudant/account.py @@ -56,6 +56,24 @@ def __delitem__(self, name): response = response.result() response.raise_for_status() + def session(self, **kwargs): + """Get current user's authentication and authorization status.""" + return self.get(self._reset_path('_session'), **kwargs) + + def login(self, username, password, **kwargs): + """Authenticate the connection via cookie.""" + # set headers, body explicitly + headers = { + "Content-Type": "application/x-www-form-urlencoded" + } + data = "name=%s&password=%s" % (username, password) + return self.post(self._reset_path('_session'), headers=headers, + data=data, **kwargs) + + def logout(self, **kwargs): + """De-authenticate the connection's cookie.""" + return self.delete(self._reset_path('_session'), **kwargs) + def all_dbs(self, **kwargs): """List all databases.""" return self.get('_all_dbs', **kwargs) diff --git a/cloudant/resource.py b/cloudant/resource.py index 0729570..cdadc6e 100644 --- a/cloudant/resource.py +++ b/cloudant/resource.py @@ -104,23 +104,6 @@ def _make_request(self, method, path='', **kwargs): **opts) return future - def session(self, **kwargs): - """Get current user's authentication and authorization status.""" - return self.get(self._reset_path('_session'), **kwargs) - - def login(self, username, password, **kwargs): - """Authenticate the connection via cookie.""" - # set headers, body explicitly - headers = { - "Content-Type": "application/x-www-form-urlencoded" - } - data = "name=%s&password=%s" % (username, password) - return self.post(self._reset_path('_session'), headers=headers, data=data, **kwargs) - - def logout(self, **kwargs): - """De-authenticate the connection's cookie.""" - return self.delete(self._reset_path('_session'), **kwargs) - def head(self, path='', **kwargs): """ Make a HEAD request against the object's URI joined diff --git a/test/__init__.py b/test/__init__.py index ff3afe9..bcb70e6 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -220,6 +220,10 @@ def testMerge(self): def testAttachment(self): self.doc.attachment('file') + def testNoLoginLogout(self): + assert not hasattr(self.doc, 'login') + assert not hasattr(self.doc, 'logout') + def tearDown(self): assert self.db.delete().status_code == 200