Skip to content

Commit 71526bb

Browse files
committed
don't complain about overwriting files IF in test mode
1 parent cfe606a commit 71526bb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

qiita_pet/handlers/cloud_handlers/file_transfer_handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def post(self):
9292
filepath = filepath[len(os.sep):]
9393
filepath = os.path.abspath(os.path.join(basedatadir, filepath))
9494

95-
if os.path.exists(filepath):
95+
# prevent overwriting existing files, except in test mode
96+
if os.path.exists(filepath) and \
97+
(not qiita_config.test_environment):
9698
raise HTTPError(403, reason=(
9799
"The requested file is already "
98100
"present in Qiita's BASE_DATA_DIR!"))

qiita_pet/handlers/cloud_handlers/tests/test_file_transfer_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from qiita_db.handlers.tests.oauthbase import OauthTestingBase
77
import qiita_db as qdb
8+
from qiita_core.qiita_settings import qiita_config
89

910

1011
class FetchFileFromCentralHandlerTests(OauthTestingBase):
@@ -70,7 +71,11 @@ def test_post(self):
7071

7172
# check if error is raised, if file already exists
7273
with open(fp_source, 'rb') as fh:
74+
# we need to let qiita thinks for this test, to NOT be in test mode
75+
oldval = qiita_config.test_environment
76+
qiita_config.test_environment = False
7377
obs = self.post_authed(endpoint, files={'bar/': fh})
78+
qiita_config.test_environment = oldval
7479
self.assertIn("already present in Qiita's BASE_DATA_DIR!",
7580
obs.reason)
7681

0 commit comments

Comments
 (0)