Skip to content

Commit

Permalink
Merge pull request #62 from pennsignals/epic
Browse files Browse the repository at this point in the history
Epic API tests
  • Loading branch information
mdbecker authored Sep 23, 2021
2 parents 43f8ed6 + 7cda645 commit fc8d404
Show file tree
Hide file tree
Showing 55 changed files with 1,899 additions and 1,185 deletions.
17 changes: 7 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,28 @@ repos:
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-symlinks
- id: check-xml
- id: check-yaml
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: http://github.com/pre-commit/pygrep-hooks
rev: v1.4.2
rev: v1.9.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- id: rst-backticks
# - repo: https://github.com/pre-commit/mirrors-isort
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21-2
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 21.7b0
hooks:
- id: black
language_version: python3.9
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions assets/postgres/epic/notifications/channel.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
listen example.epic_notifications
10 changes: 10 additions & 0 deletions assets/postgres/epic/notifications/errors/insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
insert into epic_notification_errors (
prediction_id,
name,
description
)
select
%(prediction_id)s,
%(name)s,
%(description)s
returning *
6 changes: 6 additions & 0 deletions assets/postgres/epic/notifications/insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
insert into epic_notifications (
prediction_id
)
select
%(prediction_id)s
returning *
31 changes: 31 additions & 0 deletions assets/postgres/epic/notifications/recent.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
with args as (
select
cast(%(notification_id)s as int) as notification_id
)
select
n.id
p.id as prediction_id,
p.run_id,
p.csn,
p.empi,
p.score,
r.as_of
from
args
join runs as r
upper(r.interval) != 'infinity'
join predictions as p on
p.run_id = r.id
join epic_notifications as n on
n.prediction_id = p.id
and n.id <= args.notification_id
left join epic_verifcations as v on
v.notification_id = n.id
left join epic_verification_errors as e on
e.notification_id = n.id
and e.acknowledged_on is null
where
v.id is null
and e.id is null
order by
r.id, p.id
24 changes: 24 additions & 0 deletions assets/postgres/epic/notifications/recover.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
select
n.id,
p.id as prediction_id,
p.csn,
p.empi,
p.score,
r.as_of
from
runs as r
join predictions as p on
p.run_id = r.id
and upper(r.interval) != 'infinity'
join epic_notifications as n on
n.prediction_id = p.id
left join epic_verifications as v on
v.notification_id = n.id
left join epic_verification_errors as e on
e.notification_id = n.id
and e.acknowledged_on is null
where
v.id is null
and e.id is null
order by
p.id, n.id
10 changes: 10 additions & 0 deletions assets/postgres/epic/verifications/errors/insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
insert into epic_verification_errors (
notification_id,
name,
description,
)
select
%(notification_id)s,
%(name)s,
%(description)s
returning *
6 changes: 6 additions & 0 deletions assets/postgres/epic/verifications/insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
insert into epic_verifications (
notification_id
)
select
%(notification_id)s
returning *
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions assets/postgres/predictions/listen.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
listen example.predictions
28 changes: 28 additions & 0 deletions assets/postgres/predictions/recent.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
with args as (
select
cast(%(prediction_id)s as int) as prediction_id
)
select
p.id,
p.run_id,
p.csn,
p.empi,
p.score,
r.as_of
from
args
join runs as r
upper(r.interval) != 'infinity'
join predictions as p on
p.id <= args.prediction_id
and p.run_id = r.id
left join epic_notifications as n on
n.prediction_id = p.id
left join epic_notification_errors as e on
e.prediction_id = p.id
and e.acknowledged_on is null
where
n.id is null
and e.id is null
order by
r.id, p.id
22 changes: 22 additions & 0 deletions assets/postgres/predictions/recover.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
select
p.id,
p.run_id,
p.csn,
p.empi,
p.score,
r.as_of
from
runs as r
join predictions as p on
p.run_id = r.id
and upper(r.interval) != 'infinity'
left join epic_notifications as n on
n.prediction_id = p.prediction_id
left join epic_notification_errors as e on
e.prediction_id = p.prediction_id
and e.acknowledged_on is null
where
n.id is null
and e.id is null
order by
r.id, p.id
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions assets/postgres/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set search_path = example;
20 changes: 15 additions & 5 deletions buster.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ARG IFLAGS="--quiet --no-cache-dir --user"

