def test_all_page_rendered(self): user, password = of.user(role_names=[ 'sales_report_view', ]) db_util.save_objects_commit(user) fixture.login_user(self.test_client, user.email, password) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='overall')) self.assertPageRendered( endpoint=url_for('product_sales_report.index_view', type='today')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='yesterday')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='this_week')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='last_week')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='this_month')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='last_month')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='this_quarter')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='last_quarter')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='this_year')) self.assertPageRendered(endpoint=url_for( 'product_sales_report.index_view', type='last_year')) fixture.logout_user(self.test_client)
def test_all_page_rendered(self): user, password = of.user( role_names=['report_view', ] ) db_util.save_objects_commit(user) fixture.login_user(self.test_client, user.email, password) self.assertPageRendered(endpoint=url_for('sales_amount.index')) self.assertPageRendered(endpoint=url_for('sales_profit.index')) fixture.logout_user(self.test_client)
def test_sales_order_list_create_page(self): user, password = of.user( role_names=['direct_sales_order_create', 'direct_sales_order_view'] ) db_util.save_objects_commit(user) fixture.login_user(self.test_client, user.email, password) self.assertPageRendered(endpoint=url_for('salesorder.index_view')) self.assertPageRendered(endpoint=url_for('salesorder.create_view')) fixture.logout_user(self.test_client)
def test_all_page_rendered(self): user, password = of.user(role_names=[ 'report_view', ]) db_util.save_objects_commit(user) fixture.login_user(self.test_client, user.email, password) self.assertPageRendered(endpoint=url_for('sales_amount.index')) self.assertPageRendered(endpoint=url_for('sales_profit.index')) fixture.logout_user(self.test_client)
def test_purchase_order_hide_then_show_list_page(self): from psi.app.service import Info from psi.app.models.role import Role from psi.app.utils import save_objects_commit role = Info.get_db().session.query(Role).filter_by( name='purchase_price_view').first() user, password = object_faker.user( ['product_view', 'direct_purchase_order_view']) save_objects_commit(user, role) fixture.login_user(self.test_client, user.email, password) rv = self.test_client.get(url_for('dpo.index_view'), follow_redirects=True) self.assertEqual(rv.status_code, 200) self.assertNotIn( b'<th class="column-header col-goods_amount">', rv.data, b"goods amount should not exits in purchase order " b"list page") self.assertNotIn( b'<th class="column-header col-total_amount">', rv.data, b"total amount should not exits in purchase order " b"list page") self.assertNotIn( b'<th class="column-header col-all_expenses">', rv.data, b"all expenses should not exits in purchase order " b"list page") rv = self.test_client.get(url_for('product.index_view'), follow_redirects=True) self.assertNotIn( b'<th class="column-header col-purchase_price">', rv.data, b"purchase price field should not exit in product " b"list page") user.roles.append(role) save_objects_commit(user, role) rv = self.test_client.get(url_for('dpo.index_view'), follow_redirects=True) self.assertEqual(rv.status_code, 200) self.assertIn( b'<th class="column-header col-goods_amount">', rv.data, b"goods amount should exist in purchase order list page") self.assertIn( b'<th class="column-header col-total_amount">', rv.data, b"total amount should exist in purchase order list page") self.assertIn( b'<th class="column-header col-all_expenses">', rv.data, b"all expenses should exist in purchase order list page") rv = self.test_client.get(url_for('product.index_view'), follow_redirects=True) self.assertIn( b'<th class="column-header col-purchase_price">', rv.data, b"purchase price field should exits in product list page") fixture.logout_user(self.test_client)
def test_logic(): fixture.login_as_admin(self.test_client) user, password = object_faker.user(role_names=[ 'franchise_sales_order_create', 'franchise_sales_order_view', 'product_view' ]) sales_order = object_faker.sales_order(creator=user, number_of_line=1) db_util.save_objects_commit(sales_order, user) so_id = sales_order.id delivered_status = EnumValues.get(SO_DELIVERED_STATUS_KEY) fixture.logout_user(self.test_client) rv = self.test_client.put('/api/sales_order/' + str(so_id), follow_redirects=True, data=dict(status_id=delivered_status.id)) self.assertEqual(rv.status_code, 403)
def test_all_page_rendered(self): user, password = of.user( role_names=['sales_report_view', ] ) db_util.save_objects_commit(user) fixture.login_user(self.test_client, user.email, password) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='overall')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='today')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='yesterday')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_week')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_week')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_month')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_month')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_quarter')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_quarter')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_year')) self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_year')) fixture.logout_user(self.test_client)
def create_sales_order(self, status_key): from psi.app.models import EnumValues from psi.app.services.purchase_order import PurchaseOrderService user, password = of.user( role_names=['direct_sales_order_create', 'direct_sales_order_view', 'direct_sales_order_edit', 'direct_sales_order_delete'] ) db_util.save_objects_commit(user) fixture.login_as_admin(self.test_client) fixture.login_user(self.test_client, user.email, password) direct_po = EnumValues.get(const.DIRECT_PO_TYPE_KEY) po = of.purchase_order(number_of_line=2, type=direct_po, creator=user) po.status = EnumValues.get(const.PO_ISSUED_STATUS_KEY) fixture.login_as_admin(self.test_client) l_e, g_e, recv = PurchaseOrderService.create_expense_receiving(po) customer = of.customer(creator=user) db_util.save_objects_commit(po, l_e, g_e, recv, customer) fixture.logout_user(self.test_client) fixture.login_user(self.test_client, user.email, password) order_status = EnumValues.get(status_key) order_date = of.faker.date_time_this_year() logistic_amount = random.randint(0, 100) remark = of.faker.text(max_nb_chars=50) data = dict(customer=customer.id, status=order_status.id, order_date=order_date, logistic_amount=logistic_amount, remark=remark) total, data = self.prepare_so_lines_data_from_po(po, data) expect = [customer.name, order_status.display, order_date.strftime("%Y-%m-%d"), remark, str(total)] self.assertPageRendered(method=self.test_client.post, data=data, endpoint=url_for('salesorder.create_view', url=url_for( 'salesorder.index_view')), expect_contents=expect) return data, expect
def create_sales_order(self, status_key): from psi.app.models import EnumValues from psi.app.services.purchase_order import PurchaseOrderService user, password = of.user( role_names=['direct_sales_order_create', 'direct_sales_order_view', 'direct_sales_order_edit', 'direct_sales_order_delete'] ) db_util.save_objects_commit(user) fixture.login_as_admin(self.test_client) fixture.login_user(self.test_client, user.email, password) direct_po = EnumValues.get(const.DIRECT_PO_TYPE_KEY) po = of.purchase_order(number_of_line=2, type=direct_po, creator=user) po.status = EnumValues.get(const.PO_ISSUED_STATUS_KEY) fixture.login_as_admin(self.test_client) l_e, g_e, recv = PurchaseOrderService.create_expense_receiving(po) customer = of.customer(creator=user) db_util.save_objects_commit(po, l_e, g_e, recv, customer) fixture.logout_user(self.test_client) fixture.login_user(self.test_client, user.email, password) order_status = EnumValues.get(status_key) order_date = of.faker.date_time_this_year() logistic_amount = random.randint(0, 100) remark = of.faker.text(max_nb_chars=50) data = dict(customer=customer.id, status=order_status.id, order_date=order_date, logistic_amount=logistic_amount, remark=remark) total, data = self.prepare_so_lines_data_from_po(po, data) expect = [customer.name, order_status.display, order_date.strftime("%Y-%m-%d"), remark, str(total)] self.assertPageRendered(method=self.test_client.post, data=data, endpoint=self.create_endpoint(view='salesorder'), expect_contents=expect) return data, expect
def logic_for_detail_edit_page(self, user, password, po, po_url, product_url): from psi.app.service import Info from psi.app.models.role import Role from psi.app.utils import save_objects_commit fixture.login_as_admin(self.test_client) save_objects_commit(po, user) fixture.logout_user(self.test_client) fixture.login_user(self.test_client, user.email, password) rv = self.test_client.get(po_url, follow_redirects=True) self.assertEqual(rv.status_code, 200) goods_amount_label = gettext('Goods Amount') self.assertIn(goods_amount_label, rv.data) total_amount_label = gettext('Total Amount') self.assertIn(total_amount_label, rv.data) rv = self.test_client.get(product_url, follow_redirects=True) self.assertEqual(rv.status_code, 200) purchase_price_label = gettext('Purchase Price') self.assertIn(purchase_price_label, rv.data) fixture.logout_user(self.test_client) role = Info.get_db().session.query(Role).filter_by( name='purchase_price_view' ).first() user.roles.remove(role) save_objects_commit(user) fixture.login_user(self.test_client, user.email, password) rv = self.test_client.get(po_url, follow_redirects=True) self.assertEqual(rv.status_code, 200) goods_amount_label = gettext('Goods Amount') self.assertNotIn(goods_amount_label, rv.data) total_amount_label = gettext('Total Amount') self.assertNotIn(total_amount_label, rv.data) rv = self.test_client.get(product_url, follow_redirects=True) self.assertEqual(rv.status_code, 200) purchase_price_label = gettext('Purchase Price') self.assertNotIn(purchase_price_label, rv.data) fixture.logout_user(self.test_client)