Source code for codegrade.models.verification_unavailable_heartbeat_response

"""The module that defines the ``VerificationUnavailableHeartbeatResponse`` 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 VerificationUnavailableHeartbeatResponse: """The exam environment could not be asked to verify this heartbeat. This says nothing about the student; the refresh was skipped and the next heartbeat simply retries. Clients should warn the student that their session may lapse if the provider stays unreachable. """ #: Discriminator. tag: t.Literal["verification-unavailable"] #: 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-unavailable"), 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[VerificationUnavailableHeartbeatResponse], d: t.Dict[str, t.Any], ) -> VerificationUnavailableHeartbeatResponse: parsed = cls.data_parser.try_parse(d) res = cls( tag=parsed.tag, expires_at=parsed.expires_at, ) res.raw_data = d return res