Skip to content

Commit

Permalink
test: move test config fixtures so they can be accessed by search API…
Browse files Browse the repository at this point in the history
… tests #258
  • Loading branch information
MRichards99 committed Nov 25, 2021
1 parent 1cf73e4 commit 75bb983
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
39 changes: 39 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import datetime, timedelta
import json
from unittest.mock import mock_open, patch

from flask import Flask
import pytest
Expand All @@ -7,6 +9,7 @@
create_api_endpoints,
create_app_infrastructure,
)
from datagateway_api.src.common.config import APIConfig
from datagateway_api.src.datagateway_api.database.helpers import (
delete_row_by_id,
insert_row_into_table,
Expand Down Expand Up @@ -63,3 +66,39 @@ def valid_db_credentials_header():
yield {"Authorization": f"Bearer {session.id}"}

delete_row_by_id(SESSION, "Test")


@pytest.fixture()
def test_config_data():
return {
"datagateway_api": {
"extension": "/datagateway-api",
"backend": "db",
"client_cache_size": 5,
"client_pool_init_size": 2,
"client_pool_max_size": 5,
"db_url": "mysql+pymysql://icatdbuser:icatdbuserpw@localhost:3306/icatdb",
"icat_url": "https://localhost:8181",
"icat_check_cert": False,
},
"search_api": {
"extension": "/search-api",
"icat_url": "https://localhost.testdomain:8181",
"icat_check_cert": True,
},
"flask_reloader": False,
"log_level": "WARN",
"log_location": "/home/runner/work/datagateway-api/datagateway-api/logs.log",
"debug_mode": False,
"generate_swagger": False,
"host": "127.0.0.1",
"port": "5000",
"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")
38 changes: 0 additions & 38 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,6 @@
from datagateway_api.src.common.config import APIConfig


@pytest.fixture()
def test_config_data():
return {
"datagateway_api": {
"extension": "/datagateway-api",
"backend": "db",
"client_cache_size": 5,
"client_pool_init_size": 2,
"client_pool_max_size": 5,
"db_url": "mysql+pymysql://icatdbuser:icatdbuserpw@localhost:3306/icatdb",
"icat_url": "https://localhost:8181",
"icat_check_cert": False,
},
"search_api": {
"extension": "/search-api",
"icat_url": "https://localhost:8181",
"icat_check_cert": False,
"client_pool_init_size": 2,
"client_pool_max_size": 5,
},
"flask_reloader": False,
"log_level": "WARN",
"log_location": "/home/runner/work/datagateway-api/datagateway-api/logs.log",
"debug_mode": False,
"generate_swagger": False,
"host": "127.0.0.1",
"port": "5000",
"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")


class TestAPIConfig:
def test_load_with_valid_config_data(self, test_config):
backend_type = test_config.datagateway_api.backend
Expand Down

0 comments on commit 75bb983

Please sign in to comment.