FROM python:3.9.4-slim-buster as build
FROM python:3.9.6-slim-buster as build
ARG IFLAGS
WORKDIR /root
WORKDIR /tmp
ENV PATH /root/.local/bin:$PATH
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
Expand All @@ -14,21 +14,31 @@ COPY pyproject.toml .
COPY .pre-commit-config.yaml .
COPY .git ./.git
COPY src ./src
COPY sql ./sql
COPY assets ./assets
COPY test ./test
RUN \
chmod +x /usr/bin/tini && \
apt-get -qq update --fix-missing && \
apt-get -qq install -y --no-install-recommends git > /dev/null && \
apt-get -qq install -y --no-install-recommends git libyaml-dev > /dev/null && \
pip install ${IFLAGS} "." && \
apt-get -qq clean && \
apt-get -qq autoremove -y --purge && \
rm -rf /var/lib/apt/lists/*

FROM python:3.9.6-slim-buster as epic
LABEL name="epic"
WORKDIR /tmp
ENV PATH /root/.local/bin:$PATH
COPY --from=build /root/.local /root/.local
COPY --from=build /tmp/assets /tmp/assets
COPY --from=build /usr/bin/tini /usr/bin
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["epic"]

FROM build as test
ARG IFLAGS
LABEL name="dsdk.test"
WORKDIR /root
WORKDIR /tmp
RUN \
pip install ${IFLAGS} ".[all]"
ENTRYPOINT [ "/usr/bin/tini", "--" ]
Expand Down
58 changes: 52 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,57 @@ services:
target: test
depends_on:
- postgres
- notifier
- verifier
- epic
environment:
- POSTGRES_HOST=postgres
- POSTGRES_USERNAME=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DATABASE=test
- POSTGRES_PORT=5432
- CONFIG=/local/test.yaml
- ENV=/local/docker.env
volumes:
- ./assets:/assets
- ./local:/local

notifier:
build:
context: .
target: epic
command: epic.notify
depends_on:
- epic
- postgres
environment:
- CONFIG=/local/notifier.yaml
- ENV=/local/docker.env
volumes:
- ./assets:/assets
- ./local:/local

verifier:
build:
context: .
target: epic
command: epic.verify
depends_on:
- epic
- postgres
environment:
- CONFIG=/local/verifier.yaml
- ENV=/local/docker.env
volumes:
- ./assets:/assets
- ./local:/local

epic:
build:
context: .
target: epic
environment:
- CONFIG=/local/epic.yaml
- ENV=/local/docker.env
expose:
- "80"
ports:
- "80:80"
restart: always
volumes:
- ./sql:/sql
- ./local:/local
4 changes: 4 additions & 0 deletions local/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*
!.gitignore
!configuration.yaml
!notifier.yaml
!verifier.yaml
!epic.yaml
6 changes: 6 additions & 0 deletions local/configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
postgres: !postgres
database: ${POSTGRES_DATABASE}
host: ${POSTRES_HOST}
password: ${POSTGRES_PASSWORD}
port: 5432
username: ${POSTGRES_USERNAME}
4 changes: 4 additions & 0 deletions local/epic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!epic
address: 0.0.0.0:80
add_flowsheet_value_path: ${EPIC_ROOT}${EPIC_ADD_FLOWSHEET_VALUE_PATH}
get_flowsheet_rows_path: ${EPIC_ROOT}${EPIC_GET_FLOWSHEET_ROWS_PATH}
19 changes: 19 additions & 0 deletions local/notifier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!epicnotifier
client_id: ${EPIC_CLIENT_ID}
cookie: ${EPIC_COOKIE}
flowsheet_id: ${EPIC_FLOWSHEET_ID}
flowsheet_template_id: ${EPIC_FLOWSHEET_TEMPLATE_ID}
password: ${EPIC_PASSWORD}
postgres: !postgres
database: ${POSTGRES_DATABASE}
host: ${POSTGRES_HOST}
password: ${POSTGRES_PASSWORD}
port: 5432
sql: !asset
ext: .sql
path: ./assets/postgres
tables: []
username: ${POSTGRES_USERNAME}
username: ${EPIC_USERNAME}
user_id: ${EPIC_USER_ID}
url: ${EPIC_URL}${EPIC_ROOT}${EPIC_ADD_FLOWSHEET_VALUE_PATH}
19 changes: 19 additions & 0 deletions local/verifier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!epicverifier
client_id: ${EPIC_CLIENT_ID}
cookie: ${EPIC_COOKIE}
flowsheet_id: ${EPIC_FLOWSHEET_ID}
flowsheet_template_id: ${EPIC_FLOWSHEET_TEMPLATE_ID}
password: ${EPIC_PASSWORD}
postgres: !postgres
database: ${POSTGRES_DATABASE}
host: ${POSTGRES_HOST}
password: ${POSTGRES_PASSWORD}
port: 5432
sql: !asset
ext: .sql
path: ./assets/postgres
tables: []
username: ${POSTGRES_USERNAME}
username: ${EPIC_USERNAME}
user_id: ${EPIC_USER_ID}
url: ${EPIC_URL}${EPIC_ROOT}${EPIC_GET_FLOWSHEET_ROWS_PATH}
2 changes: 1 addition & 1 deletion postgres/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM timescale/timescaledb-postgis:latest-pg11 as postgres
FROM timescale/timescaledb-postgis:latest-pg13 as postgres
LABEL name=postgres
COPY ./docker-entrypoint.sh /usr/local/bin/
COPY ./sql/initdb.d/*.sql /docker-entrypoint-initdb.d/
Expand Down
6 changes: 3 additions & 3 deletions postgres/sql/initdb.d/003.create.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
create extension if not exists btree_gist;

create schema if not exists dsdk;
grant usage on schema dsdk to public;
grant create on schema dsdk to public;
create schema if not exists example;
grant usage on schema example to public;
grant create on schema example to public;
Loading

0 comments on commit fc8d404

Please sign in to comment.