Verified Commit 295c0aec authored by Jakob Moser's avatar Jakob Moser
Browse files

Add code to load a certification from a dict

parent 1e677200
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
from collections.abc import Mapping
from typing import Any, get_args

from coliverter.certifications.FachschaftCertification import FachschaftCertification

# The types of certification the coliverter can produce
type ColiCertification = FachschaftCertification

certification_classes: Mapping[str, type[ColiCertification]] = {
    cls.required_office_kind_name: cls
    for cls in get_args(ColiCertification.__value__)
}


def from_dict(certification_request: dict[str, Any]) -> ColiCertification:
    # Variable name has a capital C, because it is a class, so this makes the next line look nicer
    Certification = certification_classes[certification_request["office"]["kind"]["name"]]  # noqa: N806
    return Certification.from_dict(certification_request)