-
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.
Tests have been organised into ones that immediately work with no icat stack and ones that don't.
- Loading branch information
1 parent
71d81ac
commit 185e304
Showing
74 changed files
with
247 additions
and
133 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
File renamed without changes.
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,85 @@ | ||
from datetime import datetime, timedelta | ||
import json | ||
from unittest.mock import mock_open, patch | ||
|
||
from flask import Flask | ||
from icat.client import Client | ||
from icat.query import Query | ||
import pytest | ||
|
||
from datagateway_api.src.api_start_utils import ( | ||
create_api_endpoints, | ||
create_app_infrastructure, | ||
) | ||
from datagateway_api.src.common.config import APIConfig, Config | ||
from datagateway_api.src.datagateway_api.database.helpers import ( | ||
delete_row_by_id, | ||
insert_row_into_table, | ||
) | ||
from datagateway_api.src.datagateway_api.database.models import SESSION | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def icat_client(): | ||
client = Client( | ||
Config.config.datagateway_api.icat_url, | ||
checkCert=Config.config.datagateway_api.icat_check_cert, | ||
) | ||
client.login( | ||
Config.config.test_mechanism, Config.config.test_user_credentials.dict(), | ||
) | ||
return client | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def flask_test_app(): | ||
"""This is used to check the endpoints exist and have the correct HTTP methods""" | ||
test_app = Flask(__name__) | ||
api, spec = create_app_infrastructure(test_app) | ||
create_api_endpoints(test_app, api, spec) | ||
|
||
yield test_app | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def flask_test_app_db(): | ||
""" | ||
This is in the common conftest file because this test app is also used in | ||
non-backend specific tests | ||
""" | ||
db_app = Flask(__name__) | ||
db_app.config["TESTING"] = True | ||
db_app.config["TEST_BACKEND"] = "db" | ||
|
||
api, spec = create_app_infrastructure(db_app) | ||
create_api_endpoints(db_app, api, spec) | ||
db_app.app_context().push() | ||
|
||
yield db_app.test_client() | ||
|
||
|
||
@pytest.fixture() | ||
def valid_db_credentials_header(): | ||
session = SESSION() | ||
session.id = "Test" | ||
session.expireDateTime = datetime.now() + timedelta(hours=1) | ||
session.username = "Test User" | ||
|
||
insert_row_into_table(SESSION, session) | ||
|
||
yield {"Authorization": f"Bearer {session.id}"} | ||
|
||
delete_row_by_id(SESSION, "Test") | ||
|
||
|
||
@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") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
...ay_api/icat/endpoints/test_create_icat.py → ...ay_api/icat/endpoints/test_create_icat.py
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
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
...y_api/icat/endpoints/test_findone_icat.py → ...y_api/icat/endpoints/test_findone_icat.py
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
4 changes: 3 additions & 1 deletion
4
...api/icat/endpoints/test_get_by_id_icat.py → ...api/icat/endpoints/test_get_by_id_icat.py
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
4 changes: 3 additions & 1 deletion
4
...t/endpoints/test_get_with_filters_icat.py → ...t/endpoints/test_get_with_filters_icat.py
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
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
...at/endpoints/test_table_endpoints_icat.py → ...at/endpoints/test_table_endpoints_icat.py
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
4 changes: 3 additions & 1 deletion
4
.../icat/endpoints/test_update_by_id_icat.py → .../icat/endpoints/test_update_by_id_icat.py
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
4 changes: 3 additions & 1 deletion
4
...at/endpoints/test_update_multiple_icat.py → ...at/endpoints/test_update_multiple_icat.py
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,9 @@ | ||
class TestAPIConfig: | ||
def test_load_with_valid_config_data(self, test_config): | ||
backend_type = test_config.datagateway_api.backend | ||
assert backend_type == "db" | ||
|
||
def test_set_backend_type(self, test_config): | ||
test_config.datagateway_api.set_backend_type("backend_name_changed") | ||
|
||
assert test_config.datagateway_api.backend == "backend_name_changed" |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
Empty file.
File renamed without changes.
Oops, something went wrong.