Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": null,
"lines": null
},
"generated_at": "2021-12-21T20:46:37Z",
"generated_at": "2022-01-26T15:40:06Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down
18 changes: 12 additions & 6 deletions tests/integration/datadict/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,22 @@ def teardown():
return _app


@pytest.fixture(params=[False, True, None])
@pytest.fixture()
def use_ssl(request):
# return False, True, None
return request.param
try:
# one of [False, True, None]
return request.param
except:
return None


@pytest.fixture(params=("READ_COMMITTED", "REPEATABLE_READ", "SERIALIZABLE", None))
@pytest.fixture()
def isolation_level(request):
# return 'READ_COMMITTED', 'REPEATABLE_READ', 'SERIALIZABLE', None
return request.param
try:
# one of ["READ_COMMITTED", "REPEATABLE_READ", "SERIALIZABLE", None]
return request.param
except:
return None


@pytest.fixture
Expand Down
42 changes: 21 additions & 21 deletions tests/integration/datadict/submission/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def put_example_entities_together(client, headers):
return client.put(path, headers=headers, data=json.dumps(data))


def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter):
def do_test_post_example_entities_together(client, submitter):
with open(os.path.join(DATA_DIR, "case.json"), "r") as f:
case_sid = json.loads(f.read())["submitter_id"]
print(case_sid)
Expand All @@ -356,6 +356,10 @@ def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter
assert condition_to_check, resp.data


def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter):
do_test_post_example_entities_together(client, submitter)


def test_dictionary_list_entries(client, pg_driver, cgci_blgsp, submitter):
resp = client.get("/v0/submission/CGCI/BLGSP/_dictionary")
print(resp.data)
Expand Down Expand Up @@ -505,7 +509,7 @@ def test_disallow_cross_project_references(client, pg_driver, cgci_blgsp, submit
assert resp.status_code == 400, resp.data


def test_delete_entity(client, pg_driver, cgci_blgsp, submitter):
def do_test_delete_entity(client, submitter):
resp = client.put(
BLGSP_PATH,
headers=submitter,
Expand All @@ -524,6 +528,10 @@ def test_delete_entity(client, pg_driver, cgci_blgsp, submitter):
assert resp.status_code == 200, resp.data


def test_delete_entity(client, pg_driver, cgci_blgsp, submitter):
do_test_delete_entity(client, submitter)


def test_catch_internal_errors(monkeypatch, client, pg_driver, cgci_blgsp, submitter):
"""
Monkey patch an essential function to just raise an error and assert that
Expand Down Expand Up @@ -698,7 +706,7 @@ def test_valid_file_index(
assert index_client.get(sur_entity["id"]), "No indexd document created"


def test_submit_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
def do_test_submit_valid_tsv(client, submitter):
"""
Test that we can submit a valid TSV file
"""
Expand All @@ -710,9 +718,7 @@ def test_submit_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
}

# convert to TSV (save to file)
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data/experiment_tmp.tsv"
)
file_path = os.path.join(DATA_DIR, "experiment_tmp.tsv")
with open(file_path, "w") as f:
dw = csv.DictWriter(f, sorted(data.keys()), delimiter="\t")
dw.writeheader()
Expand All @@ -731,6 +737,10 @@ def test_submit_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
assert resp.status_code == 200, resp.data


def test_submit_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
do_test_submit_valid_tsv(client, submitter)


def test_submit_valid_csv(client, pg_driver, cgci_blgsp, submitter):
"""
Test that we can submit a valid CSV file
Expand Down Expand Up @@ -792,9 +802,7 @@ def test_can_submit_with_asterisk_tsv(client, pg_driver, cgci_blgsp, submitter):
"*projects.id": "daa208a7-f57a-562c-a04a-7a7c77542c98",
}
# convert to TSV (save to file)
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data/experiment_tmp.tsv"
)
file_path = os.path.join(DATA_DIR, "experiment_tmp.tsv")
with open(file_path, "w") as f:
dw = csv.DictWriter(f, sorted(data.keys()), delimiter="\t")
dw.writeheader()
Expand Down Expand Up @@ -1038,9 +1046,7 @@ def test_duplicate_submission(app, pg_driver, cgci_blgsp, submitter):
}

# convert to TSV (save to file)
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data/experiment_tmp.tsv"
)
file_path = os.path.join(DATA_DIR, "experiment_tmp.tsv")
with open(file_path, "w") as f:
dw = csv.DictWriter(f, sorted(data.keys()), delimiter="\t")
dw.writeheader()
Expand Down Expand Up @@ -1149,9 +1155,7 @@ def test_zero_decimal_float(client, pg_driver, cgci_blgsp, submitter):
}

# convert to TSV (save to file)
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data/experiment_tmp.tsv"
)
file_path = os.path.join(DATA_DIR, "experiment_tmp.tsv")
with open(file_path, "w") as f:
dw = csv.DictWriter(f, sorted(data.keys()), delimiter="\t")
dw.writeheader()
Expand Down Expand Up @@ -1302,9 +1306,7 @@ def test_update_to_null_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
}

# convert to TSV (save to file)
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data/experiment_tmp.tsv"
)
file_path = os.path.join(DATA_DIR, "experiment_tmp.tsv")
with open(file_path, "w") as f:
dw = csv.DictWriter(f, sorted(data.keys()), delimiter="\t")
dw.writeheader()
Expand Down Expand Up @@ -1368,9 +1370,7 @@ def test_update_to_null_invalid_tsv(client, pg_driver, cgci_blgsp, submitter):
}

