|
7 | 7 | # ----------------------------------------------------------------------------- |
8 | 8 |
|
9 | 9 | from unittest import TestCase |
10 | | -from os import environ |
| 10 | +from os import environ, sep |
| 11 | +from os.path import isabs, join, exists |
11 | 12 | from time import sleep |
12 | 13 |
|
13 | 14 | from qiita_client import QiitaClient |
@@ -82,3 +83,30 @@ def _wait_for_running_job(self, job_id): |
82 | 83 | break |
83 | 84 |
|
84 | 85 | 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