def test_01(self): """ 正常下限价买单,验证返回接口状态、MSG、STATUS """ logger.info("用例编号:2-1-----正常下限价买单,验证返回接口状态、MSG、STATUS") ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id=transtion_id)) resp = self.session.post(url=base + order_reservations_url, data=get_order_reservations_param( transtion_id=transtion_id, order_type=限价, price=price, num=num)) status = JMESPathExtractor().extract(query="MSG", body=resp.text) buy_num = JMESPathExtractor().extract(query="STATUS", body=resp.text) buy_order_id = JMESPathExtractor().extract(query="OBJECT.buyerOrderId", body=resp.text) logger.info("用户:{0}----url:{1}-----接口状态:{2}-----下单状态:{3}".format( BUYER, order_reservations_url, resp.status_code, status)) logger.info("下限价买单返回信息:{}".format(resp.json())) self.assertEqual([200, "SUCCESS", "0"], [resp.status_code, status, buy_num]) time.sleep(6) self.session.post(url=base + update_revocation_status_url, data=get_update_revocation_status_param( _type=买单, order_id=buy_order_id))
def test_03(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): logger.info("<<==========================================================================================================================>") logger.info("用例说明: 编号:90-3-%s, 余额不足限价卖单" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis(get_redis_name(transtion_id)) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=target_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=target_currency_id, balance_value=990000000000000) num_min, price_min = ConnectMysql(_type=mysql_type).query_currency_min(transtion_id=transtion_id) buy_price, sell_price, buy_num, sell_num = int(buy_price), int(sell_price), int(buy_num), int(sell_num) sell_num_list = [int(num_min) - 1, 0] for i in sell_num_list: with self.subTest(): ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=main_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=target_currency_id, balance_value=i) login_url = base_url + test_data.get("login_url") sell_url = base_url + test_data.get("sell_order_url") session = requests.session() session.post(url=login_url, headers=login_header, data=get_login_param(user=SELLER, user_password=user_password)) resp = session.post(url=sell_url, data=get_sell_order_param(transtion_id, 0, sell_price, num_min)) session.close() logger.info("下卖单返回信息:{}".format(resp.json())) assert_word = JMESPathExtractor().extract(query="MSG", body=resp.text) assert_status = JMESPathExtractor().extract(query="STATUS", body=resp.text) assert_list = [assert_word, assert_status] self.assertListEqual(assert_list, ["最小交易单位不正确", "1"])
def test_02(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 余额刚好,下单成功 """ logger.info("<<==========================================================================================================================>") logger.info("用例说明: 编号:90-2-%s, 余额刚好下限价买单" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis(get_redis_name(transtion_id)) """ ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=target_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=target_currency_id, balance_value=990000000000000) """ num_min, price_min = ConnectMysql(_type=mysql_type).query_currency_min(transtion_id=transtion_id) value = int(num_min) * int(price_min) buy_price, sell_price, buy_num, sell_num = int(buy_price), int(sell_price), int(buy_num), int(sell_num) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=main_currency_id, balance_value=value) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=target_currency_id, balance_value=9900000000000000) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id ) login_url = base_url + test_data.get("login_url") buy_url = base_url + test_data.get("order_reservations_url") session = requests.session() session.post(url=login_url, headers=login_header, data=get_login_param(user=BUYER, user_password=user_password)) resp = session.post(url=buy_url, data=get_order_reservations_param(transtion_id, 0, price=price_min, num=num_min)) logger.info("下单前买家主币余额:{0}-----下买单价格:{1}-----------下买单数量:{2}".format(before_buy_main, price_min, num_min)) session.close() logger.info("下买单返回信息:{}".format(resp.json())) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, ) assert_word = JMESPathExtractor().extract(query="MSG", body=resp.text) assert_status = JMESPathExtractor().extract(query="STATUS", body=resp.text) assert_list = [assert_word, assert_status] logger.info(" 下单前买家主币余额:{0}--------- 下单后买家主币余额:{1}-------成交金额{2}".format(before_buy_main, after_buy_main, math.ceil(value/100000000))) logger.info("下单前买家目标币余额:{0}---------下单后买家目标币余额:{1}".format(before_buy_target, after_buy_target)) self.assertIn(int(before_buy_main) - int(after_buy_main) - math.ceil(value/100000000), [0, 1]) self.assertIn(int(before_buy_target) - int(after_buy_target), [0, 1]) self.assertListEqual(assert_list, ["SUCCESS", "0"])
def tet_04(self): """ 撤单接口,下卖单正常撤单,验证接口返回状态、MSG、STATUS、OBJECT """ logger.info("用例编号:4-4---撤单接口,下卖单正常撤单,验证接口返回状态、MSG、STATUS、OBJECT") ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=1, order_status=1) ConnectRedis(_type=redis_type).clear_redis(get_redis_name(transtion_id=transtion_id)) sell_resp = self.session.post(url=base+sell_order_url, data=get_sell_order_param(transtion_id=transtion_id,order_type=限价,price=price,num=num)) sell_order_id = JMESPathExtractor().extract(query="OBJECT.sellerOrderId", body=sell_resp.text) logger.info("URL:{0}-----卖单接口返回状态:{1}-------卖单返回信息:{2}".format(sell_order_url,sell_resp.status_code, sell_resp.json())) time.sleep(5) update_resp = self.session.post(url=base+update_revocation_status_url, data=get_update_revocation_status_param(_type=卖单,order_id=sell_order_id)) status = JMESPathExtractor().extract(query="STATUS", body=update_resp.text) msg = JMESPathExtractor().extract(query="MSG", body=update_resp.text) OBJECT = JMESPathExtractor().extract(query="OBJECT", body=update_resp.text) logger.info("用户:{0}----url:{1}------接口状态:{2}".format(BUYER, update_revocation_status_url, update_resp.status_code)) logger.info("撤单返回信息:{}".format(update_resp.json())) self.assertListEqual([200, "SUCCESS", "0"], [update_resp.status_code, msg, status])
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 编号:58-1 限价买单,不收手续费,限价卖单,收取手续费,部分成交 """ logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明:编号:58-1-%s 限价买单,不收手续费,限价卖单,收取手续费,部分成交" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, transtion_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=target_currency_id, balance_value=990000000000000) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) logger.info("买入价格:{0}----买入数量:{1}-----卖出价格:{2}-----卖出数量{3}".format( buy_price, buy_num, sell_price, sell_num)) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=0) time.sleep(1) test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=sell_price, num=sell_num, order_type=0) test_buyer = Base(user=BUYER) buy_update_resp = test_buyer.updateRevocationStatus( type=1, orderId=buy_order_id) buy_assert_list = [ JMESPathExtractor().extract(query="MSG", body=buy_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=buy_update_resp.text) ] test_seller = Base(user=SELLER) sell_update_resp = test_seller.updateRevocationStatus( type=2, orderId=sell_order_id) sell_assert_list = [ JMESPathExtractor().extract(query="MSG", body=sell_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=sell_update_resp.text) ] time.sleep(3) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=buy_order_id) buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=buy_order_id, order_type=1) sell_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=sell_order_id, order_type=2) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format( buy_order_status, sell_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format( before_buy_main, after_buy_main)) logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format( before_buy_target, after_buy_target)) logger.info("交易前卖家主币余额:{0}--------交易后卖家主币余额:{1}".format( before_sell_main, after_sell_main)) logger.info("交易前卖家目标币余额:{0}--------交易后卖家目标币余额:{1}".format( before_sell_target, after_sell_target)) self.assertListEqual(buy_assert_list, ["SUCCESS", "0"]) self.assertListEqual(sell_assert_list, ["订单已被成交", "1"]) self.assertIn( int(before_buy_main) - int(after_buy_main) - int(buy_price * sell_num / 100000000), [0, 1]) self.assertIn( int(after_buy_target) - int(before_buy_target) - int(sell_num), [0, 1]) self.assertIn( int(after_sell_main) - int(before_sell_main) - int(buy_price * sell_num / 100000000 * (1 - 2 / 1000)), [0, 1]) self.assertIn( int(before_sell_target) - int(after_sell_target) - int(sell_num), [0, 1])
def tet_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 编号:52-1 市商市价买单,,市商市价卖单,不成交 做市商不支持市价单,此用例跳过 """ logger.info( "<<==========================================================================================================================>" ) logger.info("用户说明:编号:52-1-%s 市商市价买单,,市商市价卖单,不成交 " % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=target_currency_id, balance_value=990000000000000) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=1) time.sleep(1) test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=sell_price, num=sell_num, order_type=1) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=sell_order_id) buy_order_status = ConnectMysql(_type=2).get_Order_Status( order_id=buy_order_id, order_type=1) sell_order_status = ConnectMysql(_type=2).get_Order_Status( order_id=sell_order_id, order_type=2) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format( buy_order_status, sell_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format( before_buy_main, after_buy_main)) logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format( before_buy_target, after_buy_target)) logger.info("交易前卖家主币余额:{0}--------交易后卖家主币余额:{1}".format( before_sell_main, after_sell_main)) logger.info("交易前卖家目标币余额:{0}--------交易后卖家目标币余额:{1}".format( before_sell_target, after_sell_target)) self.assertEqual(int(before_buy_main), int(after_buy_main)) self.assertEqual(int(before_buy_target), int(after_buy_target)) self.assertEqual(int(before_sell_main), int(after_sell_main)) self.assertEqual(int(before_sell_target), int(after_sell_target))
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 编号:53-1 市商限价买单,不收手续费,撤单 """ logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明:编号:53-1-%s 市商限价买单,不收手续费,撤单" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=main_currency_id, balance_value=990000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=target_currency_id, balance_value=990000000000000) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=0) test_buyer = Base(user=BUYER) buy_update_resp = test_buyer.updateRevocationStatus( type=1, orderId=buy_order_id) buy_assert_list = [ JMESPathExtractor().extract(query="MSG", body=buy_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=buy_update_resp.text) ] after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=buy_order_id) buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=buy_order_id, order_type=1) logger.info("撤单后买单状态:{0}".format(buy_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format( before_buy_main, after_buy_main)) logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format( before_buy_target, after_buy_target)) self.assertListEqual(buy_assert_list, ["SUCCESS", "0"]) self.assertEqual(int(before_buy_main), int(after_buy_main)) self.assertEqual(int(before_buy_target), int(after_buy_target))
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): logger.info("<<==========================================================================================================================>") logger.info("用例说明: 编号:81-1-%s, 随机测试限价买单、限价卖单、成交、撤单,验证订单状态,冻结金额余额" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis(get_redis_name(transtion_id)) buy_price, sell_price, buy_num, sell_num = int(buy_price), int(sell_price), int(buy_num), int(sell_num) for i in range(2): with self.subTest(): ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=main_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=target_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=main_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=target_currency_id, balance_value=9900000000000000) random_price = random.randint(10, 999) * 100000000 random_num = random.randint(10, 99) * 100000000 before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id ) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=random_price, num=random_num, order_type=0) time.sleep(1) test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=random_price, num=random_num, order_type=0) time.sleep(3) test_buyer = Base(user=BUYER) buy_update_resp = test_buyer.updateRevocationStatus(type=1, orderId=buy_order_id) buy_assert_list = [JMESPathExtractor().extract(query="MSG", body=buy_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=buy_update_resp.text)] test_seller = Base(user=SELLER) sell_update_resp = test_seller.updateRevocationStatus(type=2, orderId=sell_order_id) sell_assert_list = [JMESPathExtractor().extract(query="MSG", body=sell_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=sell_update_resp.text)] after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=buy_order_id ) buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(order_id=buy_order_id, order_type=1) sell_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(order_id=sell_order_id, order_type=2) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(buy_order_status, sell_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } self.assertListEqual(buy_assert_list, ["订单已被成交", "1"]) self.assertListEqual(sell_assert_list, ["订单已被成交", "1"]) flag_list = count_value_single(buy_price=random_price, buy_num=random_num, sell_price=random_price, sell_num=random_num, **balance_dict) logger.info("<<==========================================================================================================================>") self.assertNotIn(False, flag_list)
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明: 编号:10-1-%s, 随机测试限价买单、限价卖单、成交、撤单" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) for i in range(3): with self.subTest(): ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=main_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=target_currency_id, balance_value=9900000000000000) num_min, price_min = ConnectMysql( _type=mysql_type).query_currency_min( transtion_id=transtion_id) random_price = random.randrange(int(price_min), int(price_min) * 999999, int(price_min)) random_num = random.randrange(int(num_min), int(num_min) * 999999, int(num_min)) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations( transtion_id=transtion_id, price=random_price, num=random_num, order_type=0) test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder( transtion_id=transtion_id, price=random_price, num=random_num, order_type=0) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=buy_order_id) buy_order_status = ConnectMysql( _type=mysql_type).get_Order_Status(order_id=buy_order_id, order_type=1) sell_order_status = ConnectMysql( _type=mysql_type).get_Order_Status(order_id=sell_order_id, order_type=2) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format( buy_order_status, sell_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } flag_list = count_value_single(buy_price=random_price, buy_num=random_num, sell_price=random_price, sell_num=random_num, **balance_dict) logger.info( "<<==========================================================================================================================>" ) self.assertNotIn(False, flag_list)
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 编号:45-1 限价买单,不收手续费,限价卖单,收取手续费 """ logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明: 编号:45-1-%s, 限价买单,不收手续费,限价卖单,收取手续费" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=0) time.sleep(1) test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=sell_price, num=sell_num, order_type=0) test_buyer = Base(user=BUYER) buy_update_resp = test_buyer.updateRevocationStatus( type=1, orderId=buy_order_id) buy_assert_list = [ JMESPathExtractor().extract(query="MSG", body=buy_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=buy_update_resp.text) ] test_seller = Base(user=SELLER) sell_update_resp = test_seller.updateRevocationStatus( type=2, orderId=sell_order_id) sell_assert_list = [ JMESPathExtractor().extract(query="MSG", body=sell_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=sell_update_resp.text) ] after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=sell_order_id) buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=buy_order_id, order_type=1) sell_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=sell_order_id, order_type=2) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format( buy_order_status, sell_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } self.assertListEqual(buy_assert_list, ["订单已被成交", "1"]) self.assertListEqual(sell_assert_list, ["订单已被成交", "1"]) flag_list = count_balance(free_type="buy_free", deal_price=buy_price, deal_num=buy_num, **balance_dict) self.assertNotIn(False, flag_list)
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明: 编号:91-1-%s, 小于限价买单价格下单" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) num_min, price_min = ConnectMysql(_type=mysql_type).query_currency_min( transtion_id=transtion_id) logger.info( "transtion_id : {0}-----price_min : {1}------num_min : {2}----buy_price : {3}" .format(transtion_id, price_min, num_min, int(price_min) - 1)) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=9900000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=9900000000000000) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) login_url = base_url + test_data.get("login_url") buy_url = base_url + test_data.get("order_reservations_url") session = requests.session() session.post(url=login_url, headers=login_header, data=get_login_param(user=BUYER, user_password=user_password)) resp = session.post(url=buy_url, data=get_order_reservations_param( transtion_id, 0, int(price_min) - 1, buy_num)) session.close() logger.info("下买单信息:{}".format(resp.json())) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, ) assert_word = JMESPathExtractor().extract(query="MSG", body=resp.text) assert_status = JMESPathExtractor().extract(query="STATUS", body=resp.text) assert_list = [assert_word, assert_status] self.assertIn(int(before_buy_main) - int(after_buy_main), [0, 1]) self.assertIn(int(before_buy_target) - int(after_buy_target), [0, 1]) self.assertListEqual(assert_list, ["最小交易单位不对", "1"])
def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 编号:41-1 限价买单,收手续费,限价卖单不收取手续费 """ logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明: 编号:41-1-%s, 限价买单,收手续费,限价卖单收取手续费" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=99000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=99000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=main_currency_id, balance_value=99000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=target_currency_id, balance_value=99000000000000) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) for i in range(10): test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations( transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=0) test_seller = Base(user=SELLER) time.sleep(1) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=sell_price, num=sell_num, order_type=0) test_buyer = Base(user=BUYER) buy_update_resp = test_buyer.updateRevocationStatus( type=1, orderId=buy_order_id) buy_assert_list = [ JMESPathExtractor().extract(query="MSG", body=buy_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=buy_update_resp.text) ] test_seller = Base(user=SELLER) sell_update_resp = test_seller.updateRevocationStatus( type=2, orderId=sell_order_id) sell_assert_list = [ JMESPathExtractor().extract(query="MSG", body=sell_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=sell_update_resp.text) ] after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=sell_order_id) buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=buy_order_id, order_type=1) sell_order_status = ConnectMysql( _type=mysql_type).get_Order_Status(order_id=sell_order_id, order_type=2) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format( buy_order_status, sell_order_status))
def test_01(self): """ 限价卖\限价买:while(余额足够){A创建卖单,B买入}, 部分成交 手续费 == 2/1000 B限价买单 UserB_BuyOrderPrice = 200,250,300,350,400 , UserB_BuyOrderNum = 1, 2, 3, 4, 5 A限价卖单等差递增 UserA_SellOrderPrice = 200,250,300,350,400 , UserA_SellOrderNum = 1, 2, 3, 4, 6 """ ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=main_currency_id, balance_value=99000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=BUYER, currency_id=target_currency_id, balance_value=99000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=main_currency_id, balance_value=99000000000000) ConnectMysql(_type=mysql_type).update_balance_value( user_mail=SELLER, currency_id=target_currency_id, balance_value=99000000000000) logger.info( "<<==========================================================================================================================>" ) logger.info("测试用例说明:{}".format(TestCase.test_01.__doc__)) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) buy_order_id_list = [] sell_order_id_list = [] for i in range(len(buy_price)): # 下买单 test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations( transtion_id=transtion_id, price=buy_price[i], num=buy_num[i], order_type=0) buy_order_id_list.append(buy_order_id) for v in range(len(sell_price)): # 下卖单 test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=sell_price[v], num=sell_num[v], order_type=0) sell_order_id_list.append(sell_order_id) time.sleep(6) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) time.sleep(3) for t in buy_order_id_list: test_buyer = Base(user=BUYER) test_buyer.updateRevocationStatus(type=1, orderId=t) for k in sell_order_id_list: test_seller = Base(user=SELLER) test_seller.updateRevocationStatus(type=2, orderId=k) buy_order_status_list = [] sell_order_status_list = [] for _id in buy_order_id_list: buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=_id, order_type=1) buy_order_status_list.append(buy_order_status) for sell_id in sell_order_id_list: sell_order_status = ConnectMysql( _type=mysql_type).get_Order_Status(order_id=sell_id, order_type=2) sell_order_status_list.append(sell_order_status) logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format( buy_order_status_list, sell_order_status_list)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format( before_buy_main, after_buy_main)) logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format( before_buy_target, after_buy_target)) logger.info("交易前卖家主币余额:{0}--------交易后卖家主币余额:{1}".format( before_sell_main, after_sell_main)) logger.info("交易前卖家目标币余额:{0}--------交易后卖家目标币余额:{1}".format( before_sell_target, after_sell_target)) buy_value, deal_num, sell_value, sell_num_value = count_value_buy_first( buy_price, buy_num, sell_price, sell_num) self.assertEqual( int(after_buy_main), int(int(before_buy_main) - int(buy_value / 100000000))) self.assertEqual( int(after_buy_target), int(before_buy_target) + int(deal_num * (1 - 2 / 1000))) self.assertEqual( int(after_sell_main), int(before_sell_main) + int(sell_value / 100000000 * (1 - 2 / 1000))) self.assertEqual(int(after_sell_target), int(before_sell_target) - int(sell_num_value))
def test_02(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num): """ 编号:56-2 市价买单,普通用户,撤单 """ logger.info( "<<==========================================================================================================================>" ) logger.info("用例说明:编号:56-2-%s, 市价买单,普通用户,撤单" % number) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=1) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=1) ConnectRedis(_type=redis_type).clear_redis( get_redis_name(transtion_id)) buy_price, sell_price, buy_num, sell_num = int(buy_price), int( sell_price), int(buy_num), int(sell_num) before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=1) test_buyer.updateRevocationStatus(orderId=buy_order_id, type=1) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id, order_id=buy_order_id) buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status( order_id=buy_order_id, order_type=1) logger.info("撤单后买单状态:{0}-----".format(buy_order_status)) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format( before_buy_main, after_buy_main)) logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format( before_buy_target, after_buy_target)) self.assertEqual(int(before_buy_main), int(after_buy_main)) self.assertEqual(int(before_buy_target), int(after_buy_target))
def test_01(self): """ 下买卖单,达不到成交价格,循环撤单,验证余额 """ ConnectRedis(_type=redis_type).clear_redis(name=get_redis_name( transtion_id=transtion_id)) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=1, order_status=2) ConnectMysql(_type=mysql_type).update_order_status( transtion_id=transtion_id, order_type=2, order_status=2) logger.info( "<<==========================================================================================================================>" ) logger.info("测试用例说明:".format(TestCase.test_01.__doc__)) logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER)) logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format( transtion_id, main_currency_id, target_currency_id)) # 下单前查询买卖双发的主币和目标币余额 before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) logger.info("成交之前买家主币余额:{0}-----成交之前买家目标币余额:{1}".format( before_buy_main, before_buy_target)) logger.info("成交之前卖家的主币余额:{0}------成交之前卖家的目标币余额{1}".format( before_sell_main, before_sell_target)) logger.info("买入价格:{0}-----买入数量{1}".format(buy_price, buy_num)) logger.info("卖出价格:{0}-----卖出数量{1}".format(sell_price, sell_num)) self.buy_id_list = [] # 下一个买单 test_buyer = Base(user=BUYER) buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=buy_price, num=buy_num, order_type=0) # 下一个卖单 test_seller = Base(user=SELLER) sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=sell_price, num=sell_num, order_type=0) time.sleep(5) for i in range(10): test_buyer.updateRevocationStatus(type=1, orderId=buy_order_id) time.sleep(5) test_seller.updateRevocationStatus(type=2, orderId=sell_order_id) after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value( buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id) balance_dict = { "before_buy_main_balance": before_buy_main, "before_buy_target_balance": before_buy_target, "before_sell_main_balance": before_sell_main, "before_sell_target_balance": before_sell_target, "after_buy_main_balance": after_buy_main, "after_buy_target_balance": after_buy_target, "after_sell_main_balance": after_sell_main, "after_sell_target_balance": after_sell_target, } self.assertEqual(int(before_buy_main), int(after_buy_main)) self.assertEqual(int(before_buy_target), int(after_buy_target)) self.assertEqual(int(before_sell_main), int(after_sell_main)) self.assertEqual(int(before_sell_target), int(after_sell_target))