diff --git a/tests/web/views/test_orders.py b/tests/web/views/test_orders.py index 98d00cd..89d5039 100644 --- a/tests/web/views/test_orders.py +++ b/tests/web/views/test_orders.py @@ -1074,18 +1074,27 @@ class TestOrderView(WebTestCase): local = model.LocalCustomer(first_name='Jack', last_name='Black', phone_number='555-1234') self.session.add(local) - order.local_customer = local self.session.flush() # viewing (local customer) with patch.object(view, 'viewing', new=True): - form = view.make_form(model_instance=order) - # nb. this is to avoid include/exclude ambiguity - form.remove('items') - view.configure_form(form) - self.assertNotIn('pending_customer', form) - schema = form.get_schema() - self.assertIsInstance(schema['total_price'].typ, WuttaMoney) + with patch.object(order, 'local_customer', new=local): + form = view.make_form(model_instance=order) + # nb. this is to avoid include/exclude ambiguity + form.remove('items') + view.configure_form(form) + self.assertNotIn('pending_customer', form) + schema = form.get_schema() + self.assertIsInstance(schema['total_price'].typ, WuttaMoney) + + # local customer is hidden if missing when customer_id is set + with patch.object(view, 'viewing', new=True): + with patch.object(order, 'customer_id', new='42'): + form = view.make_form(model_instance=order) + # nb. this is to avoid include/exclude ambiguity + form.remove('items') + view.configure_form(form) + self.assertNotIn('local_customer', form) def test_get_xref_buttons(self): self.pyramid_config.add_route('neworder_batches.view', '/batch/neworder/{uuid}')