Skip to content

Commit

Permalink
Merge pull request #35 from kxepal/normalize-access-to-session
Browse files Browse the repository at this point in the history
Move session, login and logout methods from Resource to Account
  • Loading branch information
garbados committed Mar 24, 2014
2 parents ef28976 + 798749a commit cab218b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
18 changes: 18 additions & 0 deletions cloudant/account.py
Expand Up @@ -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)
Expand Down
17 changes: 0 additions & 17 deletions cloudant/resource.py
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/__init__.py
Expand Up @@ -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

Expand Down

0 comments on commit cab218b

Please sign in to comment.