Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added an exists method to the Database type.

Signed-off-by: Nick Campbell <ncampbell@siteworx.com>
  • Loading branch information...
commit c39c412c20c2d0e828d3a3f8f1822d5b88f66370 1 parent 8c7cf6f
@ncb000gt ncb000gt authored
Showing with 19 additions and 1 deletion.
  1. +4 −0 .gitignore
  2. +6 −0 couchquery/__init__.py
  3. +9 −1 tests/test_document.py
View
4 .gitignore
@@ -0,0 +1,4 @@
+*.pyc
+build/
+couchquery.egg-info/
+dist/
View
6 couchquery/__init__.py
@@ -386,6 +386,12 @@ def get_revs(self, id_, fetch=False):
else:
yield rev["rev"]
+ def exists(self):
+ response = self.http.get('')
+ if response.status == 404:
+ return False
+ return True
+
def create(self, doc, all_or_nothing=False):
"""Create a document. Accepts any object that can be converted in to a dict.
If multiple documents are passed they are handed off to the bulk document handler.
View
10 tests/test_document.py
@@ -22,6 +22,14 @@ def setup_module(module):
{'type':'red-lectroid', 'name':"John Small Berries"},
]
+def test_db_exists_false():
+ dbf = Database('http://localhost:5984/this_db_should_likely_not_exist')
+ assert db.exists() == False
+
+def test_db_exists_true():
+ dbf = Database('http://localhost:5984/couchquery_unittest')
+ assert db.exists() == True
+
def test_simple_add():
for doc in lectroids:
assert db.create(doc)['ok'] == True
@@ -85,4 +93,4 @@ def test_revisions():
# alldocs.delete()
def teardown_module(module):
- deletedb(module.db)
+ deletedb(module.db)
Please sign in to comment.
Something went wrong with that request. Please try again.