Skip to content

Commit

Permalink
Add session creation and sensor data posting
Browse files Browse the repository at this point in the history
functionality
  • Loading branch information
motty-mio2 committed Nov 5, 2023
1 parent a06ba95 commit fb22659
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/test/api/t_gen_resp.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
from random import randint, random
from time import sleep

import requests

import kb_2315.config as config
from kb_2315.api import schemas


conf: config.env = config.read_config(dir=config.root_dir)


requests.post(
url=conf.host_url,
json=schemas.machine(id=1, status=False).model_dump(),
)

sleep(2)
import requests
from kb_2315.backend.schemas import schema_session, schema_sensor

requests.post(
url=conf.host_url,
json=schemas.machine(id=1, status=True).model_dump(),
)
from kb_2315.config import conf
from kb_2315.backend import schemas

sleep(2)
device_id = randint(1, 100)

requests.post(
url=conf.host_url,
json=schemas.machine(id=1, status=False).model_dump(),
resp: schema_session.create_session = schema_session.create_session.model_validate(
obj=requests.get(f"{conf.host_url}/session/?shoe_id={device_id}").json()
)
print(resp, resp.session_id)
str_sesison_id = str(resp.session_id)

it = 3

for i in range(it):
requests.post(
url=f"{conf.host_url}/sensor",
json=schema_sensor.sensor(
session_id=str_sesison_id,
device_id=device_id,
external_temperature=random() * 30,
external_humidity=random() * 100,
internal_temperature=random() * 30,
internal_humidity=random() * 100,
drying=(i < it - 1),
).model_dump(),
)

sleep(2)

0 comments on commit fb22659

Please sign in to comment.