Skip to content

Commit 891d43b

Browse files
authored
Merge pull request #4 from jlab/enable_pluginprotocol_change_delete
allow for file/dir deletion in test mode
2 parents 9639d56 + 6a13ca0 commit 891d43b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

qiita_client/qiita_client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,13 @@ def push_file_to_central(self, filepath):
897897
def delete_file_from_central(self, filepath):
898898
"""Deletes a file in Qiita's central BASE_DATA_DIR directory.
899899
900-
I currently (2025-09-25) assess this operation to be too dangerous for
900+
I currently (2025-11-12) assess this operation to be too dangerous for
901901
protocols other than "filesystem", i.e. on "https" the files are NOT
902902
deleted.
903-
However, this might change in the future and since I don't want to
903+
However, in plugin tests, this function is needed and I therefore
904+
implemented an API endpoint which is only activated when Qiita main
905+
instance is operated in test mode.
906+
This might change in the future and since I don't want to
904907
touch every plugin's code again, I am adding this function here already
905908
and use it in according plugin code locations, e.g. function _gzip_file
906909
in qtp-sequencing.
@@ -916,8 +919,15 @@ def delete_file_from_central(self, filepath):
916919
The given filepath - to be transparent in plugin code.
917920
"""
918921
if self._plugincoupling == 'filesystem':
919-
os.remove(filepath)
922+
if os.path.isdir(filepath):
923+
shutil.rmtree(filepath)
924+
else:
925+
os.remove(filepath)
920926
elif self._plugincoupling == 'https':
921-
pass
927+
# will return in internal server error, when qiita is in productive
928+
# mode
929+
self.get(
930+
'/cloud/delete_file_from_central/' + filepath,
931+
rettype='object')
922932

923933
return filepath

qiita_client/tests/test_qiita_client.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -511,20 +511,10 @@ def test_delete_file_from_central(self):
511511

512512
# delete file and test if it is gone
513513
fp_deleted = self.qclient.delete_file_from_central(fp_test)
514-
if protocol == 'filesystem':
515-
# all three fp should point to the same filepath
516-
self.assertFalse(exists(fp_obs))
517-
self.assertFalse(exists(fp_test))
518-
self.assertFalse(exists(fp_deleted))
519-
elif protocol == 'https':
520-
# as of 2025-09-26, I don't allow deletion of qiita main files
521-
# through API endpoints. Thus, the file is NOT deleted!
522-
# local version of the file
523-
self.assertTrue(exists(fp_test))
524-
# qiita main filepath
525-
self.assertTrue(exists(fp_obs))
526-
# qiita main filepath, returned by delete_file_from_central
527-
self.assertTrue(exists(fp_deleted))
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))
528518

529519
def test_fetch_directory(self):
530520
# a bit hacky, but should work as long as test database does not change

0 commit comments

Comments
 (0)