Skip to content

Commit

Permalink
#217: Add tests for get_entity_object_from_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Apr 8, 2021
1 parent 550bd41 commit b9fc454
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/test_get_entity_object.py
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")

0 comments on commit b9fc454

Please sign in to comment.