-
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.
#217: Add tests for get_entity_object_from_name()
- Loading branch information
1 parent
550bd41
commit b9fc454
Showing
1 changed file
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
from datagateway_api.common.database.models import FACILITY, INVESTIGATION, JOB | ||
from datagateway_api.common.exceptions import ApiError | ||
from datagateway_api.common.helpers import get_entity_object_from_name | ||
|
||
|
||
class TestGetEntityObject: | ||
@pytest.mark.parametrize( | ||
"entity_name, expected_object_type", | ||
[ | ||
pytest.param( | ||
"investigation", type(INVESTIGATION), id="singular entity name", | ||
), | ||
pytest.param("jobs", type(JOB), id="plural entity name, 's' added"), | ||
pytest.param( | ||
"facilities", type(FACILITY), id="plural entity name, 'y' to 'ies'", | ||
), | ||
], | ||
) | ||
def test_valid_get_entity_object_from_name(self, entity_name, expected_object_type): | ||
database_entity = get_entity_object_from_name(entity_name) | ||
|
||
assert type(database_entity) == expected_object_type | ||
|
||
def test_invalid_get_entity_object_from_name(self): | ||
with pytest.raises(ApiError): | ||
get_entity_object_from_name("Application1234s") |