mirror of
https://github.com/hass-api/hassapi.git
synced 2022-10-22 18:29:31 +03:00
Add base model for HASS API JSON objects representation
This commit is contained in:
@@ -47,7 +47,7 @@ class BaseClient(AuthenticatedClient):
|
||||
url=self._get_url(endpoint),
|
||||
headers=self._headers,
|
||||
timeout=self._timeout,
|
||||
params={**(params or {}), **kwargs} or None
|
||||
params={**(params or {}), **kwargs} or None,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
1
tests/client/__init__.py
Normal file
1
tests/client/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for client subpackage."""
|
||||
1
tests/models/__init__.py
Normal file
1
tests/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for models subpackage."""
|
||||
36
tests/models/test_base.py
Normal file
36
tests/models/test_base.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from hassapi.models import base
|
||||
|
||||
|
||||
class DummyModel(base.Model):
|
||||
pass
|
||||
|
||||
|
||||
class DummyModelList(base.ModelList):
|
||||
def __init__(self):
|
||||
super().__init__(("a", "b"))
|
||||
|
||||
|
||||
@patch("hassapi.models.base.asdict")
|
||||
@patch("hassapi.models.base._repr_dict", return_value="dummy field repr")
|
||||
def test_model_repr(mock_repr_dict, mock_asdict):
|
||||
assert repr(DummyModel()) == "DummyModel with fields:\ndummy field repr"
|
||||
|
||||
|
||||
def test_model_list_repr():
|
||||
assert repr(DummyModelList()) == "DummyModelList with items: [\n- 'a'\n\n\n- 'b'\n\n\n]"
|
||||
|
||||
|
||||
def test_repr_dict():
|
||||
input_dict = {"a": "b", "c": {"d": "e", "f": {"g": "h"}}}
|
||||
expected_lines = (
|
||||
" a: b",
|
||||
" c: ",
|
||||
" d: e",
|
||||
" f: ",
|
||||
" g: h",
|
||||
)
|
||||
assert base._repr_dict(input_dict) == "\n".join(expected_lines)
|
||||
Reference in New Issue
Block a user