-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(FCL-343): Ensure tests no longer have incomplete RawCourtRepo data
- Loading branch information
1 parent
84aa896
commit 9b550e6
Showing
4 changed files
with
131 additions
and
4 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,29 @@ | ||
from .courts import Court | ||
from .courts_schema_types_autogenerated import RawCourt, RawCourtRepository | ||
|
||
|
||
class CourtFactory(Court): | ||
def __init__(self, data): | ||
data = make_court_valid(data) | ||
super().__init__(data) | ||
|
||
|
||
def make_court_valid(data) -> RawCourt: | ||
for keyword in ["code", "name", "link"]: | ||
if keyword not in data: | ||
data[keyword] = f"placeholder {keyword}" | ||
for keyword in ["selectable", "listable"]: | ||
if keyword not in data: | ||
data[keyword] = True | ||
return data | ||
|
||
|
||
def make_court_repo_valid(data) -> RawCourtRepository: | ||
new_court_groups = [] | ||
for court_group in data: | ||
new_courts = [] | ||
for court in court_group["courts"]: | ||
new_courts.append(make_court_valid(court)) | ||
court_group["court"] = new_courts | ||
new_court_groups.append(court_group) | ||
return new_court_groups |
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,84 @@ | ||
from .factory import make_court_repo_valid | ||
|
||
|
||
def test_factory(): | ||
input_data = [ | ||
{ | ||
"name": "court_group", | ||
"display_name": "court group 1", | ||
"courts": [ | ||
{ | ||
"name": "court1", | ||
"selectable": True, | ||
}, | ||
{"name": "court2", "selectable": False}, | ||
], | ||
}, | ||
{ | ||
"name": "court_group2", | ||
"display_name": "court group 2", | ||
"courts": [{"name": "court3", "selectable": False}], | ||
}, | ||
] | ||
|
||
output_data = [ | ||
{ | ||
"name": "court_group", | ||
"display_name": "court group 1", | ||
"courts": [ | ||
{ | ||
"name": "court1", | ||
"selectable": True, | ||
"code": "placeholder code", | ||
"link": "placeholder link", | ||
"listable": True, | ||
}, | ||
{ | ||
"name": "court2", | ||
"selectable": False, | ||
"code": "placeholder code", | ||
"link": "placeholder link", | ||
"listable": True, | ||
}, | ||
], | ||
"court": [ | ||
{ | ||
"name": "court1", | ||
"selectable": True, | ||
"code": "placeholder code", | ||
"link": "placeholder link", | ||
"listable": True, | ||
}, | ||
{ | ||
"name": "court2", | ||
"selectable": False, | ||
"code": "placeholder code", | ||
"link": "placeholder link", | ||
"listable": True, | ||
}, | ||
], | ||
}, | ||
{ | ||
"name": "court_group2", | ||
"display_name": "court group 2", | ||
"courts": [ | ||
{ | ||
"name": "court3", | ||
"selectable": False, | ||
"code": "placeholder code", | ||
"link": "placeholder link", | ||
"listable": True, | ||
} | ||
], | ||
"court": [ | ||
{ | ||
"name": "court3", | ||
"selectable": False, | ||
"code": "placeholder code", | ||
"link": "placeholder link", | ||
"listable": True, | ||
} | ||
], | ||
}, | ||
] | ||
assert str(output_data) == str(make_court_repo_valid(input_data)) |