-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#223: Move tests for distinct attr mapping
- Loading branch information
1 parent
d3bda6e
commit d21bd67
Showing
2 changed files
with
63 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from datagateway_api.common.helpers import map_distinct_attributes_to_results | ||
from datetime import datetime, timezone | ||
|
||
import pytest | ||
|
||
|
||
class TestMapDistinctAttrs: | ||
@pytest.mark.parametrize( | ||
"distinct_attrs, result, expected_output", | ||
[ | ||
pytest.param( | ||
["summary"], | ||
["Summary 1"], | ||
{"summary": "Summary 1"}, | ||
id="Single attribute", | ||
), | ||
pytest.param( | ||
["startDate"], | ||
( | ||
datetime( | ||
year=2020, | ||
month=1, | ||
day=4, | ||
hour=1, | ||
minute=1, | ||
second=1, | ||
tzinfo=timezone.utc, | ||
), | ||
), | ||
{"startDate": "2020-01-04 01:01:01+00:00"}, | ||
id="Single date attribute", | ||
), | ||
pytest.param( | ||
["summary", "title"], | ||
("Summary 1", "Title 1"), | ||
{"summary": "Summary 1", "title": "Title 1"}, | ||
id="Multiple attributes", | ||
), | ||
pytest.param( | ||
["summary", "investigationUsers.role"], | ||
("Summary 1", "PI"), | ||
{"summary": "Summary 1", "investigationUsers": {"role": "PI"}}, | ||
id="Multiple attributes with related attribute", | ||
), | ||
pytest.param( | ||
["summary", "investigationUsers.investigation.name"], | ||
("Summary 1", "Investigation Name 1"), | ||
{ | ||
"summary": "Summary 1", | ||
"investigationUsers": { | ||
"investigation": {"name": "Investigation Name 1"}, | ||
}, | ||
}, | ||
id="Multiple attributes with 2-level nested related attribute", | ||
), | ||
], | ||
) | ||
def test_valid_map_distinct_attributes_to_results( | ||
self, distinct_attrs, result, expected_output, | ||
): | ||
test_output = map_distinct_attributes_to_results(distinct_attrs, result) | ||
|
||
assert test_output == expected_output |