From a123341aa8194a089240d759762e3fc9552ba792 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Fri, 30 Jan 2026 10:16:28 +0100 Subject: [PATCH] fix: update test patch paths for module routes Update test files to use new module route paths: - test_password_reset.py: app.api.v1.shop.auth -> app.modules.customers.routes.api.storefront - test_addresses.py: app.api.v1.shop.addresses -> app.modules.customers.routes.api.storefront - test_orders.py: app.api.v1.shop.orders -> app.modules.orders.routes.api.storefront Note: Some tests still fail due to patching built-in functions incorrectly. These tests need further refactoring to match the new module architecture. Co-Authored-By: Claude Opus 4.5 --- .../api/v1/storefront/test_addresses.py | 38 +++++++++---------- .../api/v1/storefront/test_orders.py | 22 +++++------ .../api/v1/storefront/test_password_reset.py | 30 +++++++-------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/tests/integration/api/v1/storefront/test_addresses.py b/tests/integration/api/v1/storefront/test_addresses.py index 2ba612bf..b2f0db2c 100644 --- a/tests/integration/api/v1/storefront/test_addresses.py +++ b/tests/integration/api/v1/storefront/test_addresses.py @@ -162,7 +162,7 @@ class TestShopAddressesListAPI: def test_list_addresses_requires_authentication(self, client, test_vendor): """Test that listing addresses requires authentication.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.get("/api/v1/storefront/addresses") assert response.status_code in [401, 403] @@ -176,7 +176,7 @@ class TestShopAddressesListAPI: shop_customer, ): """Test listing customer addresses successfully.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -196,7 +196,7 @@ class TestShopAddressesListAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test listing addresses when customer has none.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -220,7 +220,7 @@ class TestShopAddressesListAPI: shop_customer, ): """Test listing addresses includes both shipping and billing.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -253,7 +253,7 @@ class TestShopAddressDetailAPI: shop_customer, ): """Test getting address details successfully.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -273,7 +273,7 @@ class TestShopAddressDetailAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test getting non-existent address returns 404.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -293,7 +293,7 @@ class TestShopAddressDetailAPI: shop_customer, ): """Test cannot access another customer's address.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -328,7 +328,7 @@ class TestShopAddressCreateAPI: "is_default": False, } - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -362,7 +362,7 @@ class TestShopAddressCreateAPI: "is_default": True, } - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -386,7 +386,7 @@ class TestShopAddressCreateAPI: # Missing required fields } - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -419,7 +419,7 @@ class TestShopAddressUpdateAPI: "city": "Esch-sur-Alzette", } - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -440,7 +440,7 @@ class TestShopAddressUpdateAPI: """Test updating non-existent address returns 404.""" update_data = {"first_name": "Test"} - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -463,7 +463,7 @@ class TestShopAddressUpdateAPI: """Test cannot update another customer's address.""" update_data = {"first_name": "Hacked"} - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -491,7 +491,7 @@ class TestShopAddressDeleteAPI: shop_customer, ): """Test deleting an address.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -506,7 +506,7 @@ class TestShopAddressDeleteAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test deleting non-existent address returns 404.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -526,7 +526,7 @@ class TestShopAddressDeleteAPI: shop_customer, ): """Test cannot delete another customer's address.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -572,7 +572,7 @@ class TestShopAddressSetDefaultAPI: db.commit() db.refresh(second_address) - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -589,7 +589,7 @@ class TestShopAddressSetDefaultAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test setting default on non-existent address returns 404.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -609,7 +609,7 @@ class TestShopAddressSetDefaultAPI: shop_customer, ): """Test cannot set default on another customer's address.""" - with patch("app.api.v1.shop.addresses.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.addresses.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer diff --git a/tests/integration/api/v1/storefront/test_orders.py b/tests/integration/api/v1/storefront/test_orders.py index 4d6ae875..a3b23c61 100644 --- a/tests/integration/api/v1/storefront/test_orders.py +++ b/tests/integration/api/v1/storefront/test_orders.py @@ -310,7 +310,7 @@ class TestShopOrdersListAPI: def test_list_orders_requires_authentication(self, client, test_vendor): """Test that listing orders requires authentication.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.get("/api/v1/storefront/orders") # Without token, should get 401 or 403 @@ -321,7 +321,7 @@ class TestShopOrdersListAPI: ): """Test listing customer orders successfully.""" # Mock vendor context and customer auth - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor # Mock the dependency to return our customer with patch("app.api.deps._validate_customer_token") as mock_validate: @@ -340,7 +340,7 @@ class TestShopOrdersListAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test listing orders when customer has none.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -364,7 +364,7 @@ class TestShopOrderDetailAPI: self, client, shop_customer_headers, shop_order, test_vendor, shop_customer ): """Test getting order details successfully.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -385,7 +385,7 @@ class TestShopOrderDetailAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test getting non-existent order returns 404.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -405,7 +405,7 @@ class TestShopOrderDetailAPI: shop_customer, ): """Test cannot access another customer's order.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -428,7 +428,7 @@ class TestShopOrderInvoiceDownloadAPI: self, client, shop_customer_headers, shop_order, test_vendor, shop_customer ): """Test cannot download invoice for pending orders.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -480,7 +480,7 @@ class TestShopOrderInvoiceDownloadAPI: shop_customer, ): """Test cannot download invoice for another customer's order.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -496,7 +496,7 @@ class TestShopOrderInvoiceDownloadAPI: self, client, shop_customer_headers, test_vendor, shop_customer ): """Test downloading invoice for non-existent order.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -518,7 +518,7 @@ class TestShopOrderVATFields: self, client, shop_customer_headers, shop_order, test_vendor, shop_customer ): """Test order response includes VAT fields.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer @@ -539,7 +539,7 @@ class TestShopOrderVATFields: self, client, shop_customer_headers, shop_order, test_vendor, shop_customer ): """Test order list includes VAT fields.""" - with patch("app.api.v1.shop.orders.getattr") as mock_getattr: + with patch("app.modules.orders.routes.api.storefront.getattr") as mock_getattr: mock_getattr.return_value = test_vendor with patch("app.api.deps._validate_customer_token") as mock_validate: mock_validate.return_value = shop_customer diff --git a/tests/integration/api/v1/storefront/test_password_reset.py b/tests/integration/api/v1/storefront/test_password_reset.py index 894cfbc3..0b94fdfd 100644 --- a/tests/integration/api/v1/storefront/test_password_reset.py +++ b/tests/integration/api/v1/storefront/test_password_reset.py @@ -110,11 +110,11 @@ class TestForgotPasswordAPI: self, client, db, test_vendor, shop_customer ): """Test password reset request for existing customer.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor # Mock email service to avoid actual email sending - with patch("app.api.v1.shop.auth.EmailService") as mock_email_service: + with patch("app.modules.customers.routes.api.storefront.auth.EmailService") as mock_email_service: mock_instance = MagicMock() mock_email_service.return_value = mock_instance @@ -135,7 +135,7 @@ class TestForgotPasswordAPI: def test_forgot_password_nonexistent_email(self, client, db, test_vendor): """Test password reset request for non-existent email (same response).""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -152,7 +152,7 @@ class TestForgotPasswordAPI: self, client, db, test_vendor, inactive_customer ): """Test password reset request for inactive customer.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -169,10 +169,10 @@ class TestForgotPasswordAPI: self, client, db, test_vendor, shop_customer ): """Test that forgot password creates a token in the database.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor - with patch("app.api.v1.shop.auth.EmailService"): + with patch("app.modules.customers.routes.api.storefront.auth.EmailService"): response = client.post( "/api/v1/storefront/auth/forgot-password", params={"email": shop_customer.email}, @@ -205,10 +205,10 @@ class TestForgotPasswordAPI: ) assert old_token_count == 1 - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor - with patch("app.api.v1.shop.auth.EmailService"): + with patch("app.modules.customers.routes.api.storefront.auth.EmailService"): response = client.post( "/api/v1/storefront/auth/forgot-password", params={"email": shop_customer.email}, @@ -238,7 +238,7 @@ class TestResetPasswordAPI: self, client, db, test_vendor, shop_customer, valid_reset_token ): """Test successful password reset.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor new_password = "newpassword123" @@ -267,7 +267,7 @@ class TestResetPasswordAPI: self, client, db, test_vendor, shop_customer, valid_reset_token ): """Test that token is marked as used after successful reset.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -290,7 +290,7 @@ class TestResetPasswordAPI: def test_reset_password_invalid_token(self, client, db, test_vendor): """Test reset with invalid token.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -307,7 +307,7 @@ class TestResetPasswordAPI: self, client, db, test_vendor, shop_customer, expired_reset_token ): """Test reset with expired token.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -324,7 +324,7 @@ class TestResetPasswordAPI: self, client, db, test_vendor, shop_customer, used_reset_token ): """Test reset with already used token.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -341,7 +341,7 @@ class TestResetPasswordAPI: self, client, db, test_vendor, shop_customer, valid_reset_token ): """Test reset with password that's too short.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor response = client.post( @@ -358,7 +358,7 @@ class TestResetPasswordAPI: self, client, db, test_vendor, shop_customer, valid_reset_token ): """Test that token cannot be reused after successful reset.""" - with patch("app.api.v1.shop.auth.getattr") as mock_getattr: + with patch("app.modules.customers.routes.api.storefront.auth.getattr") as mock_getattr: mock_getattr.return_value = test_vendor # First reset should succeed