From bf5592a908a160a4ec448a6fba5a1b7a232dd609 Mon Sep 17 00:00:00 2001 From: konstantin Date: Mon, 26 Feb 2024 15:02:00 +0100 Subject: [PATCH] more renames; remove deps --- README.md | 6 +-- pyproject.toml | 9 ++-- requirements.txt | 4 -- src/bssclient/models/patches.py | 28 ------------ unittests/conftest.py | 6 +-- unittests/test_patches.py | 81 --------------------------------- 6 files changed, 10 insertions(+), 124 deletions(-) delete mode 100644 src/bssclient/models/patches.py delete mode 100644 unittests/test_patches.py diff --git a/README.md b/README.md index 352c407..96a2a16 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,12 @@ pip install bssclient from yarl import URL from bssclient import bssclient, BssConfig -tmds_config = BssConfig( - server_url=URL("https://my-tmds.xtk-test.org/"), +bss_config = BssConfig( + server_url=URL("https://my-bss.xtk-test.org/"), usr="my-usr", pwd="my-pwd", ) -client = bssclient(tmds_config) +client = bssclient(bss_config) netzvertrage = await client.get_netzvertraege_for_melo("DE1234567890123456789012345678901") ``` diff --git a/pyproject.toml b/pyproject.toml index 76d5334..409669f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "bssclient" -description = "Fully typed, async client library for Technical Master Data Service (TMDS)" +description = "Fully typed, async client library for Basic Supply Service (BSS)" license = { text = "MIT" } requires-python = ">=3.11" authors = [{ name = "Hochfreuqenz Unternehmensberatung GmbH", email = "info+github@hochfrequenz.de" }] -keywords = ["technical master data", "tmds"] +keywords = ["basic supply", "bss"] classifiers = [ "Development Status :: 4 - Beta", "Environment :: Console", @@ -18,13 +18,12 @@ classifiers = [ ] dependencies = [ "pydantic>=2.0.0", - "aiohttp[speedups]>=3.9.3", - "jsonpatch" + "aiohttp[speedups]>=3.9.3" ] # add all the dependencies here dynamic = ["readme", "version"] [project.urls] -Changelog = "https://github.com/Hochfrequenz/tmddsclient.py/releases" +Changelog = "https://github.com/Hochfrequenz/bssclient.py/releases" Homepage = "https://github.com/Hochfrequenz/bssclient.py" [tool.black] diff --git a/requirements.txt b/requirements.txt index ceabdf9..44e2c50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,10 +20,6 @@ frozenlist==1.4.1 # aiosignal idna==3.6 # via yarl -jsonpatch==1.33 - # via bssclient (pyproject.toml) -jsonpointer==2.4 - # via jsonpatch multidict==6.0.5 # via # aiohttp diff --git a/src/bssclient/models/patches.py b/src/bssclient/models/patches.py deleted file mode 100644 index af3f923..0000000 --- a/src/bssclient/models/patches.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -TMDS in v2 supports RFC6902 JSON Patch. This module contains the patching logic. -""" - -import json -from typing import Callable, TypeVar - -import jsonpatch # type:ignore[import]# https://github.com/stefankoegl/python-json-patch/issues/158 -from pydantic import BaseModel - -Entity = TypeVar("Entity", bound=BaseModel) - - -def build_json_patch_document(current_state: Entity, changes: list[Callable[[Entity], None]]) -> jsonpatch.JsonPatch: - """ - creates a json patch (RFC6902) that contains all the changes applied to current_state. - Note that the result is not stable, i.e. the order of operations in the patch may vary. - See https://github.com/stefankoegl/python-json-patch/issues/151 - """ - current_state_dict = json.loads(current_state.model_dump_json(by_alias=True)) - # we create a deep copy of the original object - # using construct rather than model_validate to bypass validation - new_state = current_state.model_copy(deep=True) - for change in changes: - change(new_state) - new_state_dict = json.loads(new_state.model_dump_json(by_alias=True)) - patch = jsonpatch.make_patch(current_state_dict, new_state_dict) - return patch diff --git a/unittests/conftest.py b/unittests/conftest.py index 570dc8e..cd513bb 100644 --- a/unittests/conftest.py +++ b/unittests/conftest.py @@ -13,11 +13,11 @@ async def bss_client_with_default_auth() -> AsyncGenerator[tuple[BssClient, BssC (and the code after yield the test execution) :return: """ - tmds_config = BssConfig( + bss_config = BssConfig( server_url=URL("https://bss.inv/"), usr="my-usr", pwd="my-pwd", ) - client = BssClient(tmds_config) - yield client, tmds_config + client = BssClient(bss_config) + yield client, bss_config await client.close_session() diff --git a/unittests/test_patches.py b/unittests/test_patches.py deleted file mode 100644 index 4c80a2f..0000000 --- a/unittests/test_patches.py +++ /dev/null @@ -1,81 +0,0 @@ -""" -tests the bare JSON patch logic (no requests) -""" - -import uuid -from datetime import datetime, timezone -from typing import Callable - -import pytest -from jsonpatch import JsonPatch # type:ignore[import] - -from bssclient.models.netzvertrag import Bo4eVertrag, Netzvertrag, Vertragsstatus -from bssclient.models.patches import build_json_patch_document - - -def _set_netzvertrag_vertragsbeginn(nv: Netzvertrag, vertragsbeginn: datetime) -> None: - assert nv.bo_model is not None - nv.bo_model.vertragsbeginn = vertragsbeginn - - -def _set_netzvertrag_status(nv: Netzvertrag, status: Vertragsstatus) -> None: - assert nv.bo_model is not None - nv.bo_model.vertragstatus = status - - -@pytest.mark.parametrize( - "old_nv, changes, expected", - [ - pytest.param( - Netzvertrag( - id=uuid.uuid4(), - boModel=Bo4eVertrag.construct(vertragsbeginn=datetime(2023, 1, 1, 0, 0, 0, tzinfo=timezone.utc)), - ), - [lambda x: _set_netzvertrag_vertragsbeginn(x, datetime(2023, 1, 1, 0, 0, 0, tzinfo=timezone.utc))], - JsonPatch([]), - id="nothing to do", - ), - pytest.param( - Netzvertrag( - id=uuid.uuid4(), - boModel=Bo4eVertrag.construct(vertragsbeginn=datetime(2023, 1, 1, 0, 0, 0, tzinfo=timezone.utc)), - ), - [lambda x: _set_netzvertrag_vertragsbeginn(x, datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc))], - JsonPatch([{"op": "replace", "path": "/boModel/vertragsbeginn", "value": "2024-01-01T00:00:00Z"}]), - id="change one property", - ), - pytest.param( - Netzvertrag( - id=uuid.uuid4(), - boModel=Bo4eVertrag.construct( - vertragsbeginn=datetime(2023, 1, 1, 0, 0, 0, tzinfo=timezone.utc), - vertragstatus=Vertragsstatus.AKTIV, - ), - ), - [ - lambda x: _set_netzvertrag_vertragsbeginn(x, datetime(2023, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), - lambda x: _set_netzvertrag_status(x, Vertragsstatus.STORNIERT), - ], - JsonPatch( - [ - {"op": "replace", "path": "/boModel/vertragsbeginn", "value": "2023-07-01T00:00:00Z"}, - {"op": "replace", "path": "/boModel/vertragstatus", "value": "STORNIERT"}, - ] - ), - id="change 2 properties", - ), - ], -) -def test_netzvertrag_patch_creation( - old_nv: Netzvertrag, changes: list[Callable[[Netzvertrag], None]], expected: JsonPatch -): - actual = build_json_patch_document(old_nv, changes) - actual_patch = actual.patch - expected_patch = expected.patch - assert isinstance(actual_patch, list) - assert actual_patch is not None - assert actual_patch == expected_patch or list(reversed(actual_patch)) == expected_patch - # why the hack is the last assertion necessary? - # see https://github.com/stefankoegl/python-json-patch/issues/151 - # note the last assertion only is guaranteed for lists up to 2 entries. - # for longer lists you might find the test to be flaky.