Update tests

This commit is contained in:
Marek Wolan
2023-08-09 09:19:11 +01:00
parent a3c2ae6c7d
commit 1de8e0a058
2 changed files with 1 additions and 34 deletions

View File

@@ -4,7 +4,7 @@ from primaite.simulator.domain.account import Account, AccountType
def test_account_serialise():
"""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()
print(serialised)

View File

@@ -44,36 +44,3 @@ class TestIsolatedSimComponent:
comp = TestComponent(name="computer", size=(5, 10))
dump = comp.model_dump_json()
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"])