# convert to TSV (save to file)
file_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data/experiment_tmp.tsv"
)
file_path = os.path.join(DATA_DIR, "experiment_tmp.tsv")
with open(file_path, "w") as f:
dw = csv.DictWriter(f, sorted(data.keys()), delimiter="\t")
dw.writeheader()
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/datadict/test_ssl_and_isolation_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Copy of a few functional tests in order to test that SSL and isolation level
settings work.
"""

import pytest

from tests.integration.datadict.submission.test_endpoints import (
do_test_post_example_entities_together,
do_test_delete_entity,
do_test_submit_valid_tsv,
do_test_export,
)


USE_SSL = [False, True, None]
ISOLATION_LEVELS = ["READ_COMMITTED", "REPEATABLE_READ", "SERIALIZABLE", None]


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter):
do_test_post_example_entities_together(client, submitter)


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_delete_entity(client, pg_driver, cgci_blgsp, submitter):
do_test_delete_entity(client, submitter)


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_submit_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
do_test_submit_valid_tsv(client, submitter)


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_export_all_node_types(
client, pg_driver, cgci_blgsp, submitter, require_index_exists_off
):
do_test_export(client, pg_driver, submitter, "experimental_metadata", "tsv")
18 changes: 12 additions & 6 deletions tests/integration/datadictwithobjid/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,22 @@ def teardown():
return _app


@pytest.fixture(params=[None, False, True])
@pytest.fixture()
def use_ssl(request):
# return None, False, True
return request.param
try:
# one of [False, True, None]
return request.param
except:
return None


@pytest.fixture(params=("READ_COMMITTED", "REPEATABLE_READ", "SERIALIZABLE", None))
@pytest.fixture()
def isolation_level(request):
# return 'READ_COMMITTED', 'REPEATABLE_READ', 'SERIALIZABLE', None
return request.param
try:
# one of ["READ_COMMITTED", "REPEATABLE_READ", "SERIALIZABLE", None]
return request.param
except:
return None


@pytest.fixture
Expand Down
26 changes: 9 additions & 17 deletions tests/integration/datadictwithobjid/submission/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
from moto import mock_s3
from datamodelutils import models as md
from sheepdog.transactions.upload import UploadTransaction

from tests.integration.datadict.submission.utils import data_fnames
from tests.integration.datadictwithobjid.submission.utils import extended_data_fnames
from tests.integration.datadict.submission.test_endpoints import (
do_test_export,
)

BLGSP_PATH = "/v0/submission/CGCI/BLGSP/"
BRCA_PATH = "/v0/submission/TCGA/BRCA/"
Expand Down Expand Up @@ -355,7 +359,7 @@ def put_example_entities_together(client, headers):
return client.put(path, headers=headers, data=json.dumps(data))


def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter):
def do_test_post_example_entities_together(client, submitter):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not importing it from datadict because the datadictwithobjid test data might be different

with open(os.path.join(DATA_DIR, "case.json"), "r") as f:
case_sid = json.loads(f.read())["submitter_id"]
assert case_sid
Expand All @@ -371,6 +375,10 @@ def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter
assert condition_to_check, resp.data


def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter):
do_test_post_example_entities_together(client, submitter)


def test_dictionary_list_entries(client, pg_driver, cgci_blgsp, submitter):
resp = client.get("/v0/submission/CGCI/BLGSP/_dictionary")
print(resp.data)
Expand Down Expand Up @@ -708,22 +716,6 @@ def test_export_entity_by_id(client, pg_driver, cgci_blgsp, submitter):
assert data[0]["id"] == case_id


def do_test_export(client, pg_driver, submitter, node_type, format_type):
post_example_entities_together(client, submitter, extended_data_fnames)
experimental_metadata_count = add_and_get_new_experimental_metadata_count(pg_driver)
r = get_export_data(client, submitter, node_type, format_type, False)
assert r.status_code == 200, r.data
assert r.headers["Content-Disposition"].endswith(format_type)
if format_type == "tsv":
str_data = str(r.data, "utf-8")
assert len(str_data.strip().split("\n")) == experimental_metadata_count + 1
return str_data
else:
js_data = json.loads(r.data)
assert len(js_data["data"]) == experimental_metadata_count
return js_data


def get_export_data(client, submitter, node_type, format_type, without_id):
path = "/v0/submission/CGCI/BLGSP/export/?node_label={}&format={}".format(
node_type, format_type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Copy of a few functional tests in order to test that SSL and isolation level
settings work.
"""

import pytest

from tests.integration.datadictwithobjid.submission.test_endpoints import (
do_test_post_example_entities_together,
)
from tests.integration.datadict.submission.test_endpoints import (
do_test_delete_entity,
do_test_submit_valid_tsv,
do_test_export,
)


USE_SSL = [False, True, None]
ISOLATION_LEVELS = ["READ_COMMITTED", "REPEATABLE_READ", "SERIALIZABLE", None]


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_post_example_entities_together(client, pg_driver, cgci_blgsp, submitter):
do_test_post_example_entities_together(client, submitter)


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_delete_entity(client, pg_driver, cgci_blgsp, submitter):
do_test_delete_entity(client, submitter)


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_submit_valid_tsv(client, pg_driver, cgci_blgsp, submitter):
do_test_submit_valid_tsv(client, submitter)


@pytest.mark.parametrize("use_ssl", USE_SSL, indirect=True)
@pytest.mark.parametrize("isolation_level", ISOLATION_LEVELS, indirect=True)
def test_export_all_node_types(
client, pg_driver, cgci_blgsp, submitter, require_index_exists_off
):
do_test_export(client, pg_driver, submitter, "experimental_metadata", "tsv")