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 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)