Skip to content

Commit

Permalink
fixing failures tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antgonza committed Jan 30, 2017
1 parent 1626859 commit ade8cbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
13 changes: 7 additions & 6 deletions qiita_pet/handlers/download.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from tornado.web import authenticated
from tornado.web import authenticated, HTTPError

from os.path import basename
from datetime import datetime

from .base_handlers import BaseHandler
from qiita_pet.exceptions import QiitaPetAuthorizationError
from qiita_pet.handlers.api_proxy import study_get_req
from qiita_db.study import Study
from qiita_db.util import filepath_id_to_rel_path, get_db_files_base_dir
Expand All @@ -19,8 +18,9 @@ def get(self, filepath_id):
fid = int(filepath_id)

if not validate_filepath_access_by_user(self.current_user, fid):
raise QiitaPetAuthorizationError(
self.current_user, 'filepath id %s' % str(fid))
raise HTTPError(
404, "%s doesn't have access to "
"filepath_id: %s" % (self.current_user.email, str(fid)))

relpath = filepath_id_to_rel_path(fid)
fname = basename(relpath)
Expand Down Expand Up @@ -51,8 +51,9 @@ def get(self, study_id):
study_info = study_get_req(study_id, self.current_user.id)

if study_info['status'] != 'success':
raise QiitaPetAuthorizationError(
self.current_user, 'study id %s' % str(study_id))
raise HTTPError(405, "%s: %s, %s" % (study_info['message'],
self.current_user.email,
str(study_id)))

study = Study(study_id)
user = self.current_user
Expand Down
18 changes: 13 additions & 5 deletions qiita_pet/test/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
# -----------------------------------------------------------------------------

from unittest import main
from mock import Mock

# from qiita_pet.exceptions import QiitaPetAuthorizationError
from qiita_pet.test.tornado_test_base import TestHandlerBase
from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_db.user import User


class TestDownloadHandler(TestHandlerBase):
Expand All @@ -30,7 +32,8 @@ def test_download(self):
"download is located at raw_data/1_s_G1_L001_sequences.fastq.gz"))

# failure
# response = self.get('/download/1000')
response = self.get('/download/1000')
self.assertEqual(response.code, 404)


class TestDownloadStudyBIOMSHandler(TestHandlerBase):
Expand All @@ -42,7 +45,6 @@ def tearDown(self):
super(TestDownloadStudyBIOMSHandler, self).tearDown()

def test_download_study(self):
# check success
response = self.get('/download_study_bioms/1')
self.assertEqual(response.code, 200)
self.assertEqual(response.body, (
Expand All @@ -56,8 +58,14 @@ def test_download_study(self):
"processed_data/1_study_1001_closed_reference_otu_table_Silva.biom"
"\nQIIME map file: templates/1_prep_1_qiime_19700101-000000.txt"))

# failure
# response = self.get('/download_study_bioms/2')
response = self.get('/download_study_bioms/200')
self.assertEqual(response.code, 405)

# changing user so we can test the failures
BaseHandler.get_current_user = Mock(
return_value=User("demo@microbio.me"))
response = self.get('/download_study_bioms/1')
self.assertEqual(response.code, 405)


if __name__ == '__main__':
Expand Down

0 comments on commit ade8cbe

Please sign in to comment.