test: preserve archived debug scripts
This commit is contained in:
91
tests/archive/test_event_file_model_debug.py
Normal file
91
tests/archive/test_event_file_model_debug.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import sys
|
||||
import os
|
||||
from typing import Optional, Union
|
||||
from pydantic import BaseModel, Field, root_validator
|
||||
|
||||
# Mock base_fields
|
||||
base_fields = {
|
||||
'event_file_id_random': {},
|
||||
'hosted_file_id_random': {},
|
||||
'obj_id_random': {},
|
||||
'event_id_random': {},
|
||||
'event_exhibit_id_random': {},
|
||||
'event_location_id_random': {},
|
||||
'event_presentation_id_random': {},
|
||||
'event_presenter_id_random': {},
|
||||
'event_session_id_random': {},
|
||||
'event_track_id_random': {},
|
||||
}
|
||||
|
||||
class Event_File_Base(BaseModel):
|
||||
id: Optional[Union[int, str]] = Field(None, **base_fields['event_file_id_random'])
|
||||
event_file_id: Optional[Union[int, str]] = Field(None, **base_fields['event_file_id_random'])
|
||||
hosted_file_id: Optional[Union[int, str]] = Field(None, **base_fields['hosted_file_id_random'])
|
||||
for_id: Optional[Union[int, str]] = Field(None, **base_fields['obj_id_random'])
|
||||
event_id: Optional[Union[int, str]] = Field(None, **base_fields['event_id_random'])
|
||||
event_exhibit_id: Optional[Union[int, str]] = Field(None, **base_fields['event_exhibit_id_random'])
|
||||
event_location_id: Optional[Union[int, str]] = Field(None, **base_fields['event_location_id_random'])
|
||||
event_presentation_id: Optional[Union[int, str]] = Field(None, **base_fields['event_presentation_id_random'])
|
||||
event_presenter_id: Optional[Union[int, str]] = Field(None, **base_fields['event_presenter_id_random'])
|
||||
event_session_id: Optional[Union[int, str]] = Field(None, **base_fields['event_session_id_random'])
|
||||
event_track_id: Optional[Union[int, str]] = Field(None, **base_fields['event_track_id_random'])
|
||||
|
||||
id_random: Optional[str] = Field(None, alias='event_file_id_random', exclude=True)
|
||||
hosted_file_id_random: Optional[str] = Field(None, exclude=True)
|
||||
for_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_exhibit_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_location_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_presentation_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_presenter_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_session_id_random: Optional[str] = Field(None, exclude=True)
|
||||
event_track_id_random: Optional[str] = Field(None, exclude=True)
|
||||
|
||||
@root_validator(pre=True)
|
||||
def map_v3_ids(cls, values):
|
||||
rid = values.get('id_random') or values.get('event_file_id_random')
|
||||
if rid and isinstance(rid, str):
|
||||
values['id'] = rid
|
||||
values['event_file_id'] = rid
|
||||
|
||||
if h_rid := values.get('hosted_file_id_random'): values['hosted_file_id'] = h_rid
|
||||
if f_rid := values.get('for_id_random'): values['for_id'] = f_rid
|
||||
if e_rid := values.get('event_id_random'): values['event_id'] = e_rid
|
||||
if ex_rid := values.get('event_exhibit_id_random'): values['event_exhibit_id'] = ex_rid
|
||||
if loc_rid := values.get('event_location_id_random'): values['event_location_id'] = loc_rid
|
||||
if pres_rid := values.get('event_presentation_id_random'): values['event_presentation_id'] = pres_rid
|
||||
if pr_rid := values.get('event_presenter_id_random'): values['event_presenter_id'] = pr_rid
|
||||
if s_rid := values.get('event_session_id_random'): values['event_session_id'] = s_rid
|
||||
if t_rid := values.get('event_track_id_random'): values['event_track_id'] = t_rid
|
||||
|
||||
id_fields = [
|
||||
'id', 'event_file_id', 'hosted_file_id', 'for_id', 'event_id',
|
||||
'event_exhibit_id', 'event_location_id', 'event_presentation_id',
|
||||
'event_presenter_id', 'event_session_id', 'event_track_id'
|
||||
]
|
||||
for k in id_fields:
|
||||
val = values.get(k)
|
||||
if val is not None and not isinstance(val, str):
|
||||
values[k] = None
|
||||
|
||||
return values
|
||||
|
||||
# Data from DB
|
||||
raw_data = {
|
||||
"id": "2982",
|
||||
"id_random": "a2pPIT_W28o",
|
||||
"hosted_file_id": "2726",
|
||||
"for_type": "event_presenter",
|
||||
"for_id": "1629",
|
||||
"event_id": "1",
|
||||
"event_session_id": "543",
|
||||
"event_presentation_id": "1118",
|
||||
"event_presenter_id": "1629",
|
||||
"event_file_id_random": "a2pPIT_W28o",
|
||||
"hosted_file_id_random": "lFmI035vUqqzqEomJw-sLA",
|
||||
"for_id_random": "uSEvog3bHJo" # Populated by methods.py
|
||||
}
|
||||
|
||||
print("Input Data:", raw_data)
|
||||
obj = Event_File_Base(**raw_data)
|
||||
print("\nOutput Data (dict):", obj.dict())
|
||||
Reference in New Issue
Block a user