Skip to content

Commit

Permalink
Add panosc mapping to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reillyhewitson committed Dec 1, 2022
1 parent 7ffc4b8 commit 4ebeb77
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import json
from unittest.mock import mock_open, patch

from icat.query import Query
import pytest

from datagateway_api.src.common.config import APIConfig


@pytest.fixture()
def icat_query(icat_client):
Expand Down Expand Up @@ -48,3 +53,16 @@ def test_config_data():
"test_user_credentials": {"username": "root", "password": "pw"},
"test_mechanism": "simple",
}


@pytest.fixture()
def test_config(test_config_data):
with patch("builtins.open", mock_open(read_data=json.dumps(test_config_data))):
return APIConfig.load("test/path")


@pytest.fixture()
def test_config_without_search_api(test_config_data):
del test_config_data["search_api"]
with patch("builtins.open", mock_open(read_data=json.dumps(test_config_data))):
return APIConfig.load("test/path")
27 changes: 27 additions & 0 deletions test/unit/search_api/test_panosc_mappings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import pytest

from datagateway_api.src.common.exceptions import FilterError, SearchAPIError
Expand All @@ -9,6 +11,31 @@ def test_valid_load_mappings(self, test_panosc_mappings):
test_mappings = PaNOSCMappings()
assert test_mappings.mappings == test_panosc_mappings.mappings

@pytest.mark.parametrize(
"search_api_config_flag",
[
pytest.param(True, id="Search API config present"),
pytest.param(False, id="No search API config"),
],
)
def test_invalid_load_mappings(
self, test_config, test_config_without_search_api, search_api_config_flag,
):
if search_api_config_flag:
current_test_config = test_config
else:
current_test_config = test_config_without_search_api

with patch(
"datagateway_api.src.common.config.Config.config", current_test_config,
):
if search_api_config_flag:
with pytest.raises(SystemExit):
PaNOSCMappings("bad/path")
else:
# Shouldn't SysExit if a user isn't using the search API
PaNOSCMappings("bad/path")

@pytest.mark.parametrize(
"panosc_entity_name, field_name, expected_panosc_entity_name"
", expected_icat_field_name",
Expand Down

0 comments on commit 4ebeb77

Please sign in to comment.