Skip to content

Commit

Permalink
rename 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein committed Feb 26, 2024
1 parent 01e3d77 commit c731c4a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ pip install bssclient
```

## Usage

```python
from yarl import URL
from bssclient import bssclient, TmdsConfig
from bssclient import bssclient, BssConfig

tmds_config = TmdsConfig(
tmds_config = BssConfig(
server_url=URL("https://my-tmds.xtk-test.org/"),
usr="my-usr",
pwd="my-pwd",
Expand Down
4 changes: 2 additions & 2 deletions src/bssclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"""

# convenience exports
from .client.bssclient import bssclient
from .client.config import TmdsConfig
from .client.bssclient import BssClient
from .client.config import BssConfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

from aiohttp import BasicAuth, ClientSession, ClientTimeout

from bssclient.client.config import TmdsConfig
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__)


class bssclient:
class BssClient:
"""
an async wrapper around the TMDS API
"""

def __init__(self, config: TmdsConfig):
def __init__(self, config: BssConfig):
self._config = config
self._auth = BasicAuth(login=self._config.usr, password=self._config.pwd)
self._session_lock = asyncio.Lock()
Expand Down
10 changes: 5 additions & 5 deletions src/bssclient/client/config.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""
contains a class with which the TMDS client is instantiated/configured
contains a class with which the BSS client is instantiated/configured
"""

from pydantic import BaseModel, ConfigDict, field_validator
from yarl import URL


class TmdsConfig(BaseModel):
class BssConfig(BaseModel):
"""
A class to hold the configuration for the TMDS client
A class to hold the configuration for the BSS client
"""

model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)

server_url: URL
"""
e.g. URL("https://techmasterdata.xtk-dev.de")
e.g. URL("https://basicsupply.xtk-stage.de/")
"""
usr: str
"""
Expand Down Expand Up @@ -48,5 +48,5 @@ def validate_url(cls, value):
if not isinstance(value, URL):
raise ValueError("Invalid URL type")
if len(value.parts) > 2:
raise ValueError("You must provide a base_url without any parts, e.g. https://techmasterdata.xtk-prod.de")
raise ValueError("You must provide a base_url without any parts, e.g. https://basicsupply.xtk-prod.de/")
return value
2 changes: 1 addition & 1 deletion src/bssclient/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
'models' contains the TMDS data model (or at least the part which we use in this client)
'models' contains the BSS data model (or at least the part which we use in this client)
"""
10 changes: 5 additions & 5 deletions unittests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from typing import AsyncGenerator

import pytest
from bssclient import TmdsConfig, bssclient
from bssclient import BssConfig, BssClient
from yarl import URL


@pytest.fixture
async def tmds_client_with_default_auth() -> AsyncGenerator[tuple[bssclient, TmdsConfig], None]:
async def bss_client_with_default_auth() -> AsyncGenerator[tuple[BssClient, BssConfig], None]:
"""
"mention" this fixture in the signature of your test to run the code up to yield before the respective test
(and the code after yield the test execution)
:return:
"""
tmds_config = TmdsConfig(
server_url=URL("https://tmds.inv/"),
tmds_config = BssConfig(
server_url=URL("https://bss.inv/"),
usr="my-usr",
pwd="my-pwd",
)
client = bssclient(tmds_config)
client = BssClient(tmds_config)
yield client, tmds_config
await client.close_session()
12 changes: 6 additions & 6 deletions unittests/test_netzvertraege.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ class TestGetNetzvertraege:
A class with pytest unit tests.
"""

async def test_get_netzvertrag_by_id(self, tmds_client_with_default_auth):
async def test_get_netzvertrag_by_id(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 = tmds_client_with_default_auth
client, tmds_config = bss_client_with_default_auth
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)
actual = await client.get_netzvertrag_by_id(nv_id)
assert isinstance(actual, Netzvertrag)

async def test_get_netzvertraege_by_melo(self, tmds_client_with_default_auth):
async def test_get_netzvertraege_by_melo(self, bss_client_with_default_auth):
netzvertraege_json_file = Path(__file__).parent / "example_data" / "list_of_netzvertraege.json"
with open(netzvertraege_json_file, "r", encoding="utf-8") as infile:
netzvertraege_json = json.load(infile)
melo_id = "DE0011122233344455566677788899900"
client, tmds_config = tmds_client_with_default_auth
client, tmds_config = bss_client_with_default_auth
with aioresponses() as mocked_tmds:
mocked_get_url = f"{tmds_config.server_url}api/Netzvertrag/find?messlokation={melo_id}"
mocked_tmds.get(mocked_get_url, status=200, payload=netzvertraege_json)
Expand All @@ -41,13 +41,13 @@ async def test_get_netzvertraege_by_melo(self, tmds_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, tmds_client_with_default_auth):
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 = tmds_client_with_default_auth
client, tmds_config = bss_client_with_default_auth

def set_status_to_storniert(nv: Netzvertrag) -> None:
assert nv.bo_model is not None
Expand Down

0 comments on commit c731c4a

Please sign in to comment.