def __test_manually_withdraw_success(self):
        amount = Decimal("200.25")
        channel_cost = Decimal('3.5')
        admin_user = InitData.get_admin_user()

        order = InitData.init_withdraw_order_alloc(amount)

        rsp = WithdrawTransactionCtl.manually_withdraw(admin_user,
                                                       order.merchant,
                                                       order.order_id)
        self.assertIsInstance(rsp, (ResponseSuccess, ))

        # 先成功
        rsp = WithdrawTransactionCtl.manually_withdraw_success(
            admin_user=admin_user,
            merchant=order.merchant,
            order_id=order.order_id,
            channel_cost=channel_cost,
            comment="好贵啊",
        )
        self.assertIsInstance(rsp, (ResponseSuccess, ))

        # 后失败
        rsp = WithdrawTransactionCtl.manually_withdraw_failed(
            admin_user=admin_user,
            merchant=order.merchant,
            order_id=order.order_id,
        )
        self.assertIsInstance(rsp, (ResponseSuccess, ))
    def test_withdraw_unit(self):
        InitData.init_sample_data()

        self.__test_withdraw_success()
        self.__test_withdraw_fail()
        self.__test_manually_withdraw_success()
        self.__test_manually_withdraw_fail()
示例#3
0
def init_merchant_user(merchant_id, merchant_name, password):
    from app.main import flask_app
    from app.libs.string_kit import RandomString
    if not password:
        password = RandomString.gen_random_str(10,
                                               (CharOp.N, CharOp.L, CharOp.U))

    with flask_app.app_context():
        from scripts.init_data import InitData
        InitData.merchant_name = merchant_name
        InitData.merchant_id = merchant_id
        InitData.password = RandomString.gen_md5_string(
            password.encode('utf8'))

        merchant = InitData.get_merchant_user()
        if not merchant:
            InitData.init_merchant_user()
            merchant = InitData.get_merchant_user()
            print("Merchant generated, merchant: %s, password: %s" %
                  (merchant_name, password))
        else:
            merchant.reset_password(mid=merchant_id,
                                    password=InitData.password)
            print("password changed, merchant: %s, password: %s" %
                  (merchant_name, password))

        rst = merchant.verify_login(merchant_name, InitData.password)
        if rst:
            return merchant_name, password
    return None, None
示例#4
0
def init_admin_user(account, password):
    from app.main import flask_app
    from app.libs.string_kit import RandomString
    from scripts.init_data import InitData

    if not password:
        password = RandomString.gen_random_str(10,
                                               (CharOp.N, CharOp.L, CharOp.U))

    with flask_app.app_context():
        InitData.admin_user_account = account
        InitData.password = RandomString.gen_md5_string(
            password.encode('utf8'))

        admin = InitData.get_admin_user()
        if not admin:
            InitData.init_admin_user()
            admin = InitData.get_admin_user()
            print("account generated, admin: %s, password: %s" %
                  (account, password))
        else:
            admin.reset_password(account=account, login_pwd=InitData.password)
            print("password changed, admin: %s, password: %s" %
                  (account, password))

        rst = admin.verify_login(account, InitData.password)
        print('verify login %s' % rst)

        if rst:
            return account, password

    return None, None
示例#5
0
def add_user_balance(account, balance, register=True):
    from app.main import flask_app

    with flask_app.app_context():
        print('alter balance for account: %s, balance: %s' %
              (account, balance))
        rst, msg = InitData.add_balance_to_user(account, balance, register)
        print('result:', rst, msg)
        if rst == 0:
            print('balance: ', InitData.get_balance(account))
            return InitData.get_balance(account), msg
        else:
            return 0, msg
    def __test_manually_withdraw_fail(self):
        amount = Decimal("200.25")
        admin_user = InitData.get_admin_user()

        # 先认领
        order = InitData.init_withdraw_order_alloc(amount)

        # 直接拒绝
        rsp = WithdrawTransactionCtl.manually_withdraw_failed(
            admin_user=admin_user,
            merchant=order.merchant,
            order_id=order.order_id,
        )
        self.assertIsInstance(rsp, (ResponseSuccess, ))
示例#7
0
    def test_cashier_api(self):
        with self.with_client():
            # 准备测试数据
            data = dict(
                # 正确的手机号码
                number='+639166660272',
                # 未注册的手机号码
                number_new='+639166660233',
                # 错误格式的手机号码
                number_invalid='9166660272',

                # 正确的验证码
                auth_code=SPECIAL_SMS_AUTH_CODE,
                # 错误的验证码
                auth_code_err='0000',
                # 验证码格式错误
                auth_code_invalid='s23d',

                # 正确的密码
                password=hashlib.md5('12Lk-M_6mn7'.encode('utf8')).hexdigest(),
                # 新密码
                password_new=hashlib.md5(
                    'abc12345'.encode('utf8')).hexdigest(),
                # 错误的密码
                password_err=hashlib.md5(
                    '002341ss'.encode('utf8')).hexdigest(),
            )

            # 执行用例
            InitData.init_merchant()
            # self.__merchant_config_check()
            self.__test_api_auth_mobile_check(data)
            self.__test_api_sms_get(data)
            self.__test_api_sms_verify(data)
            self.__test_api_register(data)
            self.__test_api_account_login(data)
            # self.__test_api_token_auth()
            self.__test_api_password_reset(data)
            self.__test_api_forget_password(data)
            self.__test_api_deposit()
            self.__test_get_order_list(PayTypeEnum.DEPOSIT)
            self.__test_api_withdraw()
            self.__test_get_order_list(PayTypeEnum.WITHDRAW)
            # 查询所有交易记录
            self.__test_get_order_list()
示例#8
0
    def do_ponypay_withdraw_callback(self, status):
        amount = tx_amount = Decimal("100.25")

        # 生成一个可以回调的订单
        order = InitData.init_withdraw_order_deal(amount)

        channel_config = ChannelConfig.query_by_channel_id(order.channel_id)
        controller = WithdrawCallbackPonypay(channel_config.channel_enum)
        sign = controller.generate_sign(order.sys_tx_id, tx_amount)

        self.path = "/callback/ponypay/withdraw"
        params = """merchant_id={}&corderid={}&money={}&status={}&sign={}""".format(
            controller.third_config['mch_id'],
            order.sys_tx_id,
            tx_amount,
            status,
            sign,
        )
        response = self.do_get_request(params=params)
        self.assertEqual(200, response.status_code)
        self.assertEqual("SUCCESS", response.data.decode("utf-8"))
示例#9
0
    def test_withdraw_unit():
        InitData.init_sample_data()

        __test_create_failed()
        __test_deposit_success()
        __test_deposit_fail()
 def __test_withdraw_fail(self):
     amount = Decimal("100.25")
     order = InitData.init_withdraw_order_deal(amount)
     rst = WithdrawTransactionCtl.order_fail(order)
     self.assertTrue(rst)
示例#11
0
from scripts.init_data import InitData

if __name__ == '__main__':
    from app.main import flask_app

    with flask_app.app_context():
        InitData.create_one_refund_order()
示例#12
0
def init_user(account):
    from app.main import flask_app

    with flask_app.app_context():
        InitData.user_account = account
        InitData.init_user()
 def __test_withdraw_success(self):
     amount = tx_amount = Decimal("100.25")
     order = InitData.init_withdraw_order_deal(amount)
     rst = WithdrawTransactionCtl.order_success(order, tx_amount)
     self.assertTrue(rst)
示例#14
0
from scripts.init_data import InitData

if __name__ == '__main__':
    from app.main import flask_app

    with flask_app.app_context():
        InitData.create_one_transfer_order()
示例#15
0
from scripts.init_data import InitData

if __name__ == '__main__':
    from app.main import flask_app

    with flask_app.app_context():
        for x in range(20):
            InitData.create_one_withdraw_order()
示例#16
0
    def test_unit_order_list(self):
        InitData.init_sample_data()

        InitData.create_one_refund_order()
        InitData.create_one_transfer_order()
        InitData.create_one_withdraw_order()
        InitData.create_one_deposit_order()

        page_index = 1
        begin_time, end_time = DateTimeKit.get_day_begin_end(DateTimeKit.get_cur_date())
        user = InitData.get_user()

        def get_result(pay_type):
            return TransactionListHelper.get_transaction_list(
                pay_type, user.uid, InitData.merchant, begin_time, end_time, TRANSACTION_PAGE_SIZE,
                page_index
            )

        order_entry_list, order_entry_total = get_result(None)
        self.assertEqual(6, order_entry_total)

        order_entry_list, order_entry_total = get_result(PayTypeEnum.DEPOSIT)
        self.assertEqual(1, order_entry_total)

        order_entry_list, order_entry_total = get_result(PayTypeEnum.WITHDRAW)
        self.assertEqual(2, order_entry_total)
        for item in order_entry_list:
            self.assertIsNotNone(item.get('bank_info'))
            self.assertIsNotNone(item.get('tx_id'))
            self.assertTrue(item['amount'] < 0)

        order_entry_list, order_entry_total = get_result(PayTypeEnum.REFUND)
        self.assertEqual(1, order_entry_total)

        order_entry_list, order_entry_total = get_result(PayTypeEnum.TRANSFER)
        self.assertEqual(1, order_entry_total)
        for item in order_entry_list:
            self.assertIsNotNone(item.get('out_account'))
            self.assertIsNotNone(item.get('in_account'))
            self.assertIsNotNone(item.get('comment'))

        order_entry_list, order_entry_total = get_result(PayTypeEnum.MANUALLY)
        self.assertEqual(1, order_entry_total)
示例#17
0
 def __test_deposit_success(self):
     tx_amount = Decimal('299.99')
     channel_tx_id = '29828239239238298'
     order = InitData.create_one_deposit_order()
     ret = DepositTransactionCtl.success_order_process(order, tx_amount, channel_tx_id)
     self.assertTrue(ret)
示例#18
0
 def __test_callback_ponypay_withdraw(self):
     InitData.init_sample_data()
     self.__test_withdraw_callback_success()
     self.__test_withdraw_callback_fail()
示例#19
0
 def __test_deposit_fail():
     tx_amount = Decimal('299.99')
     channel_tx_id = '29828239239238298'
     order = InitData.create_one_deposit_order()
     DepositTransactionCtl.failed_order_process(order, tx_amount, channel_tx_id)
示例#20
0
 def __test_create_failed():
     order = InitData.create_one_deposit_order()
     DepositTransactionCtl.order_create_fail(order)
示例#21
0
 def test_gateway_api(self):
     with self.with_client():
         merchant = MerchantEnum.TEST_API
         InitData.merchant = merchant
         InitData.init_sample_data()
         self.__test_get_config(merchant)
示例#22
0
 def __test_create_failed(self):
     order = InitData.create_one_deposit_order()
     rst = DepositTransactionCtl.order_create_fail(order)
     self.assertTrue(rst)