Update tests
This commit is contained in:
@@ -4,7 +4,7 @@ from primaite.simulator.domain.account import Account, AccountType
|
|||||||
|
|
||||||
def test_account_serialise():
|
def test_account_serialise():
|
||||||
"""Test that an account can be serialised."""
|
"""Test that an account can be serialised."""
|
||||||
acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.user)
|
acct = Account(username="Jake", password="JakePass1!", account_type=AccountType.USER)
|
||||||
serialised = acct.model_dump_json()
|
serialised = acct.model_dump_json()
|
||||||
print(serialised)
|
print(serialised)
|
||||||
|
|
||||||
|
|||||||
@@ -44,36 +44,3 @@ class TestIsolatedSimComponent:
|
|||||||
comp = TestComponent(name="computer", size=(5, 10))
|
comp = TestComponent(name="computer", size=(5, 10))
|
||||||
dump = comp.model_dump_json()
|
dump = comp.model_dump_json()
|
||||||
assert comp == TestComponent.model_validate_json(dump)
|
assert comp == TestComponent.model_validate_json(dump)
|
||||||
|
|
||||||
def test_apply_action(self):
|
|
||||||
"""Validate that we can override apply_action behaviour and it updates the state of the component."""
|
|
||||||
|
|
||||||
class TestComponent(SimComponent):
|
|
||||||
name: str
|
|
||||||
status: Literal["on", "off"] = "off"
|
|
||||||
|
|
||||||
def describe_state(self) -> Dict:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def _possible_actions(self) -> Dict[str, Callable[[List[str]], None]]:
|
|
||||||
return {
|
|
||||||
"turn_off": self._turn_off,
|
|
||||||
"turn_on": self._turn_on,
|
|
||||||
}
|
|
||||||
|
|
||||||
def _turn_off(self, options: List[str]) -> None:
|
|
||||||
assert len(options) == 0, "This action does not support options."
|
|
||||||
self.status = "off"
|
|
||||||
|
|
||||||
def _turn_on(self, options: List[str]) -> None:
|
|
||||||
assert len(options) == 0, "This action does not support options."
|
|
||||||
self.status = "on"
|
|
||||||
|
|
||||||
comp = TestComponent(name="computer", status="off")
|
|
||||||
|
|
||||||
assert comp.status == "off"
|
|
||||||
comp.apply_action(["turn_on"])
|
|
||||||
assert comp.status == "on"
|
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
|
||||||
comp.apply_action(["do_nothing"])
|
|
||||||
|
|||||||
Reference in New Issue
Block a user