save and confirmed added
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import random
|
||||
|
||||
from service_app_test.api_configs import BothAPIS
|
||||
from api_validations.validations_request import InsertPerson
|
||||
from api_validations.validations_request import InsertPerson, InsertUsers
|
||||
from service_app_test.test_application.migrate_old_data.reader_and_alchemy_bulk_actions import (
|
||||
read_json_file,
|
||||
)
|
||||
|
||||
# from service_app_test.test_application.evyos.people import generate_random_phone_number
|
||||
|
||||
requester_dict_build = lambda data: {"endpoint": "/people/create", "data": data}
|
||||
|
||||
|
||||
@@ -15,18 +17,40 @@ def get_people_from_json():
|
||||
for row in read_files:
|
||||
row["ref_id"] = row["uu_id"]
|
||||
pydantic_row = InsertPerson(**row)
|
||||
with_pydantic.append(pydantic_row.model_dump())
|
||||
data_dict = pydantic_row.model_dump()
|
||||
data_dict["email"] = row.get("emails")
|
||||
with_pydantic.append(data_dict)
|
||||
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))
|
||||
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():
|
||||
users_email = response_data.get("email")
|
||||
response_data["national_identity_id"] = generate_random_national_identity_id(11)
|
||||
response_data.pop("email", None)
|
||||
response = requester.local_api.post(**requester_dict_build(data=response_data))
|
||||
print("response", response.text)
|
||||
if response.ok:
|
||||
user_json = response.json().get("data", None)
|
||||
if not user_json:
|
||||
raise Exception("User can not be created user json is invalid")
|
||||
created_user = InsertUsers(
|
||||
people_uu_id=user_json.get("uu_id"),
|
||||
user_tag=user_json.get("firstname"),
|
||||
email=users_email,
|
||||
# phone_number=generate_random_phone_number(),
|
||||
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
|
||||
)
|
||||
response = requester.local_api.post(
|
||||
endpoint="/user/create",
|
||||
data=created_user.model_dump(),
|
||||
)
|
||||
print("response", response.text)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user