Apply changes from code review.
This commit is contained in:
@@ -127,6 +127,7 @@ class SimComponent(BaseModel):
|
|||||||
"""Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator."""
|
"""Extension of pydantic BaseModel with additional methods that must be defined by all classes in the simulator."""
|
||||||
|
|
||||||
model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow)
|
model_config = ConfigDict(arbitrary_types_allowed=True, extra=Extra.allow)
|
||||||
|
"""Configure pydantic to allow arbitrary types and to let the instance have attributes not present in model."""
|
||||||
|
|
||||||
uuid: str
|
uuid: str
|
||||||
"""The component UUID."""
|
"""The component UUID."""
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ class Account(SimComponent):
|
|||||||
self.enabled = False
|
self.enabled = False
|
||||||
|
|
||||||
def log_on(self) -> None:
|
def log_on(self) -> None:
|
||||||
"""TODO."""
|
"""TODO. Once the accounts are integrated with nodes, populate this accordingly."""
|
||||||
self.num_logons += 1
|
self.num_logons += 1
|
||||||
|
|
||||||
def log_off(self) -> None:
|
def log_off(self) -> None:
|
||||||
"""TODO."""
|
"""TODO. Once the accounts are integrated with nodes, populate this accordingly."""
|
||||||
self.num_logoffs += 1
|
self.num_logoffs += 1
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ 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. If pydantic throws error then this test fails."""
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
def test_account_deserialise():
|
def test_account_deserialise():
|
||||||
"""Test that an account can be deserialised."""
|
"""Test that an account can be deserialised. The test fails if pydantic throws an error."""
|
||||||
acct_json = (
|
acct_json = (
|
||||||
'{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,'
|
'{"uuid":"dfb2bcaa-d3a1-48fd-af3f-c943354622b4","num_logons":0,"num_logoffs":0,"num_group_changes":0,'
|
||||||
'"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"action_manager":null}'
|
'"username":"Jake","password":"JakePass1!","account_type":2,"status":2,"action_manager":null}'
|
||||||
|
|||||||
Reference in New Issue
Block a user