Skip to content

Commit

Permalink
Merge pull request #108 from Lightmatter/develop
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
samamorgan authored May 10, 2024
2 parents 2e720f8 + 2048cf8 commit a490d46
Show file tree
Hide file tree
Showing 45 changed files with 551 additions and 520 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
name: CI

on: [pull_request, workflow_dispatch]
on: [pull_request, workflow_dispatch, workflow_call]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
get-python-versions:
name: Get Python versions
runs-on: ubuntu-latest
outputs:
python-matrix: ${{ steps.get-python-versions-action.outputs.latest-python-versions }}
steps:
- name: Get Python version matrix
uses: snok/latest-python-versions@v1
id: get-python-versions-action
with:
min-version: 3.8

ci:
name: CI
needs: [get-python-versions]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJson(needs.get-python-versions.outputs.python-matrix) }}
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout ${{ github.repository }}
Expand All @@ -53,12 +40,13 @@ jobs:

- name: Install dependencies
id: poetry-install
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction

- name: Run pre-commit
run: poetry run pre-commit run --all-files

- name: Run Tests
shell: bash
run: |
poetry run pytest \
--junitxml=pytest.xml \
Expand Down
17 changes: 6 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: debug-statements
- id: mixed-line-ending

## Python
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: isort
types: [python]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
types: [python]
- id: ruff
args: [--fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import welkin

project = welkin.__name__
copyright = welkin.__copyright__
copyright = welkin.__copyright__ # noqa: A001
author = welkin.__author__
release = welkin.__version__

Expand Down
385 changes: 152 additions & 233 deletions poetry.lock

Large diffs are not rendered by default.

68 changes: 63 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "welkin"
version = "0.1.2"
version = "0.1.3"
description = "Python Welkin Health API Wrapper."
authors = ["Sam Morgan <[email protected]>"]
license = "GPL-3.0-or-later"
Expand All @@ -23,9 +23,8 @@ portalocker = "^2.8.2"
inflection = "^0.5.1"

[tool.poetry.group.dev.dependencies]
black = ">=22.10,<25.0"
isort = "^5.10.1"
pre-commit = "^3.5.0"
ruff = "^0.3.6"

[tool.poetry.group.test.dependencies]
pytest = "^8.0.2"
Expand All @@ -44,12 +43,71 @@ myst-parser = "^2.0.0"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
[tool.coverage.report]
# Regexes for lines to exclude from consideration
exclude_also = ["if TYPE_CHECKING:"]

[tool.coverage.run]
omit = ["test/*"]

[tool.pytest.ini_options]
addopts = ["-n=auto"]
env_files = [".env", ".env.example"]

[tool.ruff]
cache-dir = "~/.cache/ruff"
extend-exclude = ["*migrations/*"]
line-length = 92
target-version = "py38"
show-fixes = true

[tool.ruff.lint]
ignore = [
"D1", # Missing docstrings
"D205", # 1 blank line required between summary line and description (does not allow wrapping of summary lines)
"D407", # Dashed underline after doc section (not compatible with google style)
]
select = [ # https://docs.astral.sh/ruff/rules
"F", # pyflakes
"E", # pycodestyle
"W", # pycodestyle
"C90", # mccabe
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
"UP", # pyupgrade
"B", # flake8-bugbear
"S", # flake8-bandit
"A", # flake8-builtins
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"ISC", # flake8-implicit-str-concat
"EXE", # flake8-executable
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RET", # flake8-return
"TCH", # flake8-type-checking
"SIM", # flake8-simplify
"T20", # flake8-print
"TID", # flake8-tidy-imports
"ERA", # eradicate
"PL", # pylint
"RUF", # ruff
]
unfixable = ["D407"]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.lint.isort]
combine-as-imports = true

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs}/*" = ["S", "PLR2004", "PLR0913"]
"**/conftest.py" = ["S", "PLR2004", "PLR0913"]
"**/test*.py" = ["S", "PLR2004", "PLR0913"]

[tool.ruff.lint.pydocstyle]
convention = "google"
22 changes: 11 additions & 11 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import inspect
import json
import os
import uuid
from datetime import date, datetime, time, timedelta, timezone
from http import HTTPStatus
from pathlib import Path
from uuid import uuid4

import pytest

Expand All @@ -15,7 +16,7 @@

def pytest_collection_modifyitems(items):
# Ensure auth tests execute first, otherwise all other tests will fail.
items.sort(key=lambda x: True if "authentication" not in x.nodeid else False)
items.sort(key=lambda x: "authentication" not in x.nodeid)


def redact(field_name, extra=""):
Expand All @@ -34,12 +35,12 @@ def redact(field_name, extra=""):
"updatedBy",
"updatedByName",
]
CLIENT_INIT = dict(
tenant=os.environ["WELKIN_TENANT"],
instance=os.environ["WELKIN_INSTANCE"],
api_client=os.environ["WELKIN_API_CLIENT"],
secret_key=os.environ["WELKIN_SECRET"],
)
CLIENT_INIT = {
"tenant": os.environ["WELKIN_TENANT"],
"instance": os.environ["WELKIN_INSTANCE"],
"api_client": os.environ["WELKIN_API_CLIENT"],
"secret_key": os.environ["WELKIN_SECRET"],
}


@pytest.fixture(scope="module")
Expand All @@ -61,7 +62,6 @@ def vcr(vcr):

def scrub_request(blacklist, replacement="REDACTED"):
def before_record_request(request):
# request.body = filter_body(request.body, blacklist, replacement)
if "api_clients" in request.path:
return None
uri_comps = request.uri.split("/")
Expand Down Expand Up @@ -188,5 +188,5 @@ def est_datetime_str():


