Added api to tests

This commit is contained in:
Maximilian Giller 2023-12-29 22:50:40 +01:00
parent c25d099f0c
commit 051f0e8ed0

View file

@ -1,13 +1,42 @@
import asyncio
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from handler.action_queue import ActionQueue
import logging
logging.getLogger().setLevel(logging.INFO)
queue = ActionQueue()
app = FastAPI()
origins = [
"http://localhost",
"http://localhost:8000",
"http://raspberrypi",
"http://192.168.178.84:8000",
"http://192.168.178.84",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
async def idle_a():
while True:
logging.info("Idleling ...")
logging.info("Idleling AAA ...")
await asyncio.sleep(1)
async def idle_b():
while True:
logging.info("Idleling BBB ...")
await asyncio.sleep(1)
@ -22,23 +51,22 @@ async def action_b():
await asyncio.sleep(1)
logging.info("Ended action B")
async def main():
logging.info("Starting main")
await action_a()
logging.info("Starting action queue")
queue = ActionQueue()
@app.post("/idle_a")
async def api_idle_a():
await queue.set_idle_action(idle_a)
await asyncio.sleep(7)
@app.post("/idle_b")
async def api_idle_b():
await queue.set_idle_action(idle_b)
@app.post("/idle_a")
async def api_idle_a():
await queue.set_idle_action(idle_a)
@app.post("/action_a")
async def api_action_a():
await queue.add_action_to_queue(action_a)
@app.post("/action_b")
async def api_action_b():
await queue.add_action_to_queue(action_b)
await asyncio.sleep(10)
asyncio.run(main())