|
10 | 10 | from tempfile import mkstemp, mkdtemp
|
11 | 11 | from datetime import datetime
|
12 | 12 | from os import close, remove
|
13 |
| -from os.path import exists, join, basename |
| 13 | +from os.path import exists, join, basename, dirname, abspath |
14 | 14 | from shutil import copyfile
|
15 | 15 | from functools import partial
|
16 | 16 | from json import dumps
|
|
23 | 23 | from qiita_core.util import qiita_test_checker
|
24 | 24 | from qiita_core.testing import wait_for_processing_job
|
25 | 25 | import qiita_db as qdb
|
| 26 | +from qiita_ware.private_plugin import _delete_analysis_artifacts |
26 | 27 |
|
27 | 28 |
|
28 | 29 | class ArtifactTestsReadOnly(TestCase):
|
@@ -1518,15 +1519,57 @@ def test_archive(self):
|
1518 | 1519 | 'be archived'):
|
1519 | 1520 | A.archive(8)
|
1520 | 1521 |
|
1521 |
| - for aid in range(4, 7): |
| 1522 | + for aid in range(5, 7): |
1522 | 1523 | ms = A(aid).merging_scheme
|
1523 | 1524 | A.archive(aid)
|
1524 | 1525 | self.assertEqual(ms, A(aid).merging_scheme)
|
1525 | 1526 | exp_nodes.remove(A(aid))
|
1526 | 1527 | self.assertCountEqual(A(1).descendants.nodes(), exp_nodes)
|
1527 | 1528 |
|
1528 | 1529 | obs_artifacts = len(qdb.util.get_artifacts_information([4, 5, 6, 8]))
|
1529 |
| - self.assertEqual(1, obs_artifacts) |
| 1530 | + self.assertEqual(2, obs_artifacts) |
| 1531 | + |
| 1532 | + # in the tests above we generated and validated archived artifacts |
| 1533 | + # so this allows us to add tests to delete a prep-info with archived |
| 1534 | + # artifacts. The first bottleneck to do this is that this tests will |
| 1535 | + # actually remove files, which we will need for other tests so lets |
| 1536 | + # make a copy and then restore them |
| 1537 | + mfolder = dirname(dirname(abspath(__file__))) |
| 1538 | + mpath = join(mfolder, 'support_files', 'test_data') |
| 1539 | + mp = partial(join, mpath) |
| 1540 | + fps = [ |
| 1541 | + mp('processed_data/1_study_1001_closed_reference_otu_table.biom'), |
| 1542 | + mp('processed_data/' |
| 1543 | + '1_study_1001_closed_reference_otu_table_Silva.biom'), |
| 1544 | + mp('raw_data/1_s_G1_L001_sequences.fastq.gz'), |
| 1545 | + mp('raw_data/1_s_G1_L001_sequences_barcodes.fastq.gz')] |
| 1546 | + for fp in fps: |
| 1547 | + copyfile(fp, f'{fp}.bk') |
| 1548 | + |
| 1549 | + PT = qdb.metadata_template.prep_template.PrepTemplate |
| 1550 | + QEE = qdb.exceptions.QiitaDBExecutionError |
| 1551 | + pt = A(1).prep_templates[0] |
| 1552 | + # it should fail as this prep is public and have been submitted to ENA |
| 1553 | + with self.assertRaisesRegex(QEE, 'Cannot remove prep template 1'): |
| 1554 | + PT.delete(pt.id) |
| 1555 | + # now, remove those restrictions + analysis + linked artifacts |
| 1556 | + sql = "DELETE FROM qiita.artifact_processing_job" |
| 1557 | + qdb.sql_connection.perform_as_transaction(sql) |
| 1558 | + sql = "DELETE FROM qiita.ebi_run_accession" |
| 1559 | + qdb.sql_connection.perform_as_transaction(sql) |
| 1560 | + sql = "UPDATE qiita.artifact SET visibility_id = 1" |
| 1561 | + qdb.sql_connection.perform_as_transaction(sql) |
| 1562 | + _delete_analysis_artifacts(qdb.analysis.Analysis(1)) |
| 1563 | + _delete_analysis_artifacts(qdb.analysis.Analysis(2)) |
| 1564 | + _delete_analysis_artifacts(qdb.analysis.Analysis(3)) |
| 1565 | + for aid in [3, 2, 1]: |
| 1566 | + A.delete(aid) |
| 1567 | + |
| 1568 | + PT.delete(pt.id) |
| 1569 | + |
| 1570 | + # bringing back the filepaths |
| 1571 | + for fp in fps: |
| 1572 | + copyfile(f'{fp}.bk', fp) |
1530 | 1573 |
|
1531 | 1574 |
|
1532 | 1575 | if __name__ == '__main__':
|
|
0 commit comments