Skip to content

Commit

Permalink
more renames; remove deps (#2)
Browse files Browse the repository at this point in the history
* more renames; remove deps

* remove

* asd

* ununsed imports

* assdasdasd
  • Loading branch information
hf-kklein authored Feb 26, 2024
1 parent 629d698 commit 0a711fa
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 179 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```

Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }]
keywords = ["technical master data", "tmds"]
keywords = ["basic supply", "bss"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
Expand All @@ -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]
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 1 addition & 25 deletions src/bssclient/client/bssclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import asyncio
import logging
import uuid
from typing import Callable, Optional
from typing import Optional

from aiohttp import BasicAuth, ClientSession, ClientTimeout

from bssclient.client.config import BssConfig
from bssclient.models.netzvertrag import Netzvertrag, _ListOfNetzvertraege
from bssclient.models.patches import build_json_patch_document

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,26 +87,3 @@ async def get_netzvertrag_by_id(self, nv_id: uuid.UUID) -> Netzvertrag | None:
response_json = await response.json()
result = Netzvertrag.model_validate(response_json)
return result

async def update_netzvertrag(
self, netzvertrag_id: uuid.UUID, changes: list[Callable[[Netzvertrag], None]]
) -> Netzvertrag:
"""
patch the given netzvertrag using the changes
"""
session = await self._get_session()
netzvertrag = await self.get_netzvertrag_by_id(netzvertrag_id)
if netzvertrag is None:
raise ValueError(f"Netzvertrag with id {netzvertrag_id} not found")
patch_document = build_json_patch_document(netzvertrag, changes)
request_url = self._config.server_url / "api" / "v2" / "Netzvertrag" / str(netzvertrag_id)
request_uuid = uuid.uuid4()
_logger.debug("[%s] requesting %s", str(request_uuid), request_url)
async with session.patch(
request_url, json=patch_document.patch, headers={"Content-Type": "application/json-patch+json"}
) as response:
response.raise_for_status()
_logger.debug("[%s] response status: %s", str(request_uuid), response.status)
response_json = await response.json()
result = Netzvertrag.model_validate(response_json)
return result
28 changes: 0 additions & 28 deletions src/bssclient/models/patches.py

This file was deleted.

6 changes: 3 additions & 3 deletions unittests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
31 changes: 1 addition & 30 deletions unittests/test_netzvertraege.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import uuid
from pathlib import Path

from aioresponses import CallbackResult, aioresponses
from jsonpatch import JsonPatch # type:ignore[import]
from aioresponses import aioresponses

from bssclient.models.netzvertrag import Bo4eVertrag, Netzvertrag, Vertragsstatus

Expand Down Expand Up @@ -42,34 +41,6 @@ async def test_get_netzvertraege_by_melo(self, bss_client_with_default_auth):
assert any(actual[0].model_extra), "Unmapped properties should be stored in model_extra (Netzvertrag)"
assert any(actual[0].bo_model.model_extra), "Unmapped properties should be stored in model_extra (Bo4eVertrag)"

async def test_update_netzvertrag(self, bss_client_with_default_auth):
netzvertrag_json_file = Path(__file__).parent / "example_data" / "single_netzvertrag.json"
with open(netzvertrag_json_file, "r", encoding="utf-8") as infile:
netzvertrag_json = json.load(infile)

nv_id = uuid.UUID("3e15bf73-ea1b-4f50-8f18-3288074a4fec")
client, tmds_config = bss_client_with_default_auth

def set_status_to_storniert(nv: Netzvertrag) -> None:
assert nv.bo_model is not None
nv.bo_model.vertragstatus = Vertragsstatus.STORNIERT

def patch_endpoint_callback(url, **kwargs): # pylint:disable=unused-argument
request_body = kwargs["json"]
json_patch = JsonPatch(request_body)
modified_netzvertrag_json = netzvertrag_json.copy()
result = json_patch.apply(modified_netzvertrag_json)
return CallbackResult(status=200, payload=result)

with aioresponses() as mocked_tmds:
mocked_get_url = f"{tmds_config.server_url}api/Netzvertrag/{nv_id}"
mocked_tmds.get(mocked_get_url, status=200, payload=netzvertrag_json)
mocked_patch_url = f"{tmds_config.server_url}api/v2/Netzvertrag/{nv_id}"
mocked_tmds.patch(mocked_patch_url, callback=patch_endpoint_callback)
actual = await client.update_netzvertrag(nv_id, [set_status_to_storniert])
assert isinstance(actual, Netzvertrag)
assert actual.bo_model.vertragstatus == Vertragsstatus.STORNIERT

def test_netzvertrag_can_be_instantiated_using_field_names(self):
dummy_bo4e_vertrag = Bo4eVertrag.construct()
nv = Netzvertrag(bo_model=dummy_bo4e_vertrag, id=uuid.uuid4())
Expand Down
81 changes: 0 additions & 81 deletions unittests/test_patches.py

This file was deleted.

0 comments on commit 0a711fa

Please sign in to comment.