diff --git a/qiita_db/job.py b/qiita_db/job.py index c583ddddd..2cb016717 100644 --- a/qiita_db/job.py +++ b/qiita_db/job.py @@ -26,10 +26,8 @@ # ----------------------------------------------------------------------------- from __future__ import division from json import loads -from os.path import join, relpath, isdir -from os import remove +from os.path import join, relpath from glob import glob -from shutil import rmtree from functools import partial from collections import defaultdict @@ -213,16 +211,6 @@ def delete(cls, jobid): qdb.sql_connection.TRN.execute() - # remove files/folders attached to job - _, basedir = qdb.util.get_mountpoint("job")[0] - path_builder = partial(join, basedir) - for fp, _ in filepaths: - fp = path_builder(fp) - if isdir(fp): - qdb.sql_connection.TRN.add_post_commit_func(rmtree, fp) - else: - qdb.sql_connection.TRN.add_post_commit_func(remove, fp) - @classmethod def create(cls, datatype, command, options, analysis, input_file_reference, input_file_software_command, diff --git a/qiita_db/test/test_job.py b/qiita_db/test/test_job.py index f255b8566..2d097e70c 100644 --- a/qiita_db/test/test_job.py +++ b/qiita_db/test/test_job.py @@ -8,7 +8,7 @@ from unittest import TestCase, main from os import remove, mkdir -from os.path import join, exists +from os.path import join, exists, isdir from shutil import rmtree from datetime import datetime @@ -22,7 +22,6 @@ class JobTest(TestCase): def setUp(self): self._delete_path = [] - self._delete_dir = [] # creating a new job for testing self.options = {"option1": False, "option2": 25, "option3": "NEW"} @@ -44,6 +43,7 @@ def setUp(self): self.job.add_results([(self.fp, "plain_text")]) # folder self.dfp = join(self._job_folder, "my_folder") + self._delete_path.append(self.dfp) self.ffp = join(self.dfp, "%d_file_in_folder.html" % self.job_id) if not exists(self.dfp): mkdir(self.dfp) @@ -53,12 +53,12 @@ def setUp(self): self.job.add_results([(self.dfp, "directory")]) def tearDown(self): - # needs to be this way because map does not play well with remove and - # rmtree for python3 - for item in self._delete_path: - remove(item) - for item in self._delete_dir: - rmtree(item) + for path in self._delete_path: + if exists(path): + if isdir(path): + rmtree(path) + else: + remove(path) if qdb.job.Job.exists(*self.job_create_params): qdb.job.Job.delete(self.job_id) @@ -147,24 +147,6 @@ def test_get_commands(self): ] self.assertEqual(qdb.job.Job.get_commands(), exp) - def test_delete_files_and_folders(self): - qdb.job.Job.delete(self.job_id) - with self.assertRaises(qdb.exceptions.QiitaDBUnknownIDError): - qdb.job.Job(self.job_id) - - obs = self.conn_handler.execute_fetchall( - "SELECT * FROM qiita.job_results_filepath WHERE job_id = " - "%d" % self.job_id) - self.assertEqual(obs, []) - - obs = self.conn_handler.execute_fetchall( - "SELECT * FROM qiita.analysis_job WHERE job_id = %d" % self.job_id) - self.assertEqual(obs, []) - - self.assertFalse(exists(self.fp)) - self.assertFalse(exists(self.ffp)) - self.assertFalse(exists(self.dfp)) - def test_create(self): """Makes sure creation works as expected""" # make first job @@ -377,6 +359,16 @@ def setUp(self): "Metagenomic": [com2, com3], } + self._delete_path = [] + + def tearDown(self): + for path in self._delete_path: + if exists(path): + if isdir(path): + rmtree(path) + else: + remove(path) + def test_get_commands_by_datatype(self): obs = qdb.job.Command.get_commands_by_datatype() self.assertEqual(obs, self.all_comms)