You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.1 KiB
74 lines
2.1 KiB
import logging
|
|
import os
|
|
|
|
import pytest
|
|
import requests
|
|
from flask_api import status
|
|
|
|
BASE_URL = os.environ.get("TEST_BASE_URL", "http://localhost")
|
|
LOGIN_URI = BASE_URL + "/login"
|
|
LOGOUT_URI = BASE_URL + "/logout"
|
|
ADMIN_URI = BASE_URL + "/admin"
|
|
|
|
PASSWORD = os.environ.get("MONSUN_PASSWORD", "password")
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def log_variables():
|
|
logger = logging.getLogger("system tests")
|
|
logger.info(f"BASE_URL: {BASE_URL}")
|
|
|
|
|
|
@pytest.fixture()
|
|
def session() -> requests.Session:
|
|
session = requests.Session()
|
|
response_login = session.post(
|
|
url=LOGIN_URI,
|
|
data={"email": "andreasberthoud@gmail.com", "password": PASSWORD},
|
|
)
|
|
assert response_login.status_code == status.HTTP_200_OK
|
|
return session
|
|
|
|
|
|
def test_login_as_admin_and_accessing_admin_endpoint():
|
|
session_admin_ = requests.Session()
|
|
response_login = session_admin_.post(
|
|
url=LOGIN_URI,
|
|
data={"email": "andreasberthoud@gmail.com", "password": PASSWORD},
|
|
)
|
|
assert response_login.status_code == status.HTTP_200_OK
|
|
|
|
response_admin_logged_in = session_admin_.get(
|
|
url=ADMIN_URI,
|
|
)
|
|
assert response_admin_logged_in.status_code == status.HTTP_200_OK
|
|
|
|
response_logout = session_admin_.delete(
|
|
url=LOGOUT_URI,
|
|
)
|
|
assert response_logout.status_code == status.HTTP_200_OK
|
|
|
|
response_admin_logged_out = session_admin_.get(
|
|
url=ADMIN_URI,
|
|
)
|
|
assert response_admin_logged_out.status_code == status.HTTP_403_FORBIDDEN
|
|
|
|
|
|
def test_toggle_client_led_then_status_is_ok(session):
|
|
response = session.post(
|
|
url=BASE_URL + "/client/command?cmd=led&id=red&command=toggle",
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
|
|
def test_pair_with_server_then_status_is_ok(session):
|
|
response = session.post(url=BASE_URL + "/client/command?cmd=gp&command_id=1")
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|
|
|
|
def test_toggle_server_led_then_status_is_ok(session):
|
|
"""Requires a connected GATT server"""
|
|
response = session.post(
|
|
url=BASE_URL + "/client/command?cmd=led&id=red&command=toggle&target=server",
|
|
)
|
|
assert response.status_code == status.HTTP_200_OK
|
|
|