Some renaming
This commit is contained in:
@@ -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":
|
||||
|
||||
0
src/cloud_util/tests/__init__.py
Normal file
0
src/cloud_util/tests/__init__.py
Normal file
7
src/cloud_util/tests/test_ticktick.py
Normal file
7
src/cloud_util/tests/test_ticktick.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from cloud_util.ticktick import TickTick
|
||||
|
||||
|
||||
def test_ticktick_begin_auth() -> None:
|
||||
auth_url = TickTick.begin_auth()
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
11
src/tests/test_main.py
Normal file
11
src/tests/test_main.py
Normal file
@@ -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"}
|
||||
Reference in New Issue
Block a user