-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
214 additions
and
36 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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# PIXL DICOM de-identifier | ||
|
||
pip install -r requirements.txt | ||
|
||
pip install -e ../../pixl_core/ | ||
|
||
pip install -e . | ||
|
||
pytest |
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,32 @@ | ||
# Copyright (c) University College London Hospitals NHS Foundation Trust | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
rabbitmq: | ||
host: localhost | ||
port: 7008 | ||
username: rabbitmq_username | ||
password: rabbitmq_password | ||
ehr_api: | ||
host: localhost | ||
port: 7006 | ||
default_rate: 1 | ||
pacs_api: | ||
host: localhost | ||
port: 7007 | ||
default_rate: 1 | ||
postgres: | ||
host: localhost | ||
port: 7001 | ||
username: pixl_db_username | ||
password: pixl_db_password | ||
database: pixl |
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,32 @@ | ||
# Copyright (c) University College London Hospitals NHS Foundation Trust | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Configuration of CLI for db from config file.""" | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
|
||
def _load_config(filename: str = "pixl_config.yml") -> dict: | ||
"""CLI configuration generated from a .yaml file""" | ||
if not Path(filename).exists(): | ||
msg = f"Failed to find {filename}. It must be present in the current working directory" | ||
raise FileNotFoundError(msg) | ||
|
||
with Path(filename).open() as config_file: | ||
config_dict = yaml.safe_load(config_file) | ||
return dict(config_dict) | ||
|
||
|
||
cli_config = _load_config() |
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
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
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,101 @@ | ||
# Copyright (c) University College London Hospitals NHS Foundation Trust | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""CLI testing fixtures.""" | ||
from __future__ import annotations | ||
import datetime | ||
|
||
import pytest | ||
from core.database import Base, Extract, Image | ||
from dateutil.tz import UTC | ||
from sqlalchemy import Engine, create_engine | ||
from sqlalchemy.orm import Session, sessionmaker | ||
|
||
STUDY_DATE = datetime.date.fromisoformat("2023-01-01") | ||
|
||
|
||
@pytest.fixture() | ||
def rows_in_session(db_session) -> Session: | ||
"""Insert a test row for each table, returning the session for use in tests.""" | ||
extract = Extract(slug="i-am-a-project") | ||
|
||
image_exported = Image( | ||
accession_number="123", | ||
study_date=STUDY_DATE, | ||
mrn="mrn", | ||
extract=extract, | ||
exported_at=datetime.datetime.now(tz=UTC), | ||
) | ||
image_not_exported = Image( | ||
accession_number="234", | ||
study_date=STUDY_DATE, | ||
mrn="mrn", | ||
extract=extract, | ||
) | ||
with db_session: | ||
db_session.add_all([extract, image_exported, image_not_exported]) | ||
db_session.commit() | ||
|
||
return db_session | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def monkeymodule(): | ||
"""Module level monkey patch.""" | ||
from _pytest.monkeypatch import MonkeyPatch | ||
|
||
monkeypatch = MonkeyPatch() | ||
yield monkeypatch | ||
monkeypatch.undo() | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="module") | ||
def db_engine(monkeymodule) -> Engine: | ||
""" | ||
Patches the database engine with an in memory database | ||
:returns Engine: Engine for use in other setup fixtures | ||
""" | ||
# SQLite doesnt support schemas, so remove pixl schema from engine options | ||
execution_options = {"schema_translate_map": {"pixl": None}} | ||
engine = create_engine( | ||
"sqlite:///:memory:", | ||
execution_options=execution_options, | ||
echo=True, | ||
echo_pool="debug", | ||
future=True, | ||
) | ||
monkeymodule.setattr("pixl_cli._database.engine", engine) | ||
|
||
Base.metadata.create_all(engine) | ||
yield engine | ||
Base.metadata.drop_all(engine) | ||
|
||
|
||
@pytest.fixture() | ||
def db_session(db_engine) -> Session: | ||
""" | ||
Creates a session for interacting with an in memory database. | ||
Will remove any data from database in setup | ||
:returns Session: Session for use in other setup fixtures. | ||
""" | ||
InMemorySession = sessionmaker(db_engine) | ||
with InMemorySession() as session: | ||
# sqlite with sqlalchemy doesn't rollback, so manually deleting all database entities | ||
session.query(Image).delete() | ||
session.query(Extract).delete() | ||
yield session | ||
session.close() |
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
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 |
---|---|---|
|
@@ -31,5 +31,5 @@ | |
"*.tests.*", | ||
], | ||
), | ||
python_requires="==3.9.2", | ||
python_requires=">=3.9.2", | ||
) |