-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove pandas from gsaid api #3393
base: master
Are you sure you want to change the base?
Changes from 16 commits
84f208f
7d8d619
b056ad7
029cf08
095574e
5dbbeff
c2cd1c4
2150c07
1735c03
0da7f66
5926546
69ce6f2
3a20a70
2904d9e
bceafdc
a5d21d6
b795184
90c06ef
b1e548b
ca58e05
82644c3
13c0352
26e627f
cab4d11
57e4ddd
dd6c9f1
676f8a4
40a3c1f
97db74f
6869e0d
6ebdfbd
7a22141
d331d12
6dea4dd
64f17b4
3a5a550
a1073ed
259688e
f1c8fb6
12e817f
6d927b4
3c7ca9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""GISAID report models.""" | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class GisaidComplementaryReport(BaseModel): | ||
"""Model for validating a GSAID complementary reports.""" | ||
|
||
gisaid_accession: str = Field(None, alias="GISAID_accession") | ||
sample_number: str = Field(str, alias="provnummer") | ||
selection_criteria: str = Field(str, alias="urvalskriterium") | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pytest | ||
|
||
from cg.meta.upload.gisaid import GisaidAPI | ||
from cg.models.cg_config import CGConfig | ||
from cg.models.gisaid.reports import GisaidComplementaryReport | ||
|
||
|
||
@pytest.fixture | ||
def gisaid_complementary_report_raw() -> dict[str, str]: | ||
"""Return a raw GISAID complementary report.""" | ||
return { | ||
"provnummer": "a_sample_number", | ||
"urvalskriterium": "a_selection_criteria", | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def gisaid_complementary_report( | ||
gisaid_complementary_report_raw: list[dict], | ||
) -> GisaidComplementaryReport: | ||
"""Return GisaidComplementaryReport.""" | ||
return GisaidComplementaryReport.model_validate(gisaid_complementary_report_raw) | ||
|
||
|
||
@pytest.fixture | ||
def gisaid_complementary_reports( | ||
gisaid_complementary_report: GisaidComplementaryReport, | ||
) -> list[GisaidComplementaryReport]: | ||
"""Return GISAID complementary reports.""" | ||
report_1 = GisaidComplementaryReport.model_validate( | ||
{"provnummer": "1CS", "urvalskriterium": "criteria", "GISAID_accession": "an_accession"} | ||
) | ||
complementary_report = GisaidComplementaryReport.model_validate( | ||
{ | ||
"urvalskriterium": "criteria", | ||
"provnummer": "44CS000000", | ||
} | ||
) | ||
return [gisaid_complementary_report, complementary_report, report_1] | ||
|
||
|
||
@pytest.fixture | ||
def gisaid_api( | ||
cg_context: CGConfig, | ||
) -> GisaidAPI: | ||
"""GISAID API fixture.""" | ||
return GisaidAPI(cg_context) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||
from pathlib import Path | ||||||
|
||||||
from cg.meta.upload.gisaid import GisaidAPI | ||||||
from cg.models.gisaid.reports import GisaidComplementaryReport | ||||||
|
||||||
|
||||||
def test_get_complementary_report_content(gisaid_api: GisaidAPI, csv_file_path: Path): | ||||||
# GIVEN a list of CSV files | ||||||
|
||||||
# WHEN creating the report content | ||||||
content: list[dict] = gisaid_api.get_complementary_report_content(csv_file_path) | ||||||
|
||||||
# THEN each file is a list of dicts where each dict represents a row in a CSV file | ||||||
assert isinstance(content[0], dict) | ||||||
|
||||||
# THEN the file is added as a list of dicts | ||||||
assert len(content) == 3 | ||||||
|
||||||
|
||||||
def test_validate_gisaid_complementary_reports( | ||||||
gisaid_api: GisaidAPI, gisaid_complementary_report_raw: dict[str, str] | ||||||
): | ||||||
# GIVEN a dict | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# WHEN validating the dict | ||||||
content: list[GisaidComplementaryReport] = gisaid_api.validate_gisaid_complementary_reports( | ||||||
[gisaid_complementary_report_raw] | ||||||
) | ||||||
|
||||||
# THEN a list of reports is returned | ||||||
assert isinstance(content[0], GisaidComplementaryReport) | ||||||
|
||||||
|
||||||
def test_get_sars_cov_complementary_reports( | ||||||
gisaid_complementary_reports: list[GisaidComplementaryReport], gisaid_api: GisaidAPI | ||||||
): | ||||||
# GIVEN a list of reports | ||||||
|
||||||
# WHEN getting Sars-cov reports from reports | ||||||
content: list[GisaidComplementaryReport] = gisaid_api.get_sars_cov_complementary_reports( | ||||||
gisaid_complementary_reports | ||||||
) | ||||||
|
||||||
# THEN a list of reports is returned | ||||||
assert isinstance(content[0], GisaidComplementaryReport) | ||||||
|
||||||
# THEN only the report for Sars-cov2 reports remains | ||||||
assert len(content) == 1 | ||||||
assert content[0].sample_number == "44CS000000" | ||||||
|
||||||
|
||||||
def test_get_complementary_report_sample_number( | ||||||
gisaid_complementary_reports: list[GisaidComplementaryReport], gisaid_api: GisaidAPI | ||||||
): | ||||||
# GIVEN a list of reports | ||||||
|
||||||
# WHEN getting the sample numbers in the reports | ||||||
sample_numbers: set[str] = gisaid_api.get_complementary_report_sample_number( | ||||||
gisaid_complementary_reports | ||||||
) | ||||||
|
||||||
# THEN return sample numbers from reports | ||||||
for report in gisaid_complementary_reports: | ||||||
assert report.sample_number in sample_numbers | ||||||
|
||||||
|
||||||
def test_add_gisaid_accession_to_reports( | ||||||
gisaid_complementary_reports: list[GisaidComplementaryReport], gisaid_api: GisaidAPI | ||||||
): | ||||||
"""Test adding gisaid accession to the reports.""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we stick to using capitals for GISAID?
Suggested change
|
||||||
# GIVEN a GISAID API | ||||||
|
||||||
# GIVEN a list of reports | ||||||
|
||||||
# WHEN adding GISAID accession to reports | ||||||
gisaid_api.add_gisaid_accession_to_complementary_reports( | ||||||
gisaid_accession={gisaid_complementary_reports[0].sample_number: "a_gisaid_accession"}, | ||||||
reports=[gisaid_complementary_reports[0]], | ||||||
) | ||||||
|
||||||
# THEN a GISAID accession has been added | ||||||
assert isinstance(gisaid_complementary_reports[0].gisaid_accession, str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
str
in the default position might cause a bug