Make nodes only accept requests when they're on

This commit is contained in:
Marek Wolan
2024-03-09 20:47:57 +00:00
parent 289b5c548a
commit 31ae4672ac
6 changed files with 164 additions and 18 deletions

View File

@@ -0,0 +1,32 @@
import pytest
from pydantic import ValidationError
from primaite.interface.request import RequestResponse
def test_creating_response_object():
"""Test that we can create a response object with given parameters."""
r1 = RequestResponse(status="success", data={"test_data": 1, "other_data": 2})
r2 = RequestResponse(status="unreachable")
r3 = RequestResponse(data={"test_data": "is_good"})
r4 = RequestResponse()
assert isinstance(r1, RequestResponse)
assert isinstance(r2, RequestResponse)
assert isinstance(r3, RequestResponse)
assert isinstance(r4, RequestResponse)
def test_creating_response_from_boolean():
"""Test that we can build a response with a single boolean."""
r1 = RequestResponse.from_bool(True)
assert r1.status == "success"
r2 = RequestResponse.from_bool(False)
assert r2.status == "failure"
with pytest.raises(ValidationError):
r3 = RequestResponse.from_bool(1)
with pytest.raises(ValidationError):
r4 = RequestResponse.from_bool("good")
with pytest.raises(ValidationError):
r5 = RequestResponse.from_bool({"data": True})