77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
from unittest.mock import patch
|
|
|
|
from tcga_downloader.query import (
|
|
build_filters,
|
|
query_multiple_projects,
|
|
)
|
|
|
|
|
|
def test_build_filters_project_and_type():
|
|
filters = build_filters(project="TCGA-BRCA", data_type="Gene Expression")
|
|
assert filters["op"] == "and"
|
|
assert filters["content"][0]["content"]["field"] == "cases.project.project_id"
|
|
assert len(filters["content"]) == 2
|
|
|
|
|
|
def test_build_filters_with_sample_type():
|
|
filters = build_filters(
|
|
project="TCGA-BRCA", data_type="Gene Expression", sample_type="Primary Tumor"
|
|
)
|
|
assert filters["op"] == "and"
|
|
assert len(filters["content"]) == 3
|
|
assert any(f["content"]["field"] == "samples.sample_type" for f in filters["content"])
|
|
|
|
|
|
def test_build_filters_with_platform():
|
|
filters = build_filters(
|
|
project="TCGA-BRCA", data_type="Gene Expression", platform="Illumina HiSeq"
|
|
)
|
|
assert filters["op"] == "and"
|
|
assert len(filters["content"]) == 3
|
|
assert any(f["content"]["field"] == "platform" for f in filters["content"])
|
|
|
|
|
|
def test_build_filters_all_options():
|
|
filters = build_filters(
|
|
project="TCGA-BRCA",
|
|
data_type="Gene Expression",
|
|
sample_type="Primary Tumor",
|
|
platform="Illumina HiSeq",
|
|
)
|
|
assert filters["op"] == "and"
|
|
assert len(filters["content"]) == 4
|
|
|
|
|
|
@patch("tcga_downloader.query.requests.post")
|
|
def test_query_multiple_projects(mock_post):
|
|
mock_response = mock_post.return_value
|
|
mock_response.json.return_value = {
|
|
"data": {
|
|
"hits": [
|
|
{
|
|
"file_id": "f1",
|
|
"file_name": "file1.tsv",
|
|
"data_type": "Gene Expression",
|
|
"data_format": "TSV",
|
|
"file_size": 100,
|
|
"md5sum": "abc123",
|
|
},
|
|
{
|
|
"file_id": "f2",
|
|
"file_name": "file2.tsv",
|
|
"data_type": "Gene Expression",
|
|
"data_format": "TSV",
|
|
"file_size": 200,
|
|
"md5sum": "def456",
|
|
},
|
|
]
|
|
}
|
|
}
|
|
mock_response.raise_for_status = lambda: None
|
|
|
|
projects = ["TCGA-BRCA", "TCGA-LUAD"]
|
|
results = query_multiple_projects(projects, "Gene Expression")
|
|
|
|
assert len(results) == 4
|
|
assert mock_post.call_count == 2
|