def test_paid(self): YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token') YixinAccount.bind(self.another_local_account.id, 'p2p_account_1', 'p2p_token_1') order_a = HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('12000.0'), self.fin_order_id) order_b = HoardOrder.add(self.yixin_service.uuid.hex, self.another_local_account.id, decimal.Decimal('24000.12'), self.another_fin_order_id) assert not order_a.is_success assert not order_b.is_success order_a.mark_as_paid('102') assert order_a.is_success assert order_a.order_id == '102' assert not order_b.is_success order_a = HoardOrder.get(order_a.id_) order_b = HoardOrder.get(order_b.id_) assert order_a.is_success assert order_a.order_id == '102' assert not order_b.is_success order_b.mark_as_paid('101') assert order_b.is_success assert order_b.order_id == '101'
def test_create_with_invalid_account(self): with raises(NotFoundError) as error: HoardOrder.add(self.yixin_service.uuid.hex, -1, decimal.Decimal('10000.0'), uuid.uuid4().hex) assert error.value.args[0] == -1 assert error.value.args[1].__name__ == 'Account'
def test_create_with_invalid_service(self): fake_id = uuid.uuid4().hex with raises(NotFoundError) as error: HoardOrder.add(fake_id, self.local_account.id, decimal.Decimal('10000.0'), uuid.uuid4().hex) assert error.value.args[0] == fake_id assert error.value.args[1].__name__ == 'YixinService'
def test_create(self): YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token') order = HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('10000.12'), uuid.uuid4().hex) assert order assert not order.is_success assert order.is_owner(self.local_account) assert order.order_amount == decimal.Decimal('10000.12')
def main(): # 所有可能的封闭期月数 available_closures = {int(s.frozen_time) for s in YixinService.get_all()} # 获取所有可能在今天到期的订单 for closure in available_closures: # 对每种封闭期产品进行状态检查 end = date.today() - relativedelta(months=closure) start = end - timedelta(days=7) orders = HoardOrder.get_orders_by_period(start, end, closure) for order in orders: order.track_for_exited()
def test_get_multi_by_date(self): YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token') YixinAccount.bind(self.another_local_account.id, 'p2p_account_1', 'p2p_token_1') order_a = HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('12000.0'), uuid.uuid4().hex) order_b = HoardOrder.add(self.yixin_service.uuid.hex, self.another_local_account.id, decimal.Decimal('24000.12'), uuid.uuid4().hex) start = datetime.now().strftime('%Y-%m') os = HoardOrder.gets_by_month(start) assert len(os) == 2 assert order_a.id_ in [o.id_ for o in os] assert order_b.id_ in [o.id_ for o in os]
def test_amount_out_of_range(self): amount_range = (decimal.Decimal('5000'), decimal.Decimal('50000')) YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token') with raises(OutOfRangeError) as error: HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('-1'), uuid.uuid4().hex) assert error.value.args[0] == decimal.Decimal('-1') assert error.value.args[1] == amount_range with raises(OutOfRangeError) as error: HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('4999.99'), uuid.uuid4().hex) assert error.value.args[0] == decimal.Decimal('4999.99') assert error.value.args[1] == amount_range with raises(OutOfRangeError) as error: HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('50000.01'), uuid.uuid4().hex) assert error.value.args[0] == decimal.Decimal('50000.01') assert error.value.args[1] == amount_range
def test_confirmed(self): YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token') order = HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('12000.0'), self.fin_order_id) assert not order.is_success order.mark_as_paid('101') assert order.is_success assert order.status is not OrderStatus.confirmed order.mark_as_confirmed() assert order.is_success assert order.status is OrderStatus.confirmed
def genernate_report(filename, date): csv_file = open(filename, 'wb') writer = csv.writer(csv_file, delimiter=',') header = ['理财单号', '订单号', '宜人贷账号', '宜定盈名称', '订单状态', '订单金额', '创建时间'] writer.writerow(header) year, month = date.split('-') sql = 'select id from hoard_order where status="C" \ and year(creation_time)=%s and month(creation_time)=%s' params = (year, month) rs = db.execute(sql, params) orders = [HoardOrder.get(r[0]) for r in rs] if orders is not None: for order in orders: if order.order_id is None: continue profile = HoardProfile.get(order.user_id) yixin_account = YixinAccount.get_by_local( profile.account_id) if profile else '' p2p_account = yixin_account.p2p_account if yixin_account else '' p2p_service_name = (order.service.p2pservice_name if order.service else '') if order.status == OrderStatus.paid: order_status = '已支付' elif order.status == OrderStatus.unpaid: order_status = '未支付' elif order.status == OrderStatus.confirmed: order_status = '已确认' elif order.status == OrderStatus.failure: order_status = '失败' else: order_status = '未知' line = [ str(order.fin_order_id), str(order.order_id), str(p2p_account), str(p2p_service_name), order_status, int(order.order_amount), order.creation_time.strftime('%Y-%m-%d %H:%M') ] writer.writerow(line) csv_file.close()
def order(self): return HoardOrder.get(self.order_pk)
def test_create_with_unbound_account(self): with raises(UnboundAccountError) as error: HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id, decimal.Decimal('10000.0'), uuid.uuid4().hex) assert error.value.args[0] == self.local_account.id