From f4e5b5e0d228eb07d0432fd5c0220ae3bd71082c Mon Sep 17 00:00:00 2001 From: Anikesh Suresh Date: Thu, 17 Oct 2024 10:43:23 +0000 Subject: [PATCH] reformatted mock data script #338 --- .../scripts/expected_lifetime_migration.py | 34 ++++--------------- scripts/generate_mock_data.py | 2 +- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/inventory_management_system_api/migrations/scripts/expected_lifetime_migration.py b/inventory_management_system_api/migrations/scripts/expected_lifetime_migration.py index db10289b..cf312254 100644 --- a/inventory_management_system_api/migrations/scripts/expected_lifetime_migration.py +++ b/inventory_management_system_api/migrations/scripts/expected_lifetime_migration.py @@ -161,36 +161,14 @@ def forward(self, session: ClientSession): logger.info("expected_lifetime forward migration") for catalogue_item in catalogue_items: try: - old_item = OldCatalogueItemOut(**catalogue_item) - - new_item_data = { - "catalogue_category_id": old_item.catalogue_category_id, - "manufacturer_id": old_item.manufacturer_id, - "name": old_item.name, - "description": old_item.description, - "cost_gbp": old_item.cost_gbp, - "cost_to_rework_gbp": old_item.cost_to_rework_gbp, - "days_to_replace": old_item.days_to_replace, - "days_to_rework": old_item.days_to_rework, - "drawing_number": old_item.drawing_number, - "drawing_link": old_item.drawing_link, - "expected_lifetime": None, - "item_model_number": old_item.item_model_number, - "is_obsolete": old_item.is_obsolete, - "obsolete_reason": old_item.obsolete_reason, - "obsolete_replacement_catalogue_item_id": old_item.obsolete_replacement_catalogue_item_id, - "notes": old_item.notes, - "properties": old_item.properties, - "created_time": catalogue_item["created_time"], - "modified_time": catalogue_item["modified_time"], - } - - new_item = NewCatalogueItemIn(**new_item_data) - - update_data = new_item.model_dump() + old_catalogue_item = OldCatalogueItemOut(**catalogue_item.model_dump()) + + new_catalogue_item = NewCatalogueItemIn(**old_catalogue_item.model_dump()) + + update_data = {**new_catalogue_item.model_dump(), "modified_time": old_catalogue_item.modified_time} self._catalogue_items_collection.update_one( - {"_id": old_item.id}, {"$set": update_data}, session=session + {"_id": old_catalogue_item.id}, {"$set": update_data}, session=session ) except ValidationError as ve: diff --git a/scripts/generate_mock_data.py b/scripts/generate_mock_data.py index 0f6d39df..3830b747 100644 --- a/scripts/generate_mock_data.py +++ b/scripts/generate_mock_data.py @@ -350,7 +350,7 @@ def generate_random_catalogue_item( "days_to_rework": optional_catalogue_item_field(lambda: fake.random.randint(0, 100)), "drawing_number": optional_catalogue_item_field(lambda: str(fake.random.randint(1000, 10000))), "drawing_link": optional_catalogue_item_field(fake.image_url), - "expected_lifetime": optional_catalogue_item_field(lambda: fake.random.randint(1000,10000)), + "expected_lifetime": optional_catalogue_item_field(lambda: fake.random.randint(1000, 10000)), "item_model_number": optional_catalogue_item_field(fake.isbn13), "is_obsolete": bool(obsolete_replacement_catalogue_item_id), "obsolete_replacement_catalogue_item_id": obsolete_replacement_catalogue_item_id,