Source code for codegrade.models.verification_failed_heartbeat_response
"""The module that defines the ``VerificationFailedHeartbeatResponse`` model.
SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""
from __future__ import annotations
import datetime
import typing as t
from dataclasses import dataclass, field
import cg_request_args as rqa
from ..utils import to_dict
[docs]
@dataclass(kw_only=True)
class VerificationFailedHeartbeatResponse:
"""The exam environment rejected this heartbeat.
The refresh was skipped: the session is not invalidated, but it lapses at
`expires_at` unless a later heartbeat verifies. Clients should warn the
student to return to the exam environment.
"""
#: Discriminator.
tag: t.Literal["verification-failed"]
#: The unchanged session expiry.
expires_at: datetime.datetime
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: rqa.FixedMapping(
rqa.RequiredArgument(
"tag",
rqa.StringEnum("verification-failed"),
doc="Discriminator.",
),
rqa.RequiredArgument(
"expires_at",
rqa.RichValue.DateTime,
doc="The unchanged session expiry.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"tag": to_dict(self.tag),
"expires_at": to_dict(self.expires_at),
}
return res
@classmethod
def from_dict(
cls: t.Type[VerificationFailedHeartbeatResponse], d: t.Dict[str, t.Any]
) -> VerificationFailedHeartbeatResponse:
parsed = cls.data_parser.try_parse(d)
res = cls(
tag=parsed.tag,
expires_at=parsed.expires_at,
)
res.raw_data = d
return res