def test_historyOrder_page(self): with self.app.app_context(): testuser1 = User('historyOrder_testuser_1', 'testpassword', id=66) testuser2 = User('historyOrder_testuser_2', 'testpassword', id=666) instrument1 = Instrument(self.generate_random_instrument_id(), '测试乐器1', 100, 200, '测试描述1', 300, 'imagepath') instrument1.saveToDb() instrument2 = Instrument(self.generate_random_instrument_id(), '测试乐器2', 200, 200, '测试描述2', 300, 'imagepath') instrument2.saveToDb() instrument3 = Instrument(self.generate_random_instrument_id(), '测试乐器3', 300, 200, '测试描述3', 300, 'imagepath') instrument3.saveToDb() instruments = [instrument1, instrument2] testuser1.addInstrumentToShoppingCraft(instruments) order1_id = testuser1.payAllShoppingCraft() instruments = [instrument1, instrument3] testuser2.addInstrumentToShoppingCraft(instruments) order2_id = testuser2.payAllShoppingCraft() self.curr.execute("select totalprice from `order` where id=%s", order1_id) order1_totalprice = self.curr.fetchone()[0] self.curr.execute("select totalprice from `order` where id=%s", order2_id) order2_totalprice = self.curr.fetchone()[0] # 测试历史订单能否正确显示 c = self.app.test_client() with self.app.app_context(): c.post('/adminLogin', data=dict(username=environ.get('weborder_admin_username'), password=environ.get('weborder_admin_password'))) response = c.get('/historyOrder/66') assert 'historyOrder_testuser_1'.encode( 'utf-8') in response.data and str(order1_id).encode( 'utf-8') in response.data and '300'.encode( 'utf-8') in response.data response = c.get('/historyOrder/666') assert 'historyOrder_testuser_2'.encode( 'utf-8') in response.data and str(order2_id).encode( 'utf-8') in response.data and '400'.encode( 'utf-8') in response.data self.curr.execute('SET FOREIGN_KEY_CHECKS = 0;') self.curr.execute('truncate table user;') self.curr.execute('truncate table instrument;') self.curr.execute('truncate table `order`;') self.curr.execute('truncate table shopping_craft;') self.curr.execute('truncate table shoppingcraft_instrument;') self.curr.execute('SET FOREIGN_KEY_CHECKS = 1;')
def test_orderDetail_page(self): with self.app.app_context(): testuser1 = User('orderDetail_testuser_1', 'testpassword', id=66) instrument1 = Instrument(self.generate_random_instrument_id(), '测试乐器1', 100, 200, '测试描述1', 300, 'imagepath') instrument1.saveToDb() instrument2 = Instrument(self.generate_random_instrument_id(), '测试乐器2', 200, 200, '测试描述2', 300, 'imagepath') instrument2.saveToDb() instrument3_id = self.generate_random_instrument_id() instrument3 = Instrument(instrument3_id, '测试乐器3', 300, 200, '测试描述3', 300, 'imagepath') instrument3.saveToDb() instruments = [instrument1, instrument3] testuser1.addInstrumentToShoppingCraft(instruments) orderId = testuser1.payAllShoppingCraft() Instrument.removeFromDb(instrument3_id) now = datetime.now() c = self.app.test_client() with self.app.app_context(): c.post('/adminLogin', data=dict(username=environ.get('weborder_admin_username'), password=environ.get('weborder_admin_password'))) orderDetail_url = '/orderDetail/' + str(orderId) response = c.get(orderDetail_url) assert str(orderId).encode('utf-8') in response.data assert str(now.year).encode('utf-8') in response.data assert str(now.day).encode('utf-8') in response.data assert 'orderDetail_testuser_1'.encode('utf-8') in response.data assert '400'.encode('utf-8') in response.data assert '测试乐器1'.encode('utf-8') in response.data assert (str(instrument3_id) + '(此商品已下架)').encode('utf-8') in response.data assert '测试乐器2'.encode('utf-8') not in response.data self.curr.execute('SET FOREIGN_KEY_CHECKS = 0;') self.curr.execute('truncate table user;') self.curr.execute('truncate table instrument;') self.curr.execute('truncate table `order`;') self.curr.execute('truncate table shopping_craft;') self.curr.execute('truncate table shoppingcraft_instrument;') self.curr.execute('SET FOREIGN_KEY_CHECKS = 1;')