@pytest.fixture
def _uuid():
return uuid4()
def uuid4():
return uuid.uuid4()
27 changes: 10 additions & 17 deletions test/test_assessments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from welkin.exceptions import WelkinHTTPError
Expand All @@ -8,14 +10,10 @@
def test_assessment_record_answers_update(client, vcr_cassette):
patient = client.Patient(id="371dd15c-cedc-4425-a394-d666c8d3fc01")

assmt_record = patient.AssessmentRecord(
id="c8764b19-ffa3-406a-b446-c971036a7a1d"
).get()
assmt_record = patient.AssessmentRecord(id="c8764b19-ffa3-406a-b446-c971036a7a1d").get()
hi_answer = assmt_record.answers["cdt-hello__cdtf-hi"]
assmt_record.AssessmentRecordAnswers(**{"cdt-hello__cdtf-hi": "abc123def"}).update()
assmt_record = patient.AssessmentRecord(
id="c8764b19-ffa3-406a-b446-c971036a7a1d"
).get()
assmt_record = patient.AssessmentRecord(id="c8764b19-ffa3-406a-b446-c971036a7a1d").get()

assert assmt_record.answers["cdt-hello__cdtf-hi"] == "abc123def"
assert hi_answer != assmt_record.answers["cdt-hello__cdtf-hi"]
Expand All @@ -26,9 +24,7 @@ def test_assessment_record_answers_update(client, vcr_cassette):
def test_assessment_record_get(client, vcr_cassette):
patient = client.Patient(id="371dd15c-cedc-4425-a394-d666c8d3fc01")

assmt_record = patient.AssessmentRecord(
id="c8764b19-ffa3-406a-b446-c971036a7a1d"
).get()
assmt_record = patient.AssessmentRecord(id="c8764b19-ffa3-406a-b446-c971036a7a1d").get()

assert isinstance(assmt_record, AssessmentRecord)
assert assmt_record.id == "c8764b19-ffa3-406a-b446-c971036a7a1d"
Expand All @@ -37,9 +33,9 @@ def test_assessment_record_get(client, vcr_cassette):

@pytest.mark.vcr
def test_assessment_record_get_w_patient_id(client, vcr_cassette):
assmt_record = client.AssessmentRecord(
id="c8764b19-ffa3-406a-b446-c971036a7a1d"
).get(patient_id="371dd15c-cedc-4425-a394-d666c8d3fc01")
assmt_record = client.AssessmentRecord(id="c8764b19-ffa3-406a-b446-c971036a7a1d").get(
patient_id="371dd15c-cedc-4425-a394-d666c8d3fc01"
)

assert isinstance(assmt_record, AssessmentRecord)
assert assmt_record.id == "c8764b19-ffa3-406a-b446-c971036a7a1d"
Expand All @@ -50,9 +46,7 @@ def test_assessment_record_get_w_patient_id(client, vcr_cassette):
def test_assessment_record_update(client, vcr_cassette):
patient = client.Patient(id="371dd15c-cedc-4425-a394-d666c8d3fc01")

assmt_record = patient.AssessmentRecord(
id="e18a2759-5089-44e7-9d31-cf942476ffab"
).get()
assmt_record = patient.AssessmentRecord(id="e18a2759-5089-44e7-9d31-cf942476ffab").get()
status = assmt_record.status

assmt_record.status = "COMPLETED"
Expand Down Expand Up @@ -84,8 +78,7 @@ def test_assessment_record_delete(client, vcr_cassette):
with pytest.raises(WelkinHTTPError) as excinfo:
assmt_record.get()

assert excinfo.value.response.status_code == 404

assert excinfo.value.response.status_code == 404
assert len(vcr_cassette) == 2


Expand Down
4 changes: 3 additions & 1 deletion test/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import dbm
from pathlib import Path

Expand All @@ -13,7 +15,7 @@ def auth_class(client):
auth.token_method = lambda: {"token": "API_TOKEN"}

try:
auth.token
auth.token # noqa: B018
except dbm.error:
Path(DB_PATH).unlink()
return auth_class(client)
Expand Down
5 changes: 4 additions & 1 deletion test/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import inspect

import pytest
Expand Down Expand Up @@ -31,7 +33,8 @@ def test_method_args(client, class_name: str):
continue # skip dunder methods

if hasattr(method, "__wrapped__"):
method = method.__wrapped__ # unwrap decorated functions
# unwrap decorated functions
method = method.__wrapped__ # noqa: PLW2901

if method.__qualname__ != f"{class_name}.{method_name}":
continue # skip methods from parent classes
Expand Down
3 changes: 2 additions & 1 deletion test/test_calendar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import datetime, timedelta, timezone

import pytest
Expand All @@ -8,7 +10,6 @@
CalendarEvents,
Schedule,
Schedules,
WorkHours,
)

UTC = timezone.utc
Expand Down
2 changes: 2 additions & 0 deletions test/test_care_plan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from welkin.models import CarePlan
Expand Down
5 changes: 3 additions & 2 deletions test/test_cdts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from welkin.exceptions import WelkinHTTPError
Expand Down Expand Up @@ -100,6 +102,5 @@ def test_cdt_delete(client, vcr_cassette):
with pytest.raises(WelkinHTTPError) as excinfo:
cdt.get()

assert excinfo.value.response.status_code == 404

assert excinfo.value.response.status_code == 404
assert len(vcr_cassette) == 3
2 changes: 2 additions & 0 deletions test/test_chat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from welkin.models.chat import Chat, Chats, ChatSearchResult, SearchChats
Expand Down
2 changes: 2 additions & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import inspect

import pytest
Expand Down
Loading

0 comments on commit a490d46

Please sign in to comment.