Beispiel #1
0
    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)
Beispiel #2
0
    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)