Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rm not used in main system #1980

Merged
merged 2 commits into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions qiita_db/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -211,16 +209,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,
Expand Down
44 changes: 18 additions & 26 deletions qiita_db/test/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"}
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down