diff --git a/api_events/tasks2events/employee_tasks/super_user.py b/api_events/tasks2events/employee_tasks/super_user.py index 0980a8c..478aa5b 100644 --- a/api_events/tasks2events/employee_tasks/super_user.py +++ b/api_events/tasks2events/employee_tasks/super_user.py @@ -86,7 +86,9 @@ class SuperUserEventBlock(AddEventFunctionality): {"function_code": "36961d8a-cefa-46cc-9f7c-9d841d6351b6"}, {"function_code": "46d90119-3b23-4784-8053-fe11da4a3584"}, {"function_code": "c786e15c-c03e-4e8f-936c-7e5e5ec9bbcc"}, - {"function_code": ""}, + {"function_code": "f6900cb5-ac5b-478e-8e7c-fa87e65cd2e5"}, + {"function_code": "76f11a08-5f4a-4e1f-961f-aaef21699acd"}, + {"function_code": "41ea7f29-006a-4310-b5c4-b2a0e1a504bd"}, ] def __new__(cls, *args, **kwargs): diff --git a/api_validations/validations_request/building.py b/api_validations/validations_request/building.py index 1a00902..88147f2 100644 --- a/api_validations/validations_request/building.py +++ b/api_validations/validations_request/building.py @@ -6,7 +6,7 @@ from api_validations.validations_request import ( ) -class InsertBuild(PydanticBaseModel): +class InsertBuild(BaseModelRegular): gov_address_code: str build_name: str build_types_uu_id: str diff --git a/api_validations/validations_request/people.py b/api_validations/validations_request/people.py index 0ab6419..e48beca 100644 --- a/api_validations/validations_request/people.py +++ b/api_validations/validations_request/people.py @@ -6,7 +6,7 @@ from api_validations.validations_request import ( ) -class InsertPerson(PydanticBaseModel): +class InsertPerson(BaseModelRegular): firstname: str surname: str sex_code: str diff --git a/databases/sql_models/building/build.py b/databases/sql_models/building/build.py index 1c9a340..276438c 100644 --- a/databases/sql_models/building/build.py +++ b/databases/sql_models/building/build.py @@ -237,13 +237,16 @@ class Build(CrudCollection, SelectActionWithEmployee): data_dict = data.excluded_dump() data_dict["address_id"] = None if data.address_uu_id: - official_address = Addresses.find_one(uu_id=data.address_uu_id) + official_address = Addresses.filter_one( + Addresses.uu_id==data.address_uu_id, + *Addresses.valid_record_args(Addresses) + ).data data_dict["address_id"] = official_address.id data_dict["build_no"] = str(official_address.build_number) - del data_dict["address_uu_id"] + data_dict.pop("address_uu_id", None) if not data_dict["address_id"]: raise HTTPException( - status_code=status.HTTP_418_IM_A_TEAPOT, + status_code=status.HTTP_404_NOT_FOUND, detail="Address is not found in database. Re-enter address record then try again.", ) build_type = BuildTypes.find_one(uu_id=str(data.build_types_uu_id)) diff --git a/databases/sql_models/identity/identity.py b/databases/sql_models/identity/identity.py index 2ecf783..60f4077 100644 --- a/databases/sql_models/identity/identity.py +++ b/databases/sql_models/identity/identity.py @@ -36,7 +36,7 @@ class UsersTokens(CrudCollection): token_type: Mapped[str] = mapped_column(String(16), server_default="RememberMe") token: Mapped[str] = mapped_column(String, server_default="") domain: Mapped[str] = mapped_column(String, server_default="") - expires_at = mapped_column( + expires_at: Mapped[TIMESTAMP] = mapped_column( TIMESTAMP, default=str(system_arrow.shift(date=system_arrow.now(), days=3)) ) @@ -56,16 +56,16 @@ class Users(CrudCollection, UserLoginModule, SelectAction): "related_company", ] - user_tag = mapped_column( + user_tag: Mapped[str] = mapped_column( String(64), server_default="", comment="Unique tag for the user", index=True ) - email = mapped_column( + email: Mapped[str] = mapped_column( String(128), server_default="", comment="Email address of the user", index=True ) - phone_number = mapped_column( + phone_number: Mapped[str] = mapped_column( String, server_default="", comment="Phone number of the user", index=True ) - via = mapped_column( + via: Mapped[str] = mapped_column( String, server_default="111", comment="Email 1/ Phone 2/ User Tag 3 All 111 Only 100", @@ -84,13 +84,13 @@ class Users(CrudCollection, UserLoginModule, SelectAction): Boolean, server_default="0", comment="Flag to remember user login" ) - password_expires_day = mapped_column( + password_expires_day: Mapped[str] = mapped_column( "expires_day", String, server_default=str(Auth.PASSWORD_EXPIRE_DAY), comment="Password expires in days", ) - password_expiry_begins = mapped_column( + password_expiry_begins: Mapped[TIMESTAMP] = mapped_column( "expiry_begins", TIMESTAMP, server_default=func.now(), @@ -98,10 +98,10 @@ class Users(CrudCollection, UserLoginModule, SelectAction): ) related_company: Mapped[str] = mapped_column(String, comment="Related Company UUID") - person_id = mapped_column( + person_id: Mapped[int] = mapped_column( ForeignKey("people.id"), nullable=False, comment="Foreign key to person table" ) - person_uu_id = mapped_column( + person_uu_id: Mapped[str] = mapped_column( String, server_default="", comment="Person UUID", index=True ) person = relationship("People", back_populates="user", foreign_keys=[person_id]) @@ -177,7 +177,10 @@ class Users(CrudCollection, UserLoginModule, SelectAction): def get_employee_and_duty_details(self): from databases import Employees, Duties - found_person = People.find_one(id=self.person_id) + found_person = People.filter_one( + People.id==self.person_id, + *People.valid_record_args(People), + ) found_employees = Employees.filter_by_active( people_id=found_person.id, is_confirmed=True ) @@ -228,14 +231,14 @@ class RelationshipDutyPeople(CrudCollection): company_id: Mapped[int] = mapped_column( ForeignKey("companies.id"), nullable=False ) # 1, 2, 3 - duties_id = mapped_column( + duties_id: Mapped[int] = mapped_column( ForeignKey("duties.id"), nullable=False ) # duty -> (n)person Evyos LTD member_id: Mapped[int] = mapped_column( ForeignKey("people.id"), nullable=False ) # 2, 3, 4 - relationship_type = mapped_column( + relationship_type: Mapped[str] = mapped_column( String, nullable=True, server_default="Employee" ) # Commercial show_only: Mapped[bool] = mapped_column(Boolean, server_default="0") @@ -312,7 +315,7 @@ class People(CrudCollection, SelectAction): birth_place: Mapped[str] = mapped_column( String, server_default="", comment="Birth place of the person" ) - birth_date = mapped_column( + birth_date: Mapped[TIMESTAMP] = mapped_column( TIMESTAMP, server_default="1900-01-01", comment="Birth date of the person" ) tax_no: Mapped[str] = mapped_column( @@ -391,7 +394,7 @@ class RelationshipEmployee2PostCode(CrudCollection): ForeignKey("address_postcode.id"), nullable=False ) - relationship_type = mapped_column( + relationship_type: Mapped[str] = mapped_column( String, nullable=True, server_default="Employee" ) # Commercial show_only: Mapped[bool] = mapped_column(Boolean, server_default="0") @@ -410,8 +413,8 @@ class AddressPostcode(CrudCollection, SelectActionWithEmployee): __many__table__ = RelationshipEmployee2PostCode street_id: Mapped[int] = mapped_column(ForeignKey("address_street.id")) - street_uu_id = mapped_column(String, server_default="", comment="Street UUID") - postcode = mapped_column(String(32), nullable=False, comment="Postcode") + street_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Street UUID") + postcode: Mapped[str] = mapped_column(String(32), nullable=False, comment="Postcode") __table_args__ = ({"comment": "Postcode Information"},) @@ -450,10 +453,10 @@ class Addresses(CrudCollection): street_id: Mapped[int] = mapped_column( ForeignKey("address_street.id"), nullable=False ) - street_uu_id = mapped_column(String, server_default="", comment="Street UUID") + street_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Street UUID") @classmethod - def list_via_employee(cls, token_dict, filter_expr): + def list_via_employee(cls, token_dict, filter_expr = None): post_code_list = RelationshipEmployee2PostCode.filter_all( RelationshipEmployee2PostCode.employee_id == token_dict.selected_company.employee_id, @@ -470,7 +473,7 @@ class Addresses(CrudCollection): cls.pre_query = cls.filter_all( cls.post_code_id.in_(post_code_id_list), cls.valid_record_args(cls) ).query - filter_cls = cls.filter_all(*filter_expr) + filter_cls = cls.filter_all(*filter_expr or []) cls.pre_query = None return filter_cls.data @@ -524,28 +527,28 @@ class AddressGeographicLocations(CrudCollection): __tablename__ = "address_geographic_locations" __exclude__fields__ = [] - geo_table = mapped_column(String, nullable=False, comment="Address Table Name") - geo_id = mapped_column(Integer, nullable=False, comment="Address Table ID") - geo_name = mapped_column(String, nullable=False, comment="Geographic Location Name") - geo_latitude = mapped_column( + geo_table: Mapped[str] = mapped_column(String, nullable=False, comment="Address Table Name") + geo_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="Address Table ID") + geo_name: Mapped[str] = mapped_column(String, nullable=False, comment="Geographic Location Name") + geo_latitude: Mapped[float] = mapped_column( Numeric(20, 6), server_default="0", comment="Geographic Location Name" ) - geo_longitude = mapped_column( + geo_longitude: Mapped[float] = mapped_column( Numeric(20, 6), server_default="0", comment="Geographic Location Latitude" ) - geo_altitude = mapped_column( + geo_altitude: Mapped[float] = mapped_column( Numeric(20, 6), server_default="0", comment="Geographic Location Longitude" ) - geo_description = mapped_column( + geo_description: Mapped[str] = mapped_column( Text, nullable=False, comment="Geographic Location Description" ) - geo_area_size = mapped_column( + geo_area_size: Mapped[float] = mapped_column( Numeric(20, 2), nullable=True, server_default="0", comment="Geographic Location Area Size", ) - geo_population = mapped_column( + geo_population: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Geographic Location Population" ) # geo_geom_point = mapped_column(Geometry('POINT', srid=4326), nullable=True, comment="Geographic Location Points") @@ -569,11 +572,11 @@ class AddressCountry(CrudCollection): __tablename__ = "address_country" __exclude__fields__ = [] - country_code = mapped_column(String(16), nullable=False, comment="Country Code") - country_name = mapped_column(String, nullable=False, comment="Country Name") - money_code = mapped_column(String(12), nullable=True, comment="Money Code") - language = mapped_column(String, nullable=True, comment="Language Code") - address_geographic_id = mapped_column( + country_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="Country Code") + country_name: Mapped[str] = mapped_column(String, nullable=False, comment="Country Name") + money_code: Mapped[str] = mapped_column(String(12), nullable=True, comment="Money Code") + language: Mapped[str] = mapped_column(String, nullable=True, comment="Language Code") + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) @@ -592,17 +595,17 @@ class AddressState(CrudCollection): __tablename__ = "address_state" __exclude__fields__ = [] - state_code = mapped_column(String(16), nullable=False, comment="State Code") - state_name = mapped_column(String, nullable=False, comment="State Name") - licence_plate = mapped_column(String(24), nullable=True, comment="Sign Code") - phone_code = mapped_column(String(36), nullable=True, comment="Phone Code") - gov_code = mapped_column(String(128), nullable=True, comment="Government Code") - address_geographic_id = mapped_column( + state_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="State Code") + state_name: Mapped[str] = mapped_column(String, nullable=False, comment="State Name") + licence_plate: Mapped[str] = mapped_column(String(24), nullable=True, comment="Sign Code") + phone_code: Mapped[str] = mapped_column(String(36), nullable=True, comment="Phone Code") + gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code") + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) country_id: Mapped[int] = mapped_column(ForeignKey("address_country.id")) - country_uu_id = mapped_column(String, server_default="", comment="Country UUID") + country_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Country UUID") __table_args__ = ( Index( @@ -623,17 +626,17 @@ class AddressCity(CrudCollection): __tablename__ = "address_city" __exclude__fields__ = [] - city_code = mapped_column(String(24), nullable=False, comment="City Code") - city_name = mapped_column(String, nullable=False, comment="City Name") - licence_plate = mapped_column(String(24), nullable=True, comment="Sign Code") - phone_code = mapped_column(String(36), nullable=True, comment="Phone Code") - gov_code = mapped_column(String(128), nullable=True, comment="Government Code") - address_geographic_id = mapped_column( + city_code: Mapped[str] = mapped_column(String(24), nullable=False, comment="City Code") + city_name: Mapped[str] = mapped_column(String, nullable=False, comment="City Name") + licence_plate: Mapped[str] = mapped_column(String(24), nullable=True, comment="Sign Code") + phone_code: Mapped[str] = mapped_column(String(36), nullable=True, comment="Phone Code") + gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code") + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) state_id: Mapped[int] = mapped_column(ForeignKey("address_state.id")) - state_uu_id = mapped_column(String, server_default="", comment="State UUID") + state_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="State UUID") __table_args__ = ( Index( @@ -654,18 +657,18 @@ class AddressDistrict(CrudCollection): __tablename__ = "address_district" __exclude__fields__ = [] - district_code = mapped_column(String(16), nullable=False, comment="District Code") - district_name = mapped_column(String, nullable=False, comment="District Name") - phone_code = mapped_column(String(36), nullable=True, comment="Phone Code") - gov_code = mapped_column(String(128), nullable=True, comment="Government Code") - address_geographic_id = mapped_column( + district_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="District Code") + district_name: Mapped[str] = mapped_column(String, nullable=False, comment="District Name") + phone_code: Mapped[str] = mapped_column(String(36), nullable=True, comment="Phone Code") + gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code") + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) - city_id = mapped_column( + city_id: Mapped[int] = mapped_column( ForeignKey("address_city.id"), nullable=False, comment="City ID" ) - city_uu_id = mapped_column(String, server_default="", comment="City UUID") + city_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="City UUID") __table_args__ = ( Index( @@ -686,20 +689,20 @@ class AddressLocality(CrudCollection): __tablename__ = "address_locality" __exclude__fields__ = [] - locality_code = mapped_column(String(16), nullable=False, comment="Locality Code") - locality_name = mapped_column(String, nullable=False, comment="Locality Name") - type_code = mapped_column(String, nullable=True, comment="Type Name") - type_description = mapped_column(String, nullable=True, comment="Type Name") - gov_code = mapped_column(String(128), nullable=True, comment="Government Code") + locality_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="Locality Code") + locality_name: Mapped[str] = mapped_column(String, nullable=False, comment="Locality Name") + type_code: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name") + type_description: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name") + gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code") address_show: Mapped[bool] = mapped_column(Boolean, server_default="1") - address_geographic_id = mapped_column( + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) - district_id = mapped_column( + district_id: Mapped[int] = mapped_column( ForeignKey("address_district.id"), nullable=False, comment="District ID" ) - district_uu_id = mapped_column(String, server_default="", comment="District UUID") + district_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="District UUID") __table_args__ = ( Index( @@ -720,28 +723,28 @@ class AddressNeighborhood(CrudCollection): __tablename__ = "address_neighborhood" __exclude__fields__ = [] - neighborhood_code = mapped_column( + neighborhood_code: Mapped[str] = mapped_column( String(16), nullable=False, comment="Neighborhood Code" ) - neighborhood_name = mapped_column( + neighborhood_name: Mapped[str] = mapped_column( String, nullable=False, comment="Neighborhood Name" ) - type_code = mapped_column(String, nullable=True, comment="Type Name") - type_description = mapped_column(String, nullable=True, comment="Type Name") - gov_code = mapped_column(String(128), nullable=True, comment="Government Code") + type_code: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name") + type_description: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name") + gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code") address_show: Mapped[bool] = mapped_column(Boolean, server_default="1") - address_geographic_id = mapped_column( + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) - district_id = mapped_column( + district_id: Mapped[int] = mapped_column( ForeignKey("address_district.id"), nullable=True, comment="District ID" ) - district_uu_id = mapped_column(String, server_default="", comment="District UUID") - locality_id = mapped_column( + district_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="District UUID") + locality_id: Mapped[int] = mapped_column( ForeignKey("address_locality.id"), nullable=True, comment="Locality ID" ) - locality_uu_id = mapped_column(String, server_default="", comment="Locality UUID") + locality_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Locality UUID") __table_args__ = ( Index( @@ -762,19 +765,19 @@ class AddressStreet(CrudCollection): __tablename__ = "address_street" __exclude__fields__ = [] - street_code = mapped_column(String(16), nullable=False, comment="Street Code") - street_name = mapped_column(String, nullable=False, comment="Street Name") - type_code = mapped_column(String, nullable=True, comment="Type Name") - type_description = mapped_column(String, nullable=True, comment="Type Name") - gov_code = mapped_column(String(128), nullable=True, comment="Government Code") + street_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="Street Code") + street_name: Mapped[str] = mapped_column(String, nullable=False, comment="Street Name") + type_code: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name") + type_description: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name") + gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code") - address_geographic_id = mapped_column( + address_geographic_id: Mapped[int] = mapped_column( BigInteger, nullable=True, comment="Address Geographic Id" ) - neighborhood_id = mapped_column( + neighborhood_id: Mapped[int] = mapped_column( ForeignKey("address_neighborhood.id"), nullable=False, comment="Neighborhood ID" ) - neighborhood_uu_id = mapped_column( + neighborhood_uu_id: Mapped[str] = mapped_column( String, server_default="", comment="Neighborhood UUID" ) @@ -855,11 +858,11 @@ class OccupantTypes(CrudCollection): __tablename__ = "occupant_types" __exclude__fields__ = [] - occupant_type = mapped_column(String, nullable=False, comment="Occupant Type") - occupant_description = mapped_column(String, server_default="") - occupant_code = mapped_column(String, server_default="") - occupant_category = mapped_column(String, server_default="") - occupant_category_type = mapped_column(String, server_default="") + occupant_type: Mapped[str] = mapped_column(String, nullable=False, comment="Occupant Type") + occupant_description: Mapped[str] = mapped_column(String, server_default="") + occupant_code: Mapped[str] = mapped_column(String, server_default="") + occupant_category: Mapped[str] = mapped_column(String, server_default="") + occupant_category_type: Mapped[str] = mapped_column(String, server_default="") occupant_is_unique: Mapped[bool] = mapped_column(Boolean, server_default="0") __table_args__ = ({"comment": "Occupant Types Information"},) @@ -884,39 +887,39 @@ class Contracts(CrudCollection): __tablename__ = "contracts" __exclude__fields__ = [] - contract_type = mapped_column( + contract_type: Mapped[str] = mapped_column( String(5), nullable=False, comment="The code for personnel is P and the code for companies is C.", ) - contract_title = mapped_column(String(255)) - contract_details = mapped_column(Text) - contract_terms = mapped_column(Text) + contract_title: Mapped[str] = mapped_column(String(255)) + contract_details: Mapped[str] = mapped_column(Text) + contract_terms: Mapped[str] = mapped_column(Text) - contract_code = mapped_column( + contract_code: Mapped[str] = mapped_column( String(100), nullable=False, comment="contract_code is the unique code given by the system.", ) - contract_date = mapped_column( + contract_date: Mapped[TIMESTAMP] = mapped_column( TIMESTAMP, server_default="2099-12-31 23:59:59", comment="contract date is the date the contract is made. " "expire start is the start date of the contract, expire en is the end date of the contract.", ) - company_id = mapped_column(Integer, ForeignKey("companies.id"), nullable=True) - company_uu_id = mapped_column(String, server_default="", comment="Company UUID") + company_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=True) + company_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Company UUID") - person_id = mapped_column(Integer, ForeignKey("people.id"), nullable=True) - person_uu_id = mapped_column(String, server_default="", comment="Person UUID") + person_id: Mapped[int] = mapped_column(Integer, ForeignKey("people.id"), nullable=True) + person_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Person UUID") @classmethod def retrieve_contact_no(cls): - import arrow + # from api_library.date_time_actions.date_functions import system_arrow # todo When create record contract_code == below string - related_date, counter = arrow.now(), 1 + related_date, counter = Contracts.client_arrow.now(), 1 return ( f"{related_date.date().year}{str(cls.contract_type)}{str(counter).zfill(6)}" ) diff --git a/service_app_test/test_application/evyos/address_building.py b/service_app_test/test_application/evyos/address_building.py index 09e1bc7..31c689c 100644 --- a/service_app_test/test_application/evyos/address_building.py +++ b/service_app_test/test_application/evyos/address_building.py @@ -93,7 +93,8 @@ def create_post_code(post_code, requester): ) print("text", post_code_response.text) print("json", post_code_response.json()) - return + code_response = post_code_response.json() + return code_response def create_addresses(address, requester): diff --git a/service_app_test/test_application/migrate_old_data/building.py b/service_app_test/test_application/migrate_old_data/building.py index fb82d45..1079666 100644 --- a/service_app_test/test_application/migrate_old_data/building.py +++ b/service_app_test/test_application/migrate_old_data/building.py @@ -1,4 +1,5 @@ from service_app_test.api_configs import BothAPIS +from service_app_test.test_application.evyos.address_building import post_code_dict from service_app_test.test_application.migrate_old_data.reader_and_alchemy_bulk_actions import ( read_json_file, ) @@ -73,6 +74,14 @@ def get_build_iban_from_json(): return with_pydantic +address_dict = lambda post_code_uu_id: { + "post_code_uu_id": post_code_uu_id, + "comment_address": "Reşat Nuri Cad No 11", + "letter_address": "Reşat Nuri Cad No 11 ÇANKAYA ANKARA TÜRKİYE", + "short_letter_address": "Reşat Nuri Cad No 11 ÇANKAYA ANKARA TÜRKİYE", + "build_number": "11", +} + def get_build_living_space_from_json(): read_files_json, with_pydantic = read_json_file(json_file="build_living_space"), [] read_files = read_files_json.get("build_living_space") @@ -84,20 +93,75 @@ def get_build_living_space_from_json(): return with_pydantic +def create_address(requester: BothAPIS, post_code): + post_code_response = requester.local_api.post( + endpoint="/postcode/create", + data=post_code, + ) + print("post_code_response", post_code_response.text) + response_post_code = post_code_response.json() + return response_post_code + + +def search_street(search_text, requester): + response = requester.local_api.post( + endpoint="/address/search", + data={ + "search": search_text, + "list_options": { + "page": 1, + "size": 30, + }, + }, + ) + response_object = response.json() + print("text", response.text) + print("response_object", response_object) + + for street_data in response_object.get("data"): + condition_of_street = ( + street_data["AddressCity.city_name"] == "ANKARA" + and street_data["AddressDistrict.district_name"] == "ÇANKAYA" + ) + if condition_of_street: + print("street_uu_id", street_data["AddressStreet.uu_id"]) + return street_data["AddressStreet.uu_id"] + + +def create_addresses(address, requester): + address_response = requester.local_api.post( + endpoint="/address/create", + data=address, + ) + print("text", address_response.text) + print("json", address_response.json()) + response_address = address_response.json() + return response_address + + def migrate_build(requester: BothAPIS): + street_uu_id = search_street("Reşat Nuri", requester=requester) + response_post_code = create_address(requester=requester, post_code=post_code_dict(uu_id_street=street_uu_id)) + print("response_post_code", response_post_code) + created_address = create_addresses( + address=address_dict(post_code_uu_id=response_post_code["data"]["uu_id"]), + requester=requester + ) + print('created_address', created_address) + created_address_uu_id = created_address["data"]["uu_id"] for response_data in get_build_from_json(): print("response_data", response_data) + response_data["address_uu_id"] = created_address_uu_id + exit() response = requester.local_api.post(**requester_dict_build(data=response_data)) + print("response", response.text) if response.ok: - migrate_build_area( - requester=requester, build_uu_id=response_data["build_uu_id"] - ) - migrate_build_part( - requester=requester, build_uu_id=response_data["build_uu_id"] - ) - migrate_build_iban( - requester=requester, build_uu_id=response_data["build_uu_id"] - ) + build_uu_id = response.json()["data"]["uu_id"] + print("response build_uu_id", build_uu_id) + exit() + migrate_build_area(requester=requester, build_uu_id=build_uu_id) + migrate_build_part(requester=requester, build_uu_id=build_uu_id) + migrate_build_iban(requester=requester, build_uu_id=build_uu_id) return diff --git a/service_app_test/test_application/migrate_old_data/people.py b/service_app_test/test_application/migrate_old_data/people.py index 76eead3..205ca2d 100644 --- a/service_app_test/test_application/migrate_old_data/people.py +++ b/service_app_test/test_application/migrate_old_data/people.py @@ -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 diff --git a/service_app_test/test_application/migrate_old_data/runner.py b/service_app_test/test_application/migrate_old_data/runner.py index ecdfa64..b59cc04 100644 --- a/service_app_test/test_application/migrate_old_data/runner.py +++ b/service_app_test/test_application/migrate_old_data/runner.py @@ -13,7 +13,7 @@ login_data = { "access_key": "karatay.berkay.sup@evyos.com.tr", "password": "string", "remember_me": False, - "password_token": "", + "password_token": "Jx4t2JM3Xc_yNGCBe-hk_4c299ov51_s20kQueVUjm-NJU0KGWENm3alGfyGO6-y79esC5WtuhXHAsw35XJYFn-UOdUAvuW6kbHk-F2MTNbavXMp2f_UdkPrav0PppZEQ2TRcIJQ6DzFWO0ONOxJMhcGTUbqxO4DfidKiq_VjYUqfwcl6ZxSsJolctLzyfwf", } login_data_wag = { "domain": "evyos.com.tr", @@ -32,13 +32,13 @@ wag_api.selected_object = wag_api.login_via_email_and_password( local_api = RequestToApi() local_api.overwrite_base_url(base_url=LocalAPI.base_url) local_api.selected_object = local_api.login_via_email_and_password( - login_data=login_data, is_password_valid=True + login_data=login_data, is_password_valid=False ) both_apis = BothAPIS() both_apis.wag_api = wag_api both_apis.local_api = local_api -migrate_company(requester=both_apis) -migrate_people(requester=both_apis) +# migrate_company(requester=both_apis) +# migrate_people(requester=both_apis) migrate_build(requester=both_apis)