build & events updated

This commit is contained in:
2024-11-13 22:31:42 +03:00
parent 83b3a5989e
commit ac037ae54a
9 changed files with 215 additions and 145 deletions

View File

@@ -1,33 +1,30 @@
from service_app_test.api_configs import BothAPIS
from service_app_test.bases import FilterObject
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):
# Migrate old data
filter_object = FilterObject(
page=1,
size=100,
)
response = requester.wag_api.post(
endpoint="/people/list",
data=filter_object.dump(),
)
response_json = response.json()
response_datas = response_json["data"]
counter = 0
for response_data in response_datas:
new_response_data = dict()
for key, value in dict(response_data).items():
if value is not None and not str(value) == "None":
new_response_data[key] = response_data[key]
new_response_data.pop("uu_id", None)
print("new_response_data", new_response_data)
new_response_data["national_identity_id"] = f"000000000{str(counter).zfill(2)}"
response = requester.local_api.post(
endpoint="/people/create",
data=new_response_data,
)
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)
if response.ok:
counter += 1
return