From b5fd47ac8519017c2b1b02264e6ee9c1291f056c Mon Sep 17 00:00:00 2001 From: Cristina Stone Pedraza Date: Tue, 19 Nov 2024 17:02:51 -0800 Subject: [PATCH] Edit test to check specific rows in table --- nmdc_server/api.py | 2 +- tests/test_submission.py | 61 ++++++++++++---------------------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 571a9d4a..348be60b 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -676,7 +676,7 @@ async def get_metadata_submissions_mixs( # Get sample names from each sample type for sample_type in sample_data: samples = sample_data[sample_type] if sample_type in sample_data else [] - # # Iterate through each sample and extract the name + # Iterate through each sample and extract the name for x in samples: # Get the sample name sample_name = x["samp_name"] if "samp_name" in x else "" diff --git a/tests/test_submission.py b/tests/test_submission.py index 673ecf6b..1ec5f0cd 100644 --- a/tests/test_submission.py +++ b/tests/test_submission.py @@ -58,14 +58,6 @@ def test_get_metadata_submissions_mixs(db: Session, client: TestClient, logged_i "env_broad_scale": "Broad Scale B", "env_local_scale": "Local Scale B" } - ], - "water_data": [ - { - "samp_name": "Sample C", - "env_medium": "Medium C", - "env_broad_scale": "Broad Scale C", - "env_local_scale": "Local Scale C" - } ] }, "packageName": "Env Pkg 1" @@ -80,37 +72,6 @@ def test_get_metadata_submissions_mixs(db: Session, client: TestClient, logged_i # including a header. # Reference: https://docs.python.org/3/library/csv.html#csv.DictReader - # Define rows we expect to see in the table - expected_rows = [ - { - "Submission ID":str(submission1.id), - "Status":"Submitted- Pending Review", - "Sample Name":"Sample A", - "Environmental Package/Extension":"Env Pkg 1", - "Environmental Broad Scale":"Broad Scale A", - "Environmental Local Scale":"Local Scale A", - "Environmental Medium":"Medium A", - }, - { - "Submission ID":str(submission1.id), - "Status":"Submitted- Pending Review", - "Sample Name":"Sample B", - "Environmental Package/Extension":"Env Pkg 1", - "Environmental Broad Scale":"Broad Scale B", - "Environmental Local Scale":"Local Scale B", - "Environmental Medium":"Medium B", - }, - { - "Submission ID":str(submission1.id), - "Status":"Submitted- Pending Review", - "Sample Name":"Sample C", - "Environmental Package/Extension":"Env Pkg 2", - "Environmental Broad Scale":"Broad Scale C", - "Environmental Local Scale":"Local Scale C", - "Environmental Medium":"Medium C", - } - ] - fieldnames = [ "Submission ID", "Status", @@ -122,14 +83,28 @@ def test_get_metadata_submissions_mixs(db: Session, client: TestClient, logged_i ] reader = DictReader(response.text.splitlines(), fieldnames=fieldnames, delimiter="\t") rows = [row for row in reader] - assert len(rows) == 4 # including the header row + assert len(rows) == 3 # including the header row header_row = rows[0] # get the header row assert len(list(header_row.keys())) == len(fieldnames) - # Check that all samples in the expected rows appear in the list - assert all(samples in expected_rows for samples in rows) - # assert set(expected_rows).issubset(set(rows)) + data_row = rows[1] # first data row (data about Sample A in submission1) + assert data_row["Submission ID"] == str(submission1.id) + assert data_row["Status"] == "Submitted- Pending Review" + assert data_row["Sample Name"] == "Sample A" + assert data_row["Environmental Package/Extension"] == "Env Pkg 1" + assert data_row["Environmental Broad Scale"] == "Broad Scale A" + assert data_row["Environmental Local Scale"] == "Local Scale A" + assert data_row["Environmental Medium"] == "Medium A" + + data_row = rows[2] # second data row (data about Sample B in submission1) + assert data_row["Submission ID"] == str(submission1.id) + assert data_row["Status"] == "Submitted- Pending Review" + assert data_row["Sample Name"] == "Sample B" + assert data_row["Environmental Package/Extension"] == "Env Pkg 1" + assert data_row["Environmental Broad Scale"] == "Broad Scale B" + assert data_row["Environmental Local Scale"] == "Local Scale B" + assert data_row["Environmental Medium"] == "Medium B" def test_get_metadata_submissions_report_as_non_admin(