-
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.
- Loading branch information
1 parent
0439247
commit 7e89e29
Showing
3 changed files
with
51 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,24 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from datagateway_api.common.backends import create_backend | ||
from datagateway_api.common.constants import Constants | ||
from datagateway_api.common.exceptions import DatabaseError | ||
|
||
|
||
class TestICATPing: | ||
def test_valid_ping(self, flask_test_app_db): | ||
test_response = flask_test_app_db.get("/ping") | ||
|
||
assert test_response.json == Constants.PING_OK_RESPONSE | ||
|
||
def test_invalid_ping(self): | ||
with patch( | ||
"sqlalchemy.engine.reflection.Inspector.get_table_names", | ||
side_effect=SQLAlchemyError("Mocked Exception"), | ||
): | ||
with pytest.raises(DatabaseError): | ||
backend = create_backend("db") | ||
backend.ping() |
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,26 @@ | ||
from unittest.mock import patch | ||
|
||
from icat.exception import ICATError | ||
import pytest | ||
|
||
from datagateway_api.common.backends import create_backend | ||
from datagateway_api.common.constants import Constants | ||
from datagateway_api.common.exceptions import PythonICATError | ||
from datagateway_api.common.icat.icat_client_pool import create_client_pool | ||
|
||
|
||
class TestICATPing: | ||
def test_valid_ping(self, flask_test_app_icat): | ||
test_response = flask_test_app_icat.get("/ping") | ||
|
||
assert test_response.json == Constants.PING_OK_RESPONSE | ||
|
||
def test_invalid_ping(self): | ||
with patch( | ||
"icat.client.Client.getEntityNames", | ||
side_effect=ICATError("Mocked Exception"), | ||
): | ||
with pytest.raises(PythonICATError): | ||
backend = create_backend("python_icat") | ||
client_pool = create_client_pool() | ||
backend.ping(client_pool=client_pool) |
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