31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import random
|
|
|
|
from service_app_test.api_configs import BothAPIS
|
|
from api_validations.validations_request import InsertPerson
|
|
from service_app_test.test_application.migrate_old_data.reader_and_alchemy_bulk_actions import (
|
|
read_json_file,
|
|
)
|
|
|
|
requester_dict_build = lambda data: {"endpoint": "/people/create", "data": data}
|
|
|
|
|
|
def get_people_from_json():
|
|
read_files_json, with_pydantic = read_json_file(json_file="people"), []
|
|
read_files = read_files_json.get("people")
|
|
for row in read_files:
|
|
pydantic_row = InsertPerson(**row)
|
|
with_pydantic.append(pydantic_row.model_dump())
|
|
if not with_pydantic:
|
|
raise Exception("No data found")
|
|
return with_pydantic
|
|
|
|
|
|
generate_random_national_identity_id = lambda n: str(random.randint(10 ** (n - 1), 10**n))
|
|
|
|
def migrate_people(requester: BothAPIS):
|
|
for response_data in get_people_from_json():
|
|
response_data["national_identity_id"] = generate_random_national_identity_id(11)
|
|
response = requester.local_api.post(**requester_dict_build(data=response_data))
|
|
print("response", response.text)
|
|
return
|