Skip to content

Commit

Permalink
Merge pull request #1488 from Sage-Bionetworks/revert-1464-fds-1132-a…
Browse files Browse the repository at this point in the history
…dd-csv-to-unit-tests

Revert "add csv data model to unit tests"
  • Loading branch information
andrewelamb authored Sep 3, 2024
2 parents bb2606b + ea70811 commit 83c9bc3
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 115 deletions.
102 changes: 40 additions & 62 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,6 @@ def test_manifest_json(helpers) -> str:
return test_manifest_path


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


@pytest.fixture(scope="class")
def benchmark_data_model_jsonld():
benchmark_data_model_jsonld = "https://raw.githubusercontent.com/Sage-Bionetworks/schematic/develop/tests/data/example.single_rule.model.jsonld"
yield benchmark_data_model_jsonld

def get_MockComponent_attribute() -> Generator[str, None, None]:
"""
Yield all of the mock conponent attributes one at a time
Expand Down Expand Up @@ -344,9 +331,9 @@ def test_if_in_assetview(
@pytest.mark.schematic_api
class TestMetadataModelOperation:
@pytest.mark.parametrize("as_graph", [True, False])
def test_component_requirement(self, data_model_url, client: FlaskClient, as_graph: bool) -> None:
def test_component_requirement(self, client: FlaskClient, as_graph: bool) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"source_component": "BulkRNA-seqAssay",
"as_graph": as_graph,
}
Expand Down Expand Up @@ -395,8 +382,8 @@ def test_get_property_label_from_display_name(

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

def test_if_node_required(test, data_model_url, client: FlaskClient) -> None:
def test_if_node_required(test, client: FlaskClient) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"node_display_name": "FamilyHistory",
"data_model_labels": "class_label",
}
Expand All @@ -423,9 +410,9 @@ def test_if_node_required(test, data_model_url, client: FlaskClient) -> None:
assert response.status_code == 200
assert response_dta == True

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

def test_get_nodes_display_names(test, data_model_url, client: FlaskClient) -> None:
def test_get_nodes_display_names(test, client: FlaskClient) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"node_list": ["FamilyHistory", "Biospecimen"],
}
response = client.get(
Expand All @@ -453,8 +440,8 @@ def test_get_nodes_display_names(test, data_model_url, client: FlaskClient) -> N
@pytest.mark.parametrize(
"relationship", ["parentOf", "requiresDependency", "rangeValue", "domainValue"]
)
def test_get_subgraph_by_edge(self, data_model_url, client: FlaskClient, relationship: str) -> None:
params = {"schema_url": data_model_url, "relationship": relationship}
def test_get_subgraph_by_edge(self, client: FlaskClient, relationship: str) -> None:
params = {"schema_url": DATA_MODEL_JSON_LD, "relationship": relationship}

response = client.get(
"http://localhost:3001/v1/schemas/get/graph_by_edge_type",
Expand All @@ -465,10 +452,10 @@ def test_get_subgraph_by_edge(self, data_model_url, client: FlaskClient, relatio
@pytest.mark.parametrize("return_display_names", [True, False])
@pytest.mark.parametrize("node_label", ["FamilyHistory", "TissueStatus"])
def test_get_node_range(
self, data_model_url, client: FlaskClient, return_display_names: bool, node_label: str
self, client: FlaskClient, return_display_names: bool, node_label: str
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"return_display_names": return_display_names,
"node_label": node_label,
}
Expand All @@ -492,7 +479,6 @@ def test_get_node_range(
@pytest.mark.parametrize("source_node", ["Patient", "Biospecimen"])
def test_node_dependencies(
self,
data_model_url,
client: FlaskClient,
source_node: str,
return_display_names: Union[bool, None],
Expand All @@ -502,7 +488,7 @@ def test_node_dependencies(
return_schema_ordered = False

params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"source_node": source_node,
"return_display_names": return_display_names,
"return_schema_ordered": return_schema_ordered,
Expand Down Expand Up @@ -568,8 +554,7 @@ def ifPandasDataframe(self, response_dt):
["Biospecimen", "Patient", "all manifests", ["Biospecimen", "Patient"]],
)
def test_generate_existing_manifest(
self,,
data_model_url,
self,
client: FlaskClient,
data_type: str,
output_format: str,
Expand All @@ -587,7 +572,7 @@ def test_generate_existing_manifest(
dataset_id = None # if "all manifests", dataset id is None

params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"asset_view": "syn23643253",
"title": "Example",
"data_type": data_type,
Expand Down Expand Up @@ -653,15 +638,14 @@ def test_generate_existing_manifest(
)
def test_generate_new_manifest(
self,
data_model_url
caplog: pytest.LogCaptureFixture,
client: FlaskClient,
data_type: str,
output_format: str,
request_headers: Dict[str, str],
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"asset_view": "syn23643253",
"title": "Example",
"data_type": data_type,
Expand Down Expand Up @@ -757,10 +741,10 @@ def test_generate_new_manifest(
],
)
def test_generate_manifest_file_based_annotations(
self, data_model_url, client: FlaskClient, use_annotations: bool, expected: list[str]
self, client: FlaskClient, use_annotations: bool, expected: list[str]
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "BulkRNA-seqAssay",
"dataset_id": "syn25614635",
"asset_view": "syn51707141",
Expand Down Expand Up @@ -807,10 +791,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, data_model_url, client: FlaskClient
self, client: FlaskClient
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "Patient",
"dataset_id": "syn25614635",
"asset_view": "syn51707141",
Expand Down Expand Up @@ -842,9 +826,9 @@ def test_generate_manifest_not_file_based_with_annotations(
]
)

def test_generate_manifest_data_type_not_found(self, data_model_url, client: FlaskClient) -> None:
def test_generate_manifest_data_type_not_found(self, client: FlaskClient) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "wrong data type",
"use_annotations": False,
}
Expand All @@ -856,14 +840,14 @@ def test_generate_manifest_data_type_not_found(self, data_model_url, client: Fla
assert "LookupError" in str(response.data)

def test_populate_manifest(
self, data_model_url, client: FlaskClient, test_manifest_csv: str
self, client: FlaskClient, test_manifest_csv: str
) -> None:
# test manifest
test_manifest_data = open(test_manifest_csv, "rb")

params = {
"data_type": "MockComponent",
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"title": "Example",
"csv_file": test_manifest_data,
}
Expand All @@ -889,14 +873,13 @@ def test_populate_manifest(
)
def test_validate_manifest(
self,
data_model_url,
client: FlaskClient,
json_str: Union[str, None],
restrict_rules: Union[bool, None],
test_manifest_csv: str,
request_headers: Dict[str, str],
) -> None:
params = {"schema_url": data_model_url, "restrict_rules": restrict_rules}
params = {"schema_url": DATA_MODEL_JSON_LD, "restrict_rules": restrict_rules}

if json_str:
params["json_str"] = json_str
Expand Down Expand Up @@ -1093,14 +1076,13 @@ def test_dataset_manifest_download(
@pytest.mark.submission
def test_submit_manifest_table_and_file_replace(
self,
data_model_url,
client: FlaskClient,
request_headers: Dict[str, str],
test_manifest_submit: str,
) -> None:
"""Testing submit manifest in a csv format as a table and a file. Only replace the table"""
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "Biospecimen",
"restrict_rules": False,
"hide_blanks": False,
Expand Down Expand Up @@ -1132,7 +1114,6 @@ def test_submit_manifest_table_and_file_replace(
def test_submit_manifest_file_only_replace(
self,
helpers,
data_model_url,
client: FlaskClient,
request_headers: Dict[str, str],
data_type: str,
Expand All @@ -1141,7 +1122,7 @@ def test_submit_manifest_file_only_replace(
) -> None:
"""Testing submit manifest in a csv format as a file"""
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": data_type,
"restrict_rules": False,
"manifest_record_type": "file_only",
Expand Down Expand Up @@ -1184,12 +1165,12 @@ def test_submit_manifest_file_only_replace(
@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_json_str_replace(
self, cdata_model_url, lient: FlaskClient, request_headers: Dict[str, str]
self, client: FlaskClient, request_headers: Dict[str, str]
) -> None:
"""Submit json str as a file"""
json_str = '[{"Sample ID": 123, "Patient ID": 1,"Tissue Status": "Healthy","Component": "Biospecimen"}]'
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "Biospecimen",
"json_str": json_str,
"restrict_rules": False,
Expand All @@ -1213,13 +1194,12 @@ def test_submit_manifest_json_str_replace(
@pytest.mark.submission
def test_submit_manifest_w_file_and_entities(
self,
data_model_url,
client: FlaskClient,
request_headers: Dict[str, str],
test_manifest_submit: str,
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "Biospecimen",
"restrict_rules": False,
"manifest_record_type": "file_and_entities",
Expand All @@ -1244,13 +1224,12 @@ def test_submit_manifest_w_file_and_entities(
@pytest.mark.submission
def test_submit_manifest_table_and_file_upsert(
self,
data_model_url,
client: FlaskClient,
request_headers: Dict[str, str],
test_upsert_manifest_csv: str,
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"data_type": "MockRDB",
"restrict_rules": False,
"manifest_record_type": "table_and_file",
Expand All @@ -1274,8 +1253,8 @@ def test_submit_manifest_table_and_file_upsert(

@pytest.mark.schematic_api
class TestSchemaVisualization:
def test_visualize_attributes(self, data_model_url, client: FlaskClient) -> None:
params = {"schema_url": data_model_url}
def test_visualize_attributes(self, client: FlaskClient) -> None:
params = {"schema_url": DATA_MODEL_JSON_LD}

response = client.get(
"http://localhost:3001/v1/visualize/attributes", query_string=params
Expand All @@ -1285,10 +1264,10 @@ def test_visualize_attributes(self, data_model_url, client: FlaskClient) -> None

@pytest.mark.parametrize("figure_type", ["component", "dependency"])
def test_visualize_tangled_tree_layers(
self, client: FlaskClient, figure_type: str, data_model_url
self, client: FlaskClient, figure_type: str
) -> None:
# 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_url, "figure_type": figure_type}
params = {"schema_url": DATA_MODEL_JSON_LD, "figure_type": figure_type}

response = client.get(
"http://localhost:3001/v1/visualize/tangled_tree/layers",
Expand Down Expand Up @@ -1393,10 +1372,10 @@ def test_visualize_tangled_tree_layers(
],
)
def test_visualize_component(
self, data_model_url, client: FlaskClient, component: str, response_text: str
self, client: FlaskClient, component: str, response_text: str
) -> None:
params = {
"schema_url": data_model_url,
"schema_url": DATA_MODEL_JSON_LD,
"component": component,
"include_index": False,
"data_model_labels": "class_label",
Expand All @@ -1421,7 +1400,6 @@ class TestValidationBenchmark:
def test_validation_performance(
self,
helpers,
data_model_url,
client: FlaskClient,
test_invalid_manifest: pd.DataFrame,
MockComponent_attribute: Generator[str, None, None],
Expand All @@ -1442,7 +1420,7 @@ def test_validation_performance(

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

0 comments on commit 83c9bc3

Please sign in to comment.