|
9 | 9 | from unittest import TestCase, main |
10 | 10 | import filecmp |
11 | 11 | from os import remove, close, makedirs |
12 | | -from os.path import basename, exists, expanduser, join, isdir |
| 12 | +from os.path import basename, exists, expanduser, join, isdir, dirname |
13 | 13 | from tempfile import mkstemp |
14 | 14 | from json import dumps |
15 | 15 | import pandas as pd |
@@ -488,6 +488,43 @@ def test_push_file_to_central_dir(self): |
488 | 488 | # As we don't necessarily know the QIITA_BASE_DIR, we cannot fetch one |
489 | 489 | # of the files to double check for it's content |
490 | 490 |
|
| 491 | + def test_delete_file_from_central(self): |
| 492 | + # obtain current filepaths to infer QIITA_BASE_DIR |
| 493 | + ainfo = self.tester.get("/qiita_db/artifacts/%s/" % 1) |
| 494 | + cwd = dirname(ainfo['files']['raw_forward_seqs'][0]['filepath']) |
| 495 | + |
| 496 | + for protocol in ['filesystem', 'https']: |
| 497 | + self.qclient._plugincoupling = protocol |
| 498 | + |
| 499 | + # deposit a test file |
| 500 | + fp_test = join(cwd, 'deletme_%s.txt' % protocol) |
| 501 | + makedirs(cwd, exist_ok=True) |
| 502 | + with open(fp_test, 'w') as f: |
| 503 | + f.write('This is a testfile content\n') |
| 504 | + self.clean_up_files.append(fp_test) |
| 505 | + self.qclient.push_file_to_central(fp_test) |
| 506 | + |
| 507 | + # sanity check that test file has been deposited correctly |
| 508 | + fp_obs = self.qclient.fetch_file_from_central(fp_test) |
| 509 | + self.assertTrue(exists(fp_obs)) |
| 510 | + |
| 511 | + # delete file and test if it is gone |
| 512 | + fp_deleted = self.qclient.delete_file_from_central(fp_test) |
| 513 | + if protocol == 'filesystem': |
| 514 | + # all three fp should point to the same filepath |
| 515 | + self.assertFalse(exists(fp_obs)) |
| 516 | + self.assertFalse(exists(fp_test)) |
| 517 | + self.assertFalse(exists(fp_deleted)) |
| 518 | + elif protocol == 'https': |
| 519 | + # as of 2025-09-26, I don't allow deletion of qiita main files |
| 520 | + # through API endpoints. Thus, the file is NOT deleted! |
| 521 | + # local version of the file |
| 522 | + self.assertTrue(exists(fp_test)) |
| 523 | + # qiita main filepath |
| 524 | + self.assertTrue(exists(fp_obs)) |
| 525 | + # qiita main filepath, returned by delete_file_from_central |
| 526 | + self.assertTrue(exists(fp_deleted)) |
| 527 | + |
491 | 528 |
|
492 | 529 | if __name__ == '__main__': |
493 | 530 | main() |
0 commit comments