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