Skip to content

Commit

Permalink
Incorporate @guillermo-carrasco changes i.r.t waking up couchdb and b…
Browse files Browse the repository at this point in the history
…asic test, still cannot connect to the database programatically
  • Loading branch information
Roman Valls Guimera committed Dec 2, 2013
1 parent 39ad907 commit 5b70ab8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
26 changes: 25 additions & 1 deletion facs/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import json
import warnings
import requests
from contextlib import contextmanager

import couchdb
Expand Down Expand Up @@ -44,10 +45,33 @@ def generate_dummy_fastq(fname, num_reads, case=''):
f.write('arvestad' * stride + os.linesep)


def send_couchdb(server, db, user, passwd, doc):
def _wake(server, retries=5):
"""Try to wake up server by retrying get requests.
This method is basically used to wake up the public database facs.iriscouch.com
used to store the tests results.
"""
status_code = requests.codes.NO_RESPONSE
while status_code != requests.codes.OK and retries:
try:
r = requests.get(db)
status_code = r.status_code
retries = 0
except requests.ConnectionError:
if retries == 1:
raise requests.ConnectionError("There was a problem connecting to {} and the " \
"results could not be uploaded".format(db))
else:
retries -= 1
pass


def send_couchdb(server, db, user, passwd, doc, wake_up=False):
''' Send JSON document to couchdb
'''
try:
if wake_up:
_wake(server)
couch = couchdb.Server(server)
couch.resource.credentials = (user, passwd)
db = couch[db]
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"nose",
"nose-timer",
"jinja2",
"requests",
"couchdb"
],
entry_points="""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def test_1_build_ref(self):
json_doc = facs.build(org, bf)
self.results.append(json_doc)

def test_2_query(self):
""" Query against datasets (generated by simNGS)
"""

for sample in glob.glob(os.path.join(self.synthetic_fastq, "*.fastq")):
for ref in os.listdir(self.reference):
qry = os.path.join(self.synthetic_fastq, sample)
bf = os.path.join(self.bloom_dir, os.path.splitext(ref)[0]+".bloom")
print(qry, bf)
json_doc = facs.query(qry, bf)
self.results.append(json_doc)

def test_3_query_custom(self):
""" Query against the uncompressed FastQ files files manually deposited
in data/custom folder.
Expand Down

0 comments on commit 5b70ab8

Please sign in to comment.