Skip to content

Commit b12d740

Browse files
committed
generally provide a _fix_plugincoupling_filepath function for plugin tests
1 parent 464c6c6 commit b12d740

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

qiita_client/testing.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
# -----------------------------------------------------------------------------
88

99
from unittest import TestCase
10-
from os import environ
10+
from os import environ, sep
11+
from os.path import isabs, join, exists
1112
from time import sleep
1213

1314
from qiita_client import QiitaClient
@@ -82,3 +83,30 @@ def _wait_for_running_job(self, job_id):
8283
break
8384

8485
return status
86+
87+
def _fix_plugincoupling_filepath(self, fp, BASE_DATA_DIR="/qiita_data/"):
88+
# In some plugin tests, example files are generated temporarily on
89+
# local tmp directories. This is fine for plugincoupling == filesystem
90+
# but will cause "File not found errors" when communication through
91+
# other protocols as the file actually has never been pushed to Qiita
92+
# main. This helper function shall fix this by copying the according
93+
# files over to Qiita main WHEN not using "filesystem" and fix the
94+
# according file paths, i.e. we need to prepend the BASE_DATA_DIR to
95+
# the filename, which should be '/qiita_data/' e.g. here
96+
# https://github.com/jlab/qiita-keycloak
97+
if not exists(fp):
98+
raise ValueError("Filepath does not exist!")
99+
100+
if self.qclient._plugincoupling == 'filesystem':
101+
return fp
102+
else:
103+
processed_fp = fp
104+
# chop off leading / for join to work properly when prepending
105+
# the BASE_DATA_DIR
106+
if isabs(processed_fp):
107+
processed_fp = processed_fp[len(sep):]
108+
processed_fp = join(BASE_DATA_DIR, processed_fp)
109+
# ensure file is transferred to qiita main
110+
self.qclient.push_file_to_central(fp)
111+
# return the filepath prepended with qiita main base_data_dir
112+
return processed_fp

0 commit comments

Comments
 (0)