Skip to content

Commit

Permalink
Merge pull request #1289 from Sage-Bionetworks/develop-api-test-cred-…
Browse files Browse the repository at this point in the history
…markers

Develop markers for api tests according to credentials required FDS-1026
  • Loading branch information
GiaJordan authored Sep 15, 2023
2 parents ca5f293 + c1f8780 commit 135cfb2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,13 @@ markers = [
"""\
rule_benchmark: marks tests covering \
validation rule benchmarking
"""
""",
"""\
synapse_credentials_needed: marks api tests that \
require synapse credentials to run
""",
"""\
empty_token: marks api tests that \
send empty credentials in the request
"""
]
20 changes: 20 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def syn_token(config:Configuration):

@pytest.mark.schematic_api
class TestSynapseStorage:
@pytest.mark.synapse_credentials_needed
@pytest.mark.parametrize("return_type", ["json", "csv"])
def test_get_storage_assets_tables(self, client, syn_token, return_type):
params = {
Expand All @@ -120,6 +121,8 @@ def test_get_storage_assets_tables(self, client, syn_token, return_type):
os.remove(response_dt)
else:
pass

@pytest.mark.synapse_credentials_needed
@pytest.mark.parametrize("full_path", [True, False])
@pytest.mark.parametrize("file_names", [None, "Sample_A.txt"])
def test_get_dataset_files(self,full_path, file_names, syn_token, client):
Expand Down Expand Up @@ -150,6 +153,7 @@ def test_get_dataset_files(self,full_path, file_names, syn_token, client):
else:
assert ["syn25705259","Boolean Test"] and ["syn23667202","DataTypeX_table"] in response_dt

@pytest.mark.synapse_credentials_needed
def test_get_storage_project_dataset(self, syn_token, client):
params = {
"access_token": syn_token,
Expand All @@ -162,6 +166,7 @@ def test_get_storage_project_dataset(self, syn_token, client):
response_dt = json.loads(response.data)
assert ["syn26251193","Issue522"] in response_dt

@pytest.mark.synapse_credentials_needed
def test_get_storage_project_manifests(self, syn_token, client):

params = {
Expand All @@ -174,6 +179,7 @@ def test_get_storage_project_manifests(self, syn_token, client):

assert response.status_code == 200

@pytest.mark.synapse_credentials_needed
def test_get_storage_projects(self, syn_token, client):

params = {
Expand All @@ -185,6 +191,7 @@ def test_get_storage_projects(self, syn_token, client):

assert response.status_code == 200

@pytest.mark.synapse_credentials_needed
@pytest.mark.parametrize("entity_id", ["syn34640850", "syn23643253", "syn24992754"])
def test_get_entity_type(self, syn_token, client, entity_id):
params = {
Expand All @@ -203,6 +210,7 @@ def test_get_entity_type(self, syn_token, client, entity_id):
elif entity_id == "syn24992754":
assert response_dt == "project"

@pytest.mark.synapse_credentials_needed
@pytest.mark.parametrize("entity_id", ["syn30988314", "syn27221721"])
def test_if_in_assetview(self, syn_token, client, entity_id):
params = {
Expand Down Expand Up @@ -399,6 +407,7 @@ def ifPandasDataframe(self, response_dt):
assert isinstance(df, pd.DataFrame)


@pytest.mark.empty_token
#@pytest.mark.parametrize("output_format", [None, "excel", "google_sheet", "dataframe (only if getting existing manifests)"])
@pytest.mark.parametrize("output_format", ["excel"])
@pytest.mark.parametrize("data_type", ["Biospecimen", "Patient", "all manifests", ["Biospecimen", "Patient"]])
Expand Down Expand Up @@ -455,6 +464,7 @@ def test_generate_existing_manifest(self, client, data_model_jsonld, data_type,
self.ifGoogleSheetExists(response_dt)


@pytest.mark.empty_token
@pytest.mark.parametrize("output_format", ["excel", "google_sheet", "dataframe (only if getting existing manifests)", None])
@pytest.mark.parametrize("data_type", ["all manifests", ["Biospecimen", "Patient"], "Patient"])
def test_generate_new_manifest(self, caplog, client, data_model_jsonld, data_type, output_format):
Expand Down Expand Up @@ -621,6 +631,7 @@ def test_validate_manifest(self, data_model_jsonld, client, json_str, restrict_r
assert "errors" in response_dt.keys()
assert "warnings" in response_dt.keys()

@pytest.mark.synapse_credentials_needed
def test_get_datatype_manifest(self, client, syn_token):
params = {
"access_token": syn_token,
Expand All @@ -642,6 +653,7 @@ def test_get_datatype_manifest(self, client, syn_token):
"Year of Birth": "Int64",
"entityId": "string"}

@pytest.mark.synapse_credentials_needed
# small manifest: syn51078535; big manifest: syn51156998
@pytest.mark.parametrize("manifest_id, expected_component, expected_file_name", [("syn51078535", "BulkRNA-seqAssay", "synapse_storage_manifest.csv"), ("syn51156998", "Biospecimen", "synapse_storage_manifest_biospecimen.csv")])
@pytest.mark.parametrize("new_manifest_name",[None,"Example.csv"])
Expand Down Expand Up @@ -694,6 +706,8 @@ def test_manifest_download(self, config: Configuration, client, syn_token, manif
os.remove(manifest_file_path)
except:
pass

@pytest.mark.synapse_credentials_needed
# test downloading a manifest with access restriction and see if the correct error message got raised
def test_download_access_restricted_manifest(self, client, syn_token):
params = {
Expand All @@ -707,6 +721,7 @@ def test_download_access_restricted_manifest(self, client, syn_token):
raise TypeError('the type error got raised')
assert exc_info.value.args[0] == "the type error got raised"

@pytest.mark.synapse_credentials_needed
@pytest.mark.parametrize("as_json", [None, True, False])
@pytest.mark.parametrize("new_manifest_name", [None, "Test"])
def test_dataset_manifest_download(self, client, as_json, syn_token, new_manifest_name):
Expand Down Expand Up @@ -735,6 +750,7 @@ def test_dataset_manifest_download(self, client, as_json, syn_token, new_manifes
assert isinstance(response_path, str)
assert response_path.endswith(".csv")

@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_table_and_file_replace(self, client, syn_token, data_model_jsonld, test_manifest_submit):
"""Testing submit manifest in a csv format as a table and a file. Only replace the table
Expand All @@ -755,6 +771,7 @@ def test_submit_manifest_table_and_file_replace(self, client, syn_token, data_mo
response_csv = client.post('http://localhost:3001/v1/model/submit', query_string=params, data={"file_name": (open(test_manifest_submit, 'rb'), "test.csv")})
assert response_csv.status_code == 200

@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_file_only_replace(self, client, syn_token, data_model_jsonld, test_manifest_submit):
"""Testing submit manifest in a csv format as a file
Expand All @@ -773,6 +790,7 @@ def test_submit_manifest_file_only_replace(self, client, syn_token, data_model_j
response_csv = client.post('http://localhost:3001/v1/model/submit', query_string=params, data={"file_name": (open(test_manifest_submit, 'rb'), "test.csv")})
assert response_csv.status_code == 200

@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_json_str_replace(self, client, syn_token, data_model_jsonld):
"""Submit json str as a file
Expand All @@ -794,6 +812,7 @@ def test_submit_manifest_json_str_replace(self, client, syn_token, data_model_js
response = client.post('http://localhost:3001/v1/model/submit', query_string = params, data={"file_name":''})
assert response.status_code == 200

@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_w_file_and_entities(self, client, syn_token, data_model_jsonld, test_manifest_submit):
params = {
Expand All @@ -812,6 +831,7 @@ def test_submit_manifest_w_file_and_entities(self, client, syn_token, data_model
response_csv = client.post('http://localhost:3001/v1/model/submit', query_string=params, data={"file_name": (open(test_manifest_submit, 'rb'), "test.csv")})
assert response_csv.status_code == 200

@pytest.mark.synapse_credentials_needed
@pytest.mark.submission
def test_submit_manifest_table_and_file_upsert(self, client, syn_token, data_model_jsonld, test_upsert_manifest_csv, ):
params = {
Expand Down

0 comments on commit 135cfb2

Please sign in to comment.