diff --git a/.vscode/launch.json b/.vscode/launch.json index 6b76b4f..5c4a271 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,10 @@ "type": "debugpy", "request": "launch", "program": "${file}", - "console": "integratedTerminal" + "console": "integratedTerminal", + "env": { + "PYTHONPATH": "${workspaceFolder}" + }, } ] } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a47ba46..10ddf12 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,8 +5,8 @@ charset-normalizer==3.3.2 click==8.1.7 dnspython==2.6.1 email_validator==2.2.0 -fastapi==0.111.1 -fastapi-cli==0.0.4 +fastapi==0.112.1 +fastapi-cli==0.0.5 fastapi-mqtt==2.2.0 gmqtt==0.6.16 h11==0.14.0 @@ -21,6 +21,7 @@ MarkupSafe==2.1.5 mdurl==0.1.2 notion-client==2.2.1 packaging==24.1 +pip-review==1.3.0 pluggy==1.5.0 pydantic==2.8.2 pydantic_core==2.20.1 @@ -28,16 +29,16 @@ Pygments==2.18.0 pytest==8.3.2 python-dotenv==1.0.1 python-multipart==0.0.9 -PyYAML==6.0.1 +PyYAML==6.0.2 requests==2.32.3 rich==13.7.1 shellingham==1.5.4 sniffio==1.3.1 -starlette==0.37.2 -typer==0.12.3 +starlette==0.38.2 +typer==0.12.4 typing_extensions==4.12.2 urllib3==2.2.2 -uvicorn==0.30.1 -uvloop==0.19.0 -watchfiles==0.22.0 +uvicorn==0.30.6 +uvloop==0.20.0 +watchfiles==0.23.0 websockets==12.0 diff --git a/src/cloud_util/homeassistant.py b/src/cloud_util/homeassistant.py index 9e4b49b..9ed5a52 100644 --- a/src/cloud_util/homeassistant.py +++ b/src/cloud_util/homeassistant.py @@ -10,7 +10,7 @@ from src.config import Config class HomeAssistant: - class PublishMessage(BaseModel): + class Message(BaseModel): target: str action: str content: str @@ -18,13 +18,13 @@ class HomeAssistant: def __init__(self, ticktick: TickTick) -> None: self._ticktick = ticktick - def process_publish_message(self, message: PublishMessage) -> dict[str, str]: + def process_message(self, message: Message) -> dict[str, str]: if message.target == "ticktick": return self._process_ticktick_message(message=message) return {"Status": "Unknown target"} - def _process_ticktick_message(self, message: PublishMessage) -> dict[str, str]: + def _process_ticktick_message(self, message: Message) -> dict[str, str]: if message.action == "create_shopping_list": return self._create_shopping_list(content=message.content) if message.action == "create_action_task": diff --git a/src/cloud_util/tests/__init__.py b/src/cloud_util/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/cloud_util/tests/test_ticktick.py b/src/cloud_util/tests/test_ticktick.py new file mode 100644 index 0000000..c00452c --- /dev/null +++ b/src/cloud_util/tests/test_ticktick.py @@ -0,0 +1,7 @@ +import pytest + +from cloud_util.ticktick import TickTick + + +def test_ticktick_begin_auth() -> None: + auth_url = TickTick.begin_auth() diff --git a/src/main.py b/src/main.py index 5d2c6b4..db01e90 100644 --- a/src/main.py +++ b/src/main.py @@ -39,8 +39,8 @@ async def get_status() -> dict: @app.post("/homeassistant/publish") -async def homeassistant_publish(payload: HomeAssistant.PublishMessage) -> dict: - return homeassistant.process_publish_message(message=payload) +async def homeassistant_publish(payload: HomeAssistant.Message) -> dict: + return homeassistant.process_message(message=payload) # Poo recorder diff --git a/src/tests/test_config.py b/src/tests/test_config.py index 26ccde5..02bb2a8 100644 --- a/src/tests/test_config.py +++ b/src/tests/test_config.py @@ -18,7 +18,7 @@ EXPECTED_ENV_DICT: OrderedDict[str, str] = OrderedDict( ) -@pytest.fixture() +@pytest.fixture def _prepare_test_dot_env() -> any: TEST_DOT_ENV_PATH.touch(mode=0o600, exist_ok=True) for key, value in EXPECTED_ENV_DICT.items(): @@ -27,7 +27,7 @@ def _prepare_test_dot_env() -> any: TEST_DOT_ENV_PATH.unlink() -@pytest.fixture() +@pytest.fixture def _load_test_dot_env(_prepare_test_dot_env: any) -> None: Config.init(dotenv_path=TEST_DOT_ENV_PATH) diff --git a/src/tests/test_main.py b/src/tests/test_main.py new file mode 100644 index 0000000..3480612 --- /dev/null +++ b/src/tests/test_main.py @@ -0,0 +1,11 @@ +from fastapi import status +from fastapi.testclient import TestClient + +from src.main import app + + +def test_get_homeassistant_status() -> None: + client = TestClient(app) + response = client.get("/homeassistant/status") + assert response.status_code == status.HTTP_200_OK + assert response.json() == {"Status": "Ok"}