Skip to content

Commit 2294c3f

Browse files
antgonzaElDeveloper
authored andcommitted
fix 55.py (#2168)
* fix 55.py * fixing small bug in test env * addressing @ElDeveloper comments * config_test.cfg * rm /test_data/ from folders * fixing * releases * working_dir/releases * working_dir/
1 parent 9a378bc commit 2294c3f

File tree

6 files changed

+35
-23
lines changed

6 files changed

+35
-23
lines changed

qiita_core/support_files/config_test.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ REQUIRE_APPROVAL = True
2626
BASE_URL = https://localhost:21174
2727

2828
# Download path files
29-
UPLOAD_DATA_DIR = /tmp/
29+
UPLOAD_DATA_DIR = /home/travis/miniconda3/envs/qiita/lib/python2.7/site-packages/qiita_db/support_files/test_data/uploads/
3030

3131
# Working directory path
32-
WORKING_DIR = /tmp/
32+
WORKING_DIR = /home/travis/miniconda3/envs/qiita/lib/python2.7/site-packages/qiita_db/support_files/test_data/working_dir/
3333

3434
# Maximum upload size (in Gb)
3535
MAX_UPLOAD_SIZE = 100

qiita_db/artifact.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
from itertools import chain
1212
from datetime import datetime
1313
from os import remove, makedirs
14-
from os.path import isfile, exists
14+
from os.path import isfile, exists, relpath
1515
from shutil import rmtree
1616
from functools import partial
1717

1818
import networkx as nx
1919

2020
import qiita_db as qdb
2121

22+
from qiita_core.qiita_settings import qiita_config
23+
2224

2325
class Artifact(qdb.base.QiitaObject):
2426
r"""Any kind of file (or group of files) stored in the system and its
@@ -154,11 +156,17 @@ def create_type(name, description, can_be_submitted_to_ebi,
154156
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
155157

156158
# When creating a type is expected that a new mountpoint is created
157-
# for that type
159+
# for that type, note that we are going to check if there is an
160+
# extra path for the mountpoint, which is useful for the test
161+
# environment
162+
qc = qiita_config
163+
mp = relpath(qc.working_dir, qc.base_data_dir).replace(
164+
'working_dir', '')
165+
mp = mp + name if mp != '/' and mp != '' else name
158166
sql = """INSERT INTO qiita.data_directory
159167
(data_type, mountpoint, subdirectory, active)
160168
VALUES (%s, %s, %s, %s)"""
161-
qdb.sql_connection.TRN.add(sql, [name, name, True, True])
169+
qdb.sql_connection.TRN.add(sql, [name, mp, True, True])
162170

163171
# We are intersted in the dirpath
164172
dp = qdb.util.get_mountpoint(name)[0][1]

qiita_db/support_files/patches/55.sql

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
-- Jul 6, 2017
22
-- DELETE all sample/prep CONSTRAINTs
33

4-
-- Step 1, remove all FK constraints from study_sample
5-
CREATE OR REPLACE FUNCTION qiita.delete_study_sample_constraints(cname text, tname text) RETURNS void AS $$
6-
BEGIN
7-
EXECUTE 'ALTER TABLE ' || tname || ' DROP CONSTRAINT ' || cname;
8-
END;
9-
$$ LANGUAGE plpgsql;
10-
11-
WITH query AS (
12-
SELECT constraint_name AS cname, 'qiita.' || table_name AS tname
13-
FROM information_schema.table_constraints
14-
WHERE constraint_type ='FOREIGN KEY' AND (
15-
(constraint_name LIKE 'fk_sample_%' AND table_name LIKE 'sample_%') OR
16-
(constraint_name LIKE 'fk_prep_%' AND table_name LIKE 'prep_%')) AND
17-
table_name NOT IN ('prep_template', 'prep_template_sample',
18-
'prep_template_filepath', 'prep_template_processing_job'))
19-
SELECT qiita.delete_study_sample_constraints(cname, tname) FROM query;
20-
21-
DROP FUNCTION qiita.delete_study_sample_constraints(cname text, tname text);
4+
SELECT 42;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from qiita_db.sql_connection import TRN
2+
3+
sql = """
4+
SELECT constraint_name AS cname, 'qiita.' || table_name AS tname
5+
FROM information_schema.table_constraints
6+
WHERE constraint_type ='FOREIGN KEY' AND (
7+
(constraint_name LIKE 'fk_sample_%' AND table_name LIKE 'sample_%') OR
8+
(constraint_name LIKE 'fk_prep_%' AND table_name LIKE 'prep_%')) AND
9+
table_name NOT IN (
10+
'prep_template', 'prep_template_sample', 'prep_template_filepath',
11+
'prep_template_processing_job')"""
12+
13+
with TRN:
14+
TRN.add(sql)
15+
to_delete = TRN.execute_fetchindex()
16+
17+
for cname, tname in to_delete:
18+
with TRN:
19+
sql = "ALTER TABLE %s DROP CONSTRAINT %s" % (tname, cname)
20+
TRN.add(sql)
21+
TRN.execute()

qiita_db/support_files/test_data/working_dir/.keep

Whitespace-only changes.

qiita_db/support_files/test_data/working_dir/releases/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)