Mercurial > hg > orthanc-tests
diff NewTests/Authorization/models.py @ 577:0649a19df194
new tests for auth-service
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 08 Sep 2023 12:03:50 +0200 |
parents | 80ba6f1d521c |
children |
line wrap: on
line diff
--- a/NewTests/Authorization/models.py Wed Sep 06 17:04:36 2023 +0200 +++ b/NewTests/Authorization/models.py Fri Sep 08 12:03:50 2023 +0200 @@ -1,25 +1,9 @@ -# SPDX-FileCopyrightText: 2022 - 2023 Orthanc Team SRL <info@orthanc.team> -# -# SPDX-License-Identifier: GPL-3.0-or-later - from typing import Optional, List from pydantic import BaseModel, Field -from pydantic.datetime_parse import parse_datetime from enum import Enum from datetime import datetime -class StringDateTime(datetime): - @classmethod - def __get_validators__(cls): - yield parse_datetime - yield cls.validate - - @classmethod - def validate(cls, v: datetime): - return v.isoformat() - - class Levels(str, Enum): PATIENT = 'patient' STUDY = 'study' @@ -67,18 +51,18 @@ level: Levels class Config: # allow creating object from dict (used when deserializing the JWT) - allow_population_by_field_name = True + populate_by_name = True class TokenCreationRequest(BaseModel): id: Optional[str] = None resources: List[OrthancResource] type: TokenType = Field(default=TokenType.INVALID) - expiration_date: Optional[StringDateTime] = Field(alias="expiration-date", default=None) + expiration_date: Optional[datetime] = Field(alias="expiration-date", default=None) validity_duration: Optional[int] = Field(alias='validity-duration', default=None) # alternate way to provide an expiration_date, more convenient for instant-links since the duration is relative to the server time, not the client time ! class Config: # allow creating object from dict (used when deserializing the JWT) - allow_population_by_field_name = True + populate_by_name = True class TokenCreationResponse(BaseModel): @@ -95,7 +79,7 @@ server_id: Optional[str] = Field(alias="server-id", default=None) level: Optional[Levels] method: Methods - uri: Optional[str] + uri: Optional[str] = None # labels: Optional[List[str]] @@ -141,10 +125,9 @@ class UserProfileResponse(BaseModel): name: str authorized_labels: List[str] = Field(alias="authorized-labels", default_factory=list) - # authorized_labels: List[str] = Field(default_factory=list) permissions: List[UserPermissions] = Field(default_factory=list) validity: int class Config: use_enum_values = True - allow_population_by_field_name = True \ No newline at end of file + populate_by_name = True \ No newline at end of file