diff --git a/make_post_sell/tests/test_physical_product_handling.py b/make_post_sell/tests/test_physical_product_handling.py index 0561ebd..605db08 100644 --- a/make_post_sell/tests/test_physical_product_handling.py +++ b/make_post_sell/tests/test_physical_product_handling.py @@ -139,15 +139,25 @@ class PhysicalProductHandlingTests(unittest.TestCase): self.dbsession.add(cart) self.dbsession.flush() + # Save IDs before commit + cart_id = cart.id + cart_uuid_str = cart.uuid_str + shop_uuid_str = shop.uuid_str + # Commit transaction transaction.manager.commit() + # Re-query cart to avoid detached instance error + from ..models.cart import get_cart_by_id + cart = get_cart_by_id(self.dbsession, cart_id) + # Verify cart has physical products self.assertEqual(cart.count, 1) self.assertTrue(len(cart.physical_products) > 0, "Cart should have physical products") # 5. Get cart page and verify handling options section appears - cart_res = self.testapp.get(f"/cart/{cart.id}") + # Need to pass shop_id so request.shop is set correctly + cart_res = self.testapp.get(f"/cart/{cart_id}?shop_id={shop_uuid_str}") cart_body = cart_res.body.decode() # Verify handling options form is present @@ -156,10 +166,10 @@ class PhysicalProductHandlingTests(unittest.TestCase): # 6. Submit handling option form with CSRF token # This is the critical test - the form MUST include CSRF token - csrf_token = self.get_csrf_token(shop.uuid_str) + csrf_token = self.get_csrf_token(shop_uuid_str) handling_res = self.testapp.post( - f"/cart/{cart.uuid_str}/handling-option", + f"/cart/{cart_uuid_str}/handling-option", { "handling_option": "local_pickup", "csrf_token": csrf_token, @@ -188,9 +198,9 @@ class PhysicalProductHandlingTests(unittest.TestCase): ("local_shipping", 750), ("international_shipping", 1500), ]: - csrf_token = self.get_csrf_token(shop.uuid_str) + csrf_token = self.get_csrf_token(shop_uuid_str) res = self.testapp.post( - f"/cart/{cart.uuid_str}/handling-option", + f"/cart/{cart_uuid_str}/handling-option", { "handling_option": option, "csrf_token": csrf_token,