def test_online_pay_activity(self): url = self.JOIN_ACTIVITY.format(activity_id=self.activity.id) body = {"payment": "wxpay", "nickname": "Nick name"} self.auth_user = User.create(name='join activity') response = self.fetch(url, method='POST', body=json.dumps(body), params={'team_id': self.team.id}) self.assertEqual(200, response.code, response.body) order = TeamOrder.get_or_none(user=self.auth_user, activity_id=self.activity.id) self.assertIsNotNone(order, "加入活动时订单 `TeamOrder` 未创建") result = json.loads(response.body.decode()) expect = { "status": "ok", "state": ActivityMember.ActivityMemberState.wait_confirm.value, "payment_state": TeamOrder.OrderState.WAIT_BUYER_PAY.value, "order_no": order.order_no } self.assertDictEqual(expect, result, result) member = ActivityMember.get_or_none(activity=self.activity, user=self.auth_user) self.assertIsNotNone(member, "加入活动后 `ActivityMember` 未添加记录")
def refund(self, reason=""): """ 退款 """ # 未支付或已退款,无需退款 if TeamOrder.OrderState( self.payment_state) != TeamOrder.OrderState.TRADE_BUYER_PAID: return True order = TeamOrder.get_or_none(id=self.order_id) if order is None: return True # 退款 order.refund(reason=reason, free_times=self.free_times) return True