Source code for codegrade.models.exam_environment_response

"""The module that defines the ``ExamEnvironmentResponse`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from .. import parsers
from ..utils import to_dict
from .available_provider import AvailableProvider


[docs] @dataclass(kw_only=True) class ExamEnvironmentResponse: """The exam environment attachment options for a restriction.""" #: The provider types the tenant can attach to this restriction. Empty when #: the exam environment feature is disabled for the tenant or the tenant #: has no provider registered. available_providers: t.Sequence[AvailableProvider] 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( "available_providers", rqa.List(parsers.ParserFor.make(AvailableProvider)), doc="The provider types the tenant can attach to this restriction. Empty when the exam environment feature is disabled for the tenant or the tenant has no provider registered.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "available_providers": to_dict(self.available_providers), } return res @classmethod def from_dict( cls: t.Type[ExamEnvironmentResponse], d: t.Dict[str, t.Any] ) -> ExamEnvironmentResponse: parsed = cls.data_parser.try_parse(d) res = cls( available_providers=parsed.available_providers, ) res.raw_data = d return res