Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CouchDB.info() #9

Merged
merged 1 commit into from
Mar 20, 2020

Conversation

adrienverge
Copy link
Contributor

Add function to get CouchDB server information (i.e. GET /). This
allows, for example, getting the server version with:

couchdb = CouchDB(url)
info = await couchdb.info()
print(info['version'])

Copy link
Member

@bmario bmario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but it needs the wrapping of the aiohttp exceptions. I suggested my preferred way to do it inline.

@@ -39,3 +39,6 @@ def __init__(self, *args, **kwargs):

async def keys(self, **params):
return await self._server._all_dbs(**params)

async def info(self):
return await self._server._get('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an _info() method to RemoteServer and add the @raises decorator for the 401 to that new method. Just like the _check_session method there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and please use " instead of '. That's probably, what the black CI step is complaining about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Add function to get CouchDB server information (i.e. `GET /`). This
allows, for example, getting the server version with:

    couchdb = CouchDB(url)
    info = await couchdb.info()
    print(info['version'])
@adrienverge
Copy link
Contributor Author

I updated the pull request thanks to your suggestion. Here is the diff since last time:

--- a/aiocouch/couchdb.py
+++ b/aiocouch/couchdb.py
@@ -41,4 +41,4 @@ class CouchDB(object):
         return await self._server._all_dbs(**params)
 
     async def info(self):
-        return await self._server._get('/')
+        return await self._server._info()
--- a/aiocouch/remote.py
+++ b/aiocouch/remote.py
@@ -103,6 +103,10 @@ class RemoteServer(object):
         await self._http_session.close()
         await asyncio.sleep(0.250 if has_ssl_conn else 0)
 
+    @raises(401, "Invalid credentials")
+    async def _info(self):
+        return await self._get("/")
+
     @raises(401, "Authentification failed, check provided credentials.")
     async def _check_session(self):
         await self._get("/_session")

@bmario bmario merged commit 913d72c into metricq:master Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants