fix: format all code with black
and from now on should not deviate from that...
This commit is contained in:
parent
925235f0d3
commit
2107e9ee1d
47 changed files with 5729 additions and 3977 deletions
|
@ -17,10 +17,10 @@ class TestOrderRef(WebTestCase):
|
|||
self.assertIsNot(sorted_query, query)
|
||||
|
||||
def test_get_object_url(self):
|
||||
self.pyramid_config.add_route('orders.view', '/orders/{uuid}')
|
||||
self.pyramid_config.add_route("orders.view", "/orders/{uuid}")
|
||||
model = self.app.model
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
order = model.Order(order_id=42, created_by=user)
|
||||
self.session.add(order)
|
||||
|
@ -29,7 +29,7 @@ class TestOrderRef(WebTestCase):
|
|||
typ = mod.OrderRef(self.request, session=self.session)
|
||||
url = typ.get_object_url(order)
|
||||
self.assertIsNotNone(url)
|
||||
self.assertIn(f'/orders/{order.uuid}', url)
|
||||
self.assertIn(f"/orders/{order.uuid}", url)
|
||||
|
||||
|
||||
class TestLocalCustomerRef(WebTestCase):
|
||||
|
@ -43,7 +43,7 @@ class TestLocalCustomerRef(WebTestCase):
|
|||
self.assertIsNot(sorted_query, query)
|
||||
|
||||
def test_get_object_url(self):
|
||||
self.pyramid_config.add_route('local_customers.view', '/local/customers/{uuid}')
|
||||
self.pyramid_config.add_route("local_customers.view", "/local/customers/{uuid}")
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
||||
|
@ -54,7 +54,7 @@ class TestLocalCustomerRef(WebTestCase):
|
|||
typ = mod.LocalCustomerRef(self.request, session=self.session)
|
||||
url = typ.get_object_url(customer)
|
||||
self.assertIsNotNone(url)
|
||||
self.assertIn(f'/local/customers/{customer.uuid}', url)
|
||||
self.assertIn(f"/local/customers/{customer.uuid}", url)
|
||||
|
||||
|
||||
class TestPendingCustomerRef(WebTestCase):
|
||||
|
@ -68,21 +68,24 @@ class TestPendingCustomerRef(WebTestCase):
|
|||
self.assertIsNot(sorted_query, query)
|
||||
|
||||
def test_get_object_url(self):
|
||||
self.pyramid_config.add_route('pending_customers.view', '/pending/customers/{uuid}')
|
||||
self.pyramid_config.add_route(
|
||||
"pending_customers.view", "/pending/customers/{uuid}"
|
||||
)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
self.session.commit()
|
||||
|
||||
typ = mod.PendingCustomerRef(self.request, session=self.session)
|
||||
url = typ.get_object_url(customer)
|
||||
self.assertIsNotNone(url)
|
||||
self.assertIn(f'/pending/customers/{customer.uuid}', url)
|
||||
self.assertIn(f"/pending/customers/{customer.uuid}", url)
|
||||
|
||||
|
||||
class TestLocalProductRef(WebTestCase):
|
||||
|
@ -96,7 +99,7 @@ class TestLocalProductRef(WebTestCase):
|
|||
self.assertIsNot(sorted_query, query)
|
||||
|
||||
def test_get_object_url(self):
|
||||
self.pyramid_config.add_route('local_products.view', '/local/products/{uuid}')
|
||||
self.pyramid_config.add_route("local_products.view", "/local/products/{uuid}")
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
||||
|
@ -107,7 +110,7 @@ class TestLocalProductRef(WebTestCase):
|
|||
typ = mod.LocalProductRef(self.request, session=self.session)
|
||||
url = typ.get_object_url(product)
|
||||
self.assertIsNotNone(url)
|
||||
self.assertIn(f'/local/products/{product.uuid}', url)
|
||||
self.assertIn(f"/local/products/{product.uuid}", url)
|
||||
|
||||
|
||||
class TestPendingProductRef(WebTestCase):
|
||||
|
@ -121,18 +124,21 @@ class TestPendingProductRef(WebTestCase):
|
|||
self.assertIsNot(sorted_query, query)
|
||||
|
||||
def test_get_object_url(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
self.pyramid_config.add_route(
|
||||
"pending_products.view", "/pending/products/{uuid}"
|
||||
)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
self.session.commit()
|
||||
|
||||
typ = mod.PendingProductRef(self.request, session=self.session)
|
||||
url = typ.get_object_url(product)
|
||||
self.assertIsNotNone(url)
|
||||
self.assertIn(f'/pending/products/{product.uuid}', url)
|
||||
self.assertIn(f"/pending/products/{product.uuid}", url)
|
||||
|
|
|
@ -13,7 +13,7 @@ from sideshow.web import app as mod
|
|||
class TestMain(DataTestCase):
|
||||
|
||||
def test_coverage(self):
|
||||
app = mod.main({}, **{'wutta_config': self.config})
|
||||
app = mod.main({}, **{"wutta_config": self.config})
|
||||
self.assertIsInstance(app, Router)
|
||||
|
||||
|
||||
|
|
|
@ -9,12 +9,15 @@ class TestSideshowMenuHandler(WebTestCase):
|
|||
def test_make_menus(self):
|
||||
handler = mod.SideshowMenuHandler(self.config)
|
||||
menus = handler.make_menus(self.request)
|
||||
titles = [menu['title'] for menu in menus]
|
||||
self.assertEqual(titles, [
|
||||
'Orders',
|
||||
'Customers',
|
||||
'Products',
|
||||
'Batches',
|
||||
'Other',
|
||||
'Admin',
|
||||
])
|
||||
titles = [menu["title"] for menu in menus]
|
||||
self.assertEqual(
|
||||
titles,
|
||||
[
|
||||
"Orders",
|
||||
"Customers",
|
||||
"Products",
|
||||
"Batches",
|
||||
"Other",
|
||||
"Admin",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -33,16 +33,16 @@ class TestNewOrderBatchView(WebTestCase):
|
|||
|
||||
# store_id not exposed by default
|
||||
grid = view.make_grid(model_class=model.NewOrderBatch)
|
||||
self.assertIn('store_id', grid.columns)
|
||||
self.assertIn("store_id", grid.columns)
|
||||
view.configure_grid(grid)
|
||||
self.assertNotIn('store_id', grid.columns)
|
||||
self.assertNotIn("store_id", grid.columns)
|
||||
|
||||
# store_id is exposed if configured
|
||||
self.config.setdefault('sideshow.orders.expose_store_id', 'true')
|
||||
self.config.setdefault("sideshow.orders.expose_store_id", "true")
|
||||
grid = view.make_grid(model_class=model.NewOrderBatch)
|
||||
self.assertIn('store_id', grid.columns)
|
||||
self.assertIn("store_id", grid.columns)
|
||||
view.configure_grid(grid)
|
||||
self.assertIn('store_id', grid.columns)
|
||||
self.assertIn("store_id", grid.columns)
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
|
@ -50,74 +50,85 @@ class TestNewOrderBatchView(WebTestCase):
|
|||
view = self.make_view()
|
||||
handler = view.batch_handler
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
batch = handler.make_batch(self.session, pending_customer=customer, created_by=user)
|
||||
batch = handler.make_batch(
|
||||
self.session, pending_customer=customer, created_by=user
|
||||
)
|
||||
self.session.add(batch)
|
||||
self.session.commit()
|
||||
|
||||
# viewing
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
with patch.object(view, "viewing", new=True):
|
||||
form = view.make_form(model_instance=batch)
|
||||
view.configure_form(form)
|
||||
schema = form.get_schema()
|
||||
self.assertIsInstance(schema['pending_customer'].typ, PendingCustomerRef)
|
||||
self.assertIsInstance(schema['total_price'].typ, WuttaMoney)
|
||||
self.assertIsInstance(schema["pending_customer"].typ, PendingCustomerRef)
|
||||
self.assertIsInstance(schema["total_price"].typ, WuttaMoney)
|
||||
|
||||
# store_id not exposed by default
|
||||
form = view.make_form(model_instance=batch)
|
||||
self.assertIn('store_id', form)
|
||||
self.assertIn("store_id", form)
|
||||
view.configure_form(form)
|
||||
self.assertNotIn('store_id', form)
|
||||
self.assertNotIn("store_id", form)
|
||||
|
||||
# store_id is exposed if configured
|
||||
self.config.setdefault('sideshow.orders.expose_store_id', 'true')
|
||||
self.config.setdefault("sideshow.orders.expose_store_id", "true")
|
||||
form = view.make_form(model_instance=batch)
|
||||
self.assertIn('store_id', form)
|
||||
self.assertIn("store_id", form)
|
||||
view.configure_form(form)
|
||||
self.assertIn('store_id', form)
|
||||
self.assertIn("store_id", form)
|
||||
|
||||
def test_configure_row_grid(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
grid = view.make_grid(model_class=model.NewOrderBatchRow)
|
||||
self.assertNotIn('total_price', grid.renderers)
|
||||
self.assertNotIn("total_price", grid.renderers)
|
||||
view.configure_row_grid(grid)
|
||||
self.assertIn('total_price', grid.renderers)
|
||||
self.assertIn("total_price", grid.renderers)
|
||||
|
||||
def test_get_xref_buttons(self):
|
||||
self.pyramid_config.add_route('orders.view', '/orders/{uuid}')
|
||||
self.pyramid_config.add_route("orders.view", "/orders/{uuid}")
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
handler = view.batch_handler
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
|
||||
# 1st batch has no order
|
||||
batch = handler.make_batch(self.session, pending_customer=customer, created_by=user)
|
||||
batch = handler.make_batch(
|
||||
self.session, pending_customer=customer, created_by=user
|
||||
)
|
||||
self.session.add(batch)
|
||||
self.session.flush()
|
||||
buttons = view.get_xref_buttons(batch)
|
||||
self.assertEqual(len(buttons), 0)
|
||||
|
||||
# 2nd batch is executed; has order
|
||||
batch = handler.make_batch(self.session, pending_customer=customer, created_by=user,
|
||||
executed=datetime.datetime.now(), executed_by=user)
|
||||
batch = handler.make_batch(
|
||||
self.session,
|
||||
pending_customer=customer,
|
||||
created_by=user,
|
||||
executed=datetime.datetime.now(),
|
||||
executed_by=user,
|
||||
)
|
||||
self.session.add(batch)
|
||||
self.session.flush()
|
||||
order = model.Order(order_id=batch.id, created_by=user)
|
||||
self.session.add(order)
|
||||
self.session.flush()
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(view, "Session", return_value=self.session):
|
||||
# nb. this also requires perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
buttons = view.get_xref_buttons(batch)
|
||||
self.assertEqual(len(buttons), 1)
|
||||
|
|
|
@ -19,11 +19,11 @@ class TestCommonView(WebTestCase):
|
|||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
self.session.flush()
|
||||
|
||||
self.assertEqual(len(user.roles), 0)
|
||||
view.setup_enhance_admin_user(user)
|
||||
self.assertEqual(len(user.roles), 1)
|
||||
self.assertEqual(user.roles[0].name, 'Order Admin')
|
||||
self.assertEqual(user.roles[0].name, "Order Admin")
|
||||
|
|
|
@ -25,43 +25,43 @@ class TestLocalCustomerView(WebTestCase):
|
|||
model = self.app.model
|
||||
view = self.make_view()
|
||||
grid = view.make_grid(model_class=model.LocalCustomer)
|
||||
self.assertNotIn('full_name', grid.linked_columns)
|
||||
self.assertNotIn("full_name", grid.linked_columns)
|
||||
view.configure_grid(grid)
|
||||
self.assertIn('full_name', grid.linked_columns)
|
||||
self.assertIn("full_name", grid.linked_columns)
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
# creating
|
||||
with patch.object(view, 'creating', new=True):
|
||||
with patch.object(view, "creating", new=True):
|
||||
form = view.make_form(model_class=model.LocalCustomer)
|
||||
view.configure_form(form)
|
||||
self.assertNotIn('external_id', form)
|
||||
self.assertNotIn('full_name', form)
|
||||
self.assertNotIn('orders', form)
|
||||
self.assertNotIn('new_order_batches', form)
|
||||
self.assertNotIn("external_id", form)
|
||||
self.assertNotIn("full_name", form)
|
||||
self.assertNotIn("orders", form)
|
||||
self.assertNotIn("new_order_batches", form)
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.LocalCustomer()
|
||||
self.session.add(customer)
|
||||
self.session.commit()
|
||||
|
||||
# viewing
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
with patch.object(view, "viewing", new=True):
|
||||
form = view.make_form(model_instance=customer)
|
||||
view.configure_form(form)
|
||||
self.assertIn('external_id', form)
|
||||
self.assertIn('full_name', form)
|
||||
self.assertIn('orders', form)
|
||||
self.assertIn('new_order_batches', form)
|
||||
self.assertIn("external_id", form)
|
||||
self.assertIn("full_name", form)
|
||||
self.assertIn("orders", form)
|
||||
self.assertIn("new_order_batches", form)
|
||||
|
||||
def test_make_orders_grid(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.LocalCustomer()
|
||||
self.session.add(customer)
|
||||
|
@ -74,21 +74,23 @@ class TestLocalCustomerView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_orders_grid(customer)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_make_new_order_batches_grid(self):
|
||||
model = self.app.model
|
||||
handler = NewOrderBatchHandler(self.config)
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.LocalCustomer()
|
||||
self.session.add(customer)
|
||||
batch = handler.make_batch(self.session, local_customer=customer, created_by=user)
|
||||
batch = handler.make_batch(
|
||||
self.session, local_customer=customer, created_by=user
|
||||
)
|
||||
self.session.add(batch)
|
||||
self.session.commit()
|
||||
|
||||
|
@ -97,31 +99,36 @@ class TestLocalCustomerView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_new_order_batches_grid(customer)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_objectify(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
self.session.commit()
|
||||
|
||||
with patch.object(view, 'creating', new=True):
|
||||
with patch.object(self.request, 'user', new=user):
|
||||
with patch.object(view, "creating", new=True):
|
||||
with patch.object(self.request, "user", new=user):
|
||||
form = view.make_model_form()
|
||||
with patch.object(form, 'validated', create=True, new={
|
||||
'first_name': 'Chuck',
|
||||
'last_name': 'Norris',
|
||||
}):
|
||||
with patch.object(
|
||||
form,
|
||||
"validated",
|
||||
create=True,
|
||||
new={
|
||||
"first_name": "Chuck",
|
||||
"last_name": "Norris",
|
||||
},
|
||||
):
|
||||
customer = view.objectify(form)
|
||||
self.assertIsInstance(customer, model.LocalCustomer)
|
||||
self.assertEqual(customer.first_name, 'Chuck')
|
||||
self.assertEqual(customer.last_name, 'Norris')
|
||||
self.assertEqual(customer.full_name, 'Chuck Norris')
|
||||
self.assertEqual(customer.first_name, "Chuck")
|
||||
self.assertEqual(customer.last_name, "Norris")
|
||||
self.assertEqual(customer.full_name, "Chuck Norris")
|
||||
|
||||
|
||||
class TestPendingCustomerView(WebTestCase):
|
||||
|
@ -135,7 +142,7 @@ class TestPendingCustomerView(WebTestCase):
|
|||
# nb. mostly just getting coverage here
|
||||
grid = view.make_grid(model_class=model.PendingCustomer)
|
||||
view.configure_grid(grid)
|
||||
self.assertIn('full_name', grid.linked_columns)
|
||||
self.assertIn("full_name", grid.linked_columns)
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
|
@ -143,41 +150,43 @@ class TestPendingCustomerView(WebTestCase):
|
|||
view = self.make_view()
|
||||
|
||||
# creating
|
||||
with patch.object(view, 'creating', new=True):
|
||||
with patch.object(view, "creating", new=True):
|
||||
form = view.make_form(model_class=model.PendingCustomer)
|
||||
view.configure_form(form)
|
||||
self.assertNotIn('status', form)
|
||||
self.assertNotIn('created', form)
|
||||
self.assertNotIn('created_by', form)
|
||||
self.assertNotIn('orders', form)
|
||||
self.assertNotIn('new_order_batches', form)
|
||||
self.assertNotIn("status", form)
|
||||
self.assertNotIn("created", form)
|
||||
self.assertNotIn("created_by", form)
|
||||
self.assertNotIn("orders", form)
|
||||
self.assertNotIn("new_order_batches", form)
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
self.session.commit()
|
||||
|
||||
# viewing
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
with patch.object(view, "viewing", new=True):
|
||||
form = view.make_form(model_instance=customer)
|
||||
view.configure_form(form)
|
||||
self.assertIn('status', form)
|
||||
self.assertIn('created', form)
|
||||
self.assertIn('created_by', form)
|
||||
self.assertIn('orders', form)
|
||||
self.assertIn('new_order_batches', form)
|
||||
self.assertIn("status", form)
|
||||
self.assertIn("created", form)
|
||||
self.assertIn("created_by", form)
|
||||
self.assertIn("orders", form)
|
||||
self.assertIn("new_order_batches", form)
|
||||
|
||||
def test_make_orders_grid(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
order = model.Order(order_id=42, pending_customer=customer, created_by=user)
|
||||
self.session.add(order)
|
||||
|
@ -188,10 +197,10 @@ class TestPendingCustomerView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_orders_grid(customer)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_make_new_order_batches_grid(self):
|
||||
model = self.app.model
|
||||
|
@ -199,12 +208,15 @@ class TestPendingCustomerView(WebTestCase):
|
|||
handler = NewOrderBatchHandler(self.config)
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
batch = handler.make_batch(self.session, pending_customer=customer, created_by=user)
|
||||
batch = handler.make_batch(
|
||||
self.session, pending_customer=customer, created_by=user
|
||||
)
|
||||
self.session.add(batch)
|
||||
self.session.commit()
|
||||
|
||||
|
@ -213,44 +225,54 @@ class TestPendingCustomerView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_new_order_batches_grid(customer)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_objectify(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
self.session.commit()
|
||||
|
||||
with patch.object(view, 'creating', new=True):
|
||||
with patch.object(self.request, 'user', new=user):
|
||||
with patch.object(view, "creating", new=True):
|
||||
with patch.object(self.request, "user", new=user):
|
||||
form = view.make_model_form()
|
||||
with patch.object(form, 'validated', create=True, new={
|
||||
'full_name': "Fred Flinstone",
|
||||
}):
|
||||
with patch.object(
|
||||
form,
|
||||
"validated",
|
||||
create=True,
|
||||
new={
|
||||
"full_name": "Fred Flinstone",
|
||||
},
|
||||
):
|
||||
customer = view.objectify(form)
|
||||
self.assertIsInstance(customer, model.PendingCustomer)
|
||||
self.assertIs(customer.created_by, user)
|
||||
self.assertEqual(customer.status, enum.PendingCustomerStatus.PENDING)
|
||||
self.assertEqual(
|
||||
customer.status, enum.PendingCustomerStatus.PENDING
|
||||
)
|
||||
|
||||
def test_delete_instance(self):
|
||||
self.pyramid_config.add_route('pending_customers.view', '/pending/customers/{uuid}')
|
||||
self.pyramid_config.add_route(
|
||||
"pending_customers.view", "/pending/customers/{uuid}"
|
||||
)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
handler = NewOrderBatchHandler(self.config)
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
|
||||
# 1st customer is standalone, will be deleted
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
self.session.flush()
|
||||
self.assertEqual(self.session.query(model.PendingCustomer).count(), 1)
|
||||
|
@ -259,10 +281,13 @@ class TestPendingCustomerView(WebTestCase):
|
|||
self.assertEqual(self.session.query(model.PendingCustomer).count(), 0)
|
||||
|
||||
# 2nd customer is attached to new order batch, will not be deleted
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
batch = handler.make_batch(self.session, created_by=user, pending_customer=customer)
|
||||
batch = handler.make_batch(
|
||||
self.session, created_by=user, pending_customer=customer
|
||||
)
|
||||
self.session.add(batch)
|
||||
self.session.flush()
|
||||
self.assertEqual(self.session.query(model.PendingCustomer).count(), 1)
|
||||
|
@ -280,8 +305,9 @@ class TestPendingCustomerView(WebTestCase):
|
|||
self.assertEqual(self.session.query(model.PendingCustomer).count(), 0)
|
||||
|
||||
# 3rd customer is attached to order, will not be deleted
|
||||
customer = model.PendingCustomer(status=enum.PendingCustomerStatus.PENDING,
|
||||
created_by=user)
|
||||
customer = model.PendingCustomer(
|
||||
status=enum.PendingCustomerStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(customer)
|
||||
order = model.Order(order_id=42, created_by=user, pending_customer=customer)
|
||||
self.session.add(order)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,53 +25,56 @@ class TestLocalProductView(WebTestCase):
|
|||
model = self.app.model
|
||||
view = self.make_view()
|
||||
grid = view.make_grid(model_class=model.LocalProduct)
|
||||
self.assertNotIn('scancode', grid.linked_columns)
|
||||
self.assertNotIn('brand_name', grid.linked_columns)
|
||||
self.assertNotIn('description', grid.linked_columns)
|
||||
self.assertNotIn("scancode", grid.linked_columns)
|
||||
self.assertNotIn("brand_name", grid.linked_columns)
|
||||
self.assertNotIn("description", grid.linked_columns)
|
||||
view.configure_grid(grid)
|
||||
self.assertIn('scancode', grid.linked_columns)
|
||||
self.assertIn('brand_name', grid.linked_columns)
|
||||
self.assertIn('description', grid.linked_columns)
|
||||
self.assertIn("scancode", grid.linked_columns)
|
||||
self.assertIn("brand_name", grid.linked_columns)
|
||||
self.assertIn("description", grid.linked_columns)
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
# creating
|
||||
with patch.object(view, 'creating', new=True):
|
||||
with patch.object(view, "creating", new=True):
|
||||
form = view.make_form(model_class=model.LocalProduct)
|
||||
self.assertIn('external_id', form)
|
||||
self.assertIn("external_id", form)
|
||||
view.configure_form(form)
|
||||
self.assertNotIn('external_id', form)
|
||||
self.assertNotIn("external_id", form)
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
product = model.LocalProduct()
|
||||
self.session.add(product)
|
||||
self.session.commit()
|
||||
|
||||
# viewing
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
with patch.object(view, "viewing", new=True):
|
||||
form = view.make_form(model_instance=product)
|
||||
self.assertNotIn('external_id', form.readonly_fields)
|
||||
self.assertNotIn('local_products.view.orders', form.grid_vue_context)
|
||||
self.assertNotIn("external_id", form.readonly_fields)
|
||||
self.assertNotIn("local_products.view.orders", form.grid_vue_context)
|
||||
view.configure_form(form)
|
||||
self.assertIn('external_id', form.readonly_fields)
|
||||
self.assertIn('local_products.view.orders', form.grid_vue_context)
|
||||
self.assertIn("external_id", form.readonly_fields)
|
||||
self.assertIn("local_products.view.orders", form.grid_vue_context)
|
||||
|
||||
def test_make_orders_grid(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
order = model.Order(order_id=42, customer_id=42, created_by=user)
|
||||
product = model.LocalProduct()
|
||||
self.session.add(product)
|
||||
item = model.OrderItem(local_product=product,
|
||||
order_qty=1, order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_INITIATED)
|
||||
item = model.OrderItem(
|
||||
local_product=product,
|
||||
order_qty=1,
|
||||
order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_INITIATED,
|
||||
)
|
||||
order.items.append(item)
|
||||
self.session.add(order)
|
||||
self.session.commit()
|
||||
|
@ -81,10 +84,10 @@ class TestLocalProductView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_orders_grid(product)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_make_new_order_batches_grid(self):
|
||||
model = self.app.model
|
||||
|
@ -92,14 +95,15 @@ class TestLocalProductView(WebTestCase):
|
|||
handler = NewOrderBatchHandler(self.config)
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
product = model.LocalProduct()
|
||||
self.session.add(product)
|
||||
row = handler.make_row(local_product=product,
|
||||
order_qty=1, order_uom=enum.ORDER_UOM_UNIT)
|
||||
row = handler.make_row(
|
||||
local_product=product, order_qty=1, order_uom=enum.ORDER_UOM_UNIT
|
||||
)
|
||||
handler.add_row(batch, row)
|
||||
self.session.commit()
|
||||
|
||||
|
@ -108,10 +112,10 @@ class TestLocalProductView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_new_order_batches_grid(product)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
|
||||
class TestPendingProductView(WebTestCase):
|
||||
|
@ -124,13 +128,13 @@ class TestPendingProductView(WebTestCase):
|
|||
view = self.make_view()
|
||||
# nb. mostly just getting coverage here
|
||||
grid = view.make_grid(model_class=model.PendingProduct)
|
||||
self.assertNotIn('scancode', grid.linked_columns)
|
||||
self.assertNotIn('brand_name', grid.linked_columns)
|
||||
self.assertNotIn('description', grid.linked_columns)
|
||||
self.assertNotIn("scancode", grid.linked_columns)
|
||||
self.assertNotIn("brand_name", grid.linked_columns)
|
||||
self.assertNotIn("description", grid.linked_columns)
|
||||
view.configure_grid(grid)
|
||||
self.assertIn('scancode', grid.linked_columns)
|
||||
self.assertIn('brand_name', grid.linked_columns)
|
||||
self.assertIn('description', grid.linked_columns)
|
||||
self.assertIn("scancode", grid.linked_columns)
|
||||
self.assertIn("brand_name", grid.linked_columns)
|
||||
self.assertIn("description", grid.linked_columns)
|
||||
|
||||
def test_grid_row_class(self):
|
||||
enum = self.app.enum
|
||||
|
@ -143,7 +147,7 @@ class TestPendingProductView(WebTestCase):
|
|||
|
||||
# warning for ignored
|
||||
product.status = enum.PendingProductStatus.IGNORED
|
||||
self.assertEqual(view.grid_row_class(product, {}, 1), 'has-background-warning')
|
||||
self.assertEqual(view.grid_row_class(product, {}, 1), "has-background-warning")
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
|
@ -151,41 +155,46 @@ class TestPendingProductView(WebTestCase):
|
|||
view = self.make_view()
|
||||
|
||||
# creating
|
||||
with patch.object(view, 'creating', new=True):
|
||||
with patch.object(view, "creating", new=True):
|
||||
form = view.make_form(model_class=model.PendingProduct)
|
||||
view.configure_form(form)
|
||||
self.assertNotIn('created', form)
|
||||
self.assertNotIn('created_by', form)
|
||||
self.assertNotIn("created", form)
|
||||
self.assertNotIn("created_by", form)
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
self.session.commit()
|
||||
|
||||
# viewing
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
with patch.object(view, "viewing", new=True):
|
||||
form = view.make_form(model_instance=product)
|
||||
view.configure_form(form)
|
||||
self.assertIn('status', form)
|
||||
self.assertIn('created', form)
|
||||
self.assertIn('created_by', form)
|
||||
self.assertIn("status", form)
|
||||
self.assertIn("created", form)
|
||||
self.assertIn("created_by", form)
|
||||
|
||||
def test_make_orders_grid(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
order = model.Order(order_id=42, customer_id=42, created_by=user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
item = model.OrderItem(pending_product=product,
|
||||
order_qty=1, order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_INITIATED)
|
||||
item = model.OrderItem(
|
||||
pending_product=product,
|
||||
order_qty=1,
|
||||
order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_INITIATED,
|
||||
)
|
||||
order.items.append(item)
|
||||
self.session.add(order)
|
||||
self.session.commit()
|
||||
|
@ -195,10 +204,10 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_orders_grid(product)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_make_new_order_batches_grid(self):
|
||||
model = self.app.model
|
||||
|
@ -206,15 +215,17 @@ class TestPendingProductView(WebTestCase):
|
|||
handler = NewOrderBatchHandler(self.config)
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
row = handler.make_row(pending_product=product,
|
||||
order_qty=1, order_uom=enum.ORDER_UOM_UNIT)
|
||||
row = handler.make_row(
|
||||
pending_product=product, order_qty=1, order_uom=enum.ORDER_UOM_UNIT
|
||||
)
|
||||
handler.add_row(batch, row)
|
||||
self.session.commit()
|
||||
|
||||
|
@ -223,57 +234,60 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 0)
|
||||
|
||||
# with view perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = view.make_new_order_batches_grid(product)
|
||||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
|
||||
def test_get_template_context(self):
|
||||
enum = self.app.enum
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING)
|
||||
orig_context = {'instance': product}
|
||||
orig_context = {"instance": product}
|
||||
|
||||
# local setting omitted by default
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertNotIn('use_local_products', context)
|
||||
self.assertNotIn("use_local_products", context)
|
||||
|
||||
# still omitted even though 'viewing'
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
with patch.object(view, "viewing", new=True):
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertNotIn('use_local_products', context)
|
||||
self.assertNotIn("use_local_products", context)
|
||||
|
||||
# still omitted even though correct status
|
||||
product.status = enum.PendingProductStatus.READY
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertNotIn('use_local_products', context)
|
||||
self.assertNotIn("use_local_products", context)
|
||||
|
||||
# no longer omitted if user has perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertIn('use_local_products', context)
|
||||
self.assertIn("use_local_products", context)
|
||||
# nb. true by default
|
||||
self.assertTrue(context['use_local_products'])
|
||||
self.assertTrue(context["use_local_products"])
|
||||
|
||||
# accurately reflects config
|
||||
self.config.setdefault('sideshow.orders.use_local_products', 'false')
|
||||
self.config.setdefault("sideshow.orders.use_local_products", "false")
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertFalse(context['use_local_products'])
|
||||
self.assertFalse(context["use_local_products"])
|
||||
|
||||
def test_delete_instance(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
self.pyramid_config.add_route(
|
||||
"pending_products.view", "/pending/products/{uuid}"
|
||||
)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
handler = NewOrderBatchHandler(self.config)
|
||||
view = self.make_view()
|
||||
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
|
||||
# 1st product is standalone, will be deleted
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
self.session.flush()
|
||||
self.assertEqual(self.session.query(model.PendingProduct).count(), 1)
|
||||
|
@ -284,11 +298,13 @@ class TestPendingProductView(WebTestCase):
|
|||
# 2nd product is attached to new order batch, will not be deleted
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
row = handler.make_row(pending_product=product,
|
||||
order_qty=1, order_uom=enum.ORDER_UOM_UNIT)
|
||||
row = handler.make_row(
|
||||
pending_product=product, order_qty=1, order_uom=enum.ORDER_UOM_UNIT
|
||||
)
|
||||
handler.add_row(batch, row)
|
||||
self.session.flush()
|
||||
self.assertEqual(self.session.query(model.PendingProduct).count(), 1)
|
||||
|
@ -306,61 +322,74 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertEqual(self.session.query(model.PendingProduct).count(), 0)
|
||||
|
||||
def test_resolve(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
self.pyramid_config.add_route(
|
||||
"pending_products.view", "/pending/products/{uuid}"
|
||||
)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
# sample data
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
self.session.flush()
|
||||
|
||||
info = {
|
||||
'product_id': '07430500132',
|
||||
'scancode': '07430500132',
|
||||
'brand_name': "Bragg's",
|
||||
'description': "Apple Cider Vinegar",
|
||||
'size': "32oz",
|
||||
'weighed': False,
|
||||
'department_id': None,
|
||||
'department_name': None,
|
||||
'special_order': False,
|
||||
'vendor_name': None,
|
||||
'vendor_item_code': None,
|
||||
'case_size': 12,
|
||||
'unit_cost': 2.99,
|
||||
'unit_price_reg': 5.99,
|
||||
"product_id": "07430500132",
|
||||
"scancode": "07430500132",
|
||||
"brand_name": "Bragg's",
|
||||
"description": "Apple Cider Vinegar",
|
||||
"size": "32oz",
|
||||
"weighed": False,
|
||||
"department_id": None,
|
||||
"department_name": None,
|
||||
"special_order": False,
|
||||
"vendor_name": None,
|
||||
"vendor_item_code": None,
|
||||
"case_size": 12,
|
||||
"unit_cost": 2.99,
|
||||
"unit_price_reg": 5.99,
|
||||
}
|
||||
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(self.request, 'user', new=user):
|
||||
with patch.object(self.request, 'matchdict', new={'uuid': product.uuid}):
|
||||
with patch.object(view, "Session", return_value=self.session):
|
||||
with patch.object(self.request, "user", new=user):
|
||||
with patch.object(
|
||||
self.request, "matchdict", new={"uuid": product.uuid}
|
||||
):
|
||||
|
||||
# flash error if wrong status
|
||||
result = view.resolve()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertTrue(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(self.request.session.pop_flash('error'),
|
||||
["pending product does not have 'ready' status!"])
|
||||
self.assertTrue(self.request.session.peek_flash("error"))
|
||||
self.assertEqual(
|
||||
self.request.session.pop_flash("error"),
|
||||
["pending product does not have 'ready' status!"],
|
||||
)
|
||||
|
||||
# flash error if product_id not specified
|
||||
product.status = enum.PendingProductStatus.READY
|
||||
result = view.resolve()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertTrue(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(self.request.session.pop_flash('error'),
|
||||
["must specify valid product_id"])
|
||||
self.assertTrue(self.request.session.peek_flash("error"))
|
||||
self.assertEqual(
|
||||
self.request.session.pop_flash("error"),
|
||||
["must specify valid product_id"],
|
||||
)
|
||||
|
||||
# more sample data
|
||||
order = model.Order(order_id=100, created_by=user,
|
||||
customer_name="Fred Flintstone")
|
||||
item = model.OrderItem(pending_product=product,
|
||||
order_qty=1, order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_READY)
|
||||
order = model.Order(
|
||||
order_id=100, created_by=user, customer_name="Fred Flintstone"
|
||||
)
|
||||
item = model.OrderItem(
|
||||
pending_product=product,
|
||||
order_qty=1,
|
||||
order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_READY,
|
||||
)
|
||||
order.items.append(item)
|
||||
self.session.add(order)
|
||||
|
||||
|
@ -369,45 +398,58 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertEqual(product.status, enum.PendingProductStatus.READY)
|
||||
self.assertIsNone(item.product_id)
|
||||
batch_handler = NewOrderBatchHandler(self.config)
|
||||
with patch.object(batch_handler, 'get_product_info_external',
|
||||
return_value=info):
|
||||
with patch.object(self.app, 'get_batch_handler',
|
||||
return_value=batch_handler):
|
||||
with patch.object(self.request, 'POST',
|
||||
new={'product_id': '07430500132'}):
|
||||
with patch.object(batch_handler, 'get_product_info_external',
|
||||
return_value=info):
|
||||
with patch.object(
|
||||
batch_handler, "get_product_info_external", return_value=info
|
||||
):
|
||||
with patch.object(
|
||||
self.app, "get_batch_handler", return_value=batch_handler
|
||||
):
|
||||
with patch.object(
|
||||
self.request, "POST", new={"product_id": "07430500132"}
|
||||
):
|
||||
with patch.object(
|
||||
batch_handler,
|
||||
"get_product_info_external",
|
||||
return_value=info,
|
||||
):
|
||||
result = view.resolve()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertFalse(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(product.product_id, '07430500132')
|
||||
self.assertFalse(self.request.session.peek_flash("error"))
|
||||
self.assertEqual(product.product_id, "07430500132")
|
||||
self.assertEqual(product.status, enum.PendingProductStatus.RESOLVED)
|
||||
self.assertEqual(item.product_id, '07430500132')
|
||||
self.assertEqual(item.product_id, "07430500132")
|
||||
|
||||
def test_ignore(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
self.pyramid_config.add_route(
|
||||
"pending_products.view", "/pending/products/{uuid}"
|
||||
)
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
# sample data
|
||||
user = model.User(username='barney')
|
||||
user = model.User(username="barney")
|
||||
self.session.add(user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
product = model.PendingProduct(
|
||||
status=enum.PendingProductStatus.PENDING, created_by=user
|
||||
)
|
||||
self.session.add(product)
|
||||
self.session.flush()
|
||||
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(self.request, 'user', new=user):
|
||||
with patch.object(self.request, 'matchdict', new={'uuid': product.uuid}):
|
||||
with patch.object(view, "Session", return_value=self.session):
|
||||
with patch.object(self.request, "user", new=user):
|
||||
with patch.object(
|
||||
self.request, "matchdict", new={"uuid": product.uuid}
|
||||
):
|
||||
|
||||
# flash error if wrong status
|
||||
result = view.ignore()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertTrue(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(self.request.session.pop_flash('error'),
|
||||
["pending product does not have 'ready' status!"])
|
||||
self.assertTrue(self.request.session.peek_flash("error"))
|
||||
self.assertEqual(
|
||||
self.request.session.pop_flash("error"),
|
||||
["pending product does not have 'ready' status!"],
|
||||
)
|
||||
|
||||
# product updated
|
||||
product.status = enum.PendingProductStatus.READY
|
||||
|
@ -415,6 +457,6 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertEqual(product.status, enum.PendingProductStatus.READY)
|
||||
result = view.ignore()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertFalse(self.request.session.peek_flash('error'))
|
||||
self.assertFalse(self.request.session.peek_flash("error"))
|
||||
self.assertIsNone(product.product_id)
|
||||
self.assertEqual(product.status, enum.PendingProductStatus.IGNORED)
|
||||
|
|
|
@ -23,11 +23,11 @@ class TestStoreView(WebTestCase):
|
|||
model = self.app.model
|
||||
view = self.make_view()
|
||||
grid = view.make_grid(model_class=model.Store)
|
||||
self.assertNotIn('store_id', grid.linked_columns)
|
||||
self.assertNotIn('name', grid.linked_columns)
|
||||
self.assertNotIn("store_id", grid.linked_columns)
|
||||
self.assertNotIn("name", grid.linked_columns)
|
||||
view.configure_grid(grid)
|
||||
self.assertIn('store_id', grid.linked_columns)
|
||||
self.assertIn('name', grid.linked_columns)
|
||||
self.assertIn("store_id", grid.linked_columns)
|
||||
self.assertIn("name", grid.linked_columns)
|
||||
|
||||
def test_grid_row_class(self):
|
||||
model = self.app.model
|
||||
|
@ -39,7 +39,7 @@ class TestStoreView(WebTestCase):
|
|||
|
||||
store = model.Store(archived=True)
|
||||
self.assertTrue(store.archived)
|
||||
self.assertEqual(view.grid_row_class(store, {}, 0), 'has-background-warning')
|
||||
self.assertEqual(view.grid_row_class(store, {}, 0), "has-background-warning")
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
|
@ -47,48 +47,48 @@ class TestStoreView(WebTestCase):
|
|||
|
||||
# unique validators are set
|
||||
form = view.make_form(model_class=model.Store)
|
||||
self.assertNotIn('store_id', form.validators)
|
||||
self.assertNotIn('name', form.validators)
|
||||
self.assertNotIn("store_id", form.validators)
|
||||
self.assertNotIn("name", form.validators)
|
||||
view.configure_form(form)
|
||||
self.assertIn('store_id', form.validators)
|
||||
self.assertIn('name', form.validators)
|
||||
self.assertIn("store_id", form.validators)
|
||||
self.assertIn("name", form.validators)
|
||||
|
||||
def test_unique_store_id(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
store = model.Store(store_id='001', name='whatever')
|
||||
store = model.Store(store_id="001", name="whatever")
|
||||
self.session.add(store)
|
||||
self.session.commit()
|
||||
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(view, "Session", return_value=self.session):
|
||||
|
||||
# invalid if same store_id in data
|
||||
node = colander.SchemaNode(colander.String(), name='store_id')
|
||||
self.assertRaises(colander.Invalid, view.unique_store_id, node, '001')
|
||||
node = colander.SchemaNode(colander.String(), name="store_id")
|
||||
self.assertRaises(colander.Invalid, view.unique_store_id, node, "001")
|
||||
|
||||
# but not if store_id belongs to current store
|
||||
with patch.object(self.request, 'matchdict', new={'uuid': store.uuid}):
|
||||
with patch.object(view, 'editing', new=True):
|
||||
node = colander.SchemaNode(colander.String(), name='store_id')
|
||||
self.assertIsNone(view.unique_store_id(node, '001'))
|
||||
with patch.object(self.request, "matchdict", new={"uuid": store.uuid}):
|
||||
with patch.object(view, "editing", new=True):
|
||||
node = colander.SchemaNode(colander.String(), name="store_id")
|
||||
self.assertIsNone(view.unique_store_id(node, "001"))
|
||||
|
||||
def test_unique_name(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
||||
store = model.Store(store_id='001', name='Acme Goods')
|
||||
store = model.Store(store_id="001", name="Acme Goods")
|
||||
self.session.add(store)
|
||||
self.session.commit()
|
||||
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(view, "Session", return_value=self.session):
|
||||
|
||||
# invalid if same name in data
|
||||
node = colander.SchemaNode(colander.String(), name='name')
|
||||
self.assertRaises(colander.Invalid, view.unique_name, node, 'Acme Goods')
|
||||
node = colander.SchemaNode(colander.String(), name="name")
|
||||
self.assertRaises(colander.Invalid, view.unique_name, node, "Acme Goods")
|
||||
|
||||
# but not if name belongs to current store
|
||||
with patch.object(self.request, 'matchdict', new={'uuid': store.uuid}):
|
||||
with patch.object(view, 'editing', new=True):
|
||||
node = colander.SchemaNode(colander.String(), name='name')
|
||||
self.assertIsNone(view.unique_name(node, 'Acme Goods'))
|
||||
with patch.object(self.request, "matchdict", new={"uuid": store.uuid}):
|
||||
with patch.object(view, "editing", new=True):
|
||||
node = colander.SchemaNode(colander.String(), name="name")
|
||||
self.assertIsNone(view.unique_name(node, "Acme Goods"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue