def get_withdraw_channel2(cls): return ProxyChannelConfig.query_latest_one(query_fields=dict( channel_enum=cls.channel_enum2))
def __test_api_channel(self): # 充值通道管理 新增通道 channel_enum = ChannelConfigEnum.CHANNEL_1001 post_data = dict(channel_id=channel_enum.value, fee="2.3", fee_type="1", limit_per_min="2000", limit_per_max="50000", limit_day_max="50000", start_time="09:00", end_time="23:59", state="10", settlement_type="1", priority="1") post_data["state"] = 10 # 数值型参数类型错误 self.path = '/channel/deposit/add' response = self.do_request(post_data) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # print(response.json['message'], "this field must be String type") post_data["state"] = "10" # 测试交易日期为空的情况 response = self.do_request(post_data) print(response.json) self.assertEqual(ResponseSuccess.code, response.status_code, response.json['message']) self.assertEqual(ResponseSuccess.error_code, response.json['error_code'], response.json['message']) # print(response.json['message'], "this field must be String type") post_data['maintain_begin'] = "2019-09-27 09:10:00" post_data['maintain_end'] = "2019-10-20 23:09:00" # 测试每笔交易上限大于日交易上限 post_data['limit_day_max'] = "40000" response = self.do_request(post_data) print(response.json) self.assertEqual(PerLimitMustLittleDayLimitError.code, response.status_code) self.assertEqual(PerLimitMustLittleDayLimitError.error_code, response.json['error_code']) # print(response.json['message'], "this field must be String type") # self.assertEqual(response.json['message'], "单笔交易最大值必须小于当日交易限额") post_data['limit_day_max'] = "60000" # 时间类型参数业务数据不对 post_data["maintain_begin"] = "2020-08-23 09:30:00" response = self.do_request(post_data) self.assertEqual(response.status_code, DateStartMoreThanError.code) self.assertEqual(response.json['error_code'], DateStartMoreThanError.error_code) self.assertEqual(response.json['message'], DateStartMoreThanError.message) post_data["maintain_begin"] = "2019-09-27 09:00:00" # 业务类型数据不对 post_data["limit_per_min"] = "100000" response = self.do_request(post_data) self.assertEqual(response.status_code, DataStartMoreThanError.code) self.assertEqual(response.json['error_code'], DataStartMoreThanError.error_code) self.assertEqual(response.json['message'], DataStartMoreThanError.message) post_data["limit_per_min"] = "2000" # 时间类型数据格式错误 post_data["maintain_begin"] = "2019/09/27 09:00:00" response = self.do_request(post_data) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], "无效的时间格式") post_data["maintain_begin"] = "2019-09-27 09:00:00" # 测试成功添加数据 response = self.do_request(post_data) self.assertEqual(response.status_code, ResponseSuccess.code) channel = ChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(channel.channel_enum.value, post_data['channel_id']) self.assertEqual(channel.settlement_type.value, int(post_data['settlement_type'])) # 渠道管理:编辑通道 self.path = '/channel/deposit/edit' post_data['settlement_type'] = '3' response = self.do_request(post_data) self.assertEqual(response.status_code, ResponseSuccess.code) channel = ChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(channel.channel_enum.value, post_data['channel_id']) self.assertEqual(channel.settlement_type.value, 3) # 测试 不支持的 枚举类型数据 self.path = '/channel/deposit/edit' post_data['state'] = '110' response = self.do_request(post_data) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], "无效的通道状态") post_data['state'] = "10" # 代付通道管理: 新增代付通道 self.path = "/channel/withdraw/add" withdraw_postdata = dict(channel_id=channel_enum.value, fee="2.3", fee_type="1", limit_per_min="2000", limit_per_max="50000", limit_day_max="50000", start_time="09:00", end_time="23:59", maintain_begin="2019-09-27 09:00:00", maintain_end="2019-10-20 23:00:00", state="10", banks=["1", "2", "4", "6", "3", "5", "15"]) # 测试参数类型错误 withdraw_postdata['channel_id'] = '123' response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], str({'channel_id': 'this field must be Integer type'})) # 测试时间格式错误 withdraw_postdata['channel_id'] = channel_enum.value withdraw_postdata["maintain_begin"] = "2019/09/27 09:00:00" response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], "无效的时间格式") withdraw_postdata["maintain_begin"] = "2019-09-27 09:00:00" # 测试成功添加代付通道 ProxyChannelConfig.delete_all() response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ResponseSuccess.code) self.assertEqual(response.json['error_code'], ResponseSuccess.error_code) channel = ProxyChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(withdraw_postdata['maintain_begin'], DateTimeKit.datetime_to_str(channel.maintain_begin)) self.assertEqual(withdraw_postdata['channel_id'], channel.channel_enum.value) # 测试编辑 代付通道 self.path = "/channel/withdraw/edit" withdraw_postdata['banks'] = ["4", "6", "3"] withdraw_postdata['limit_day_max'] = '180000' withdraw_postdata['maintain_begin'] = "2019-10-30 09:30:01" withdraw_postdata['maintain_end'] = "2019-12-30 09:30:01" response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ResponseSuccess.code) self.assertEqual(response.json['error_code'], ResponseSuccess.error_code) channel = ProxyChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(channel_enum.value, channel.channel_enum.value) self.assertEqual(withdraw_postdata['maintain_begin'], DateTimeKit.datetime_to_str(channel.maintain_begin)) self.assertEqual(withdraw_postdata['maintain_end'], DateTimeKit.datetime_to_str(channel.maintain_end)) self.assertEqual( [PaymentBankEnum(4), PaymentBankEnum(6), PaymentBankEnum(3)], channel.banks) self.assertEqual(180000, channel.limit_day_max) # 测试代付列表 self.path = "/channel/withdraw/list" response = self.do_request() self.assertEqual(response.status_code, ResponseSuccess.code) self.assertEqual(response.json['error_code'], ResponseSuccess.error_code) self.assertEqual('1', response.json['data']['counts']) self.assertEqual(channel_enum.value, response.json['data']['withdraws'][0]['channel_id']) ProxyChannelConfig.delete_all()
def init_channel2(cls): if not cls.get_deposit_channel2(): # 充值通道配置 kwargs = dict(fee="2.5", fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER, limit_per_min="500", limit_per_max="20000", trade_begin_hour="0", trade_begin_minute="0", trade_end_hour="0", trade_end_minute="0", maintain_begin=DateTimeKit.str_to_datetime( "2019-09-07 09:00:00"), maintain_end=DateTimeKit.str_to_datetime( "2019-09-07 09:00:00"), settlement_type=SettleTypeEnum.D0, state=ChannelStateEnum.TESTING if cls.merchant.is_test else ChannelStateEnum.ONLINE, priority="101") ChannelConfig.update_channel(cls.channel_enum2, **kwargs) channel_config = ChannelConfig.query_latest_one(query_fields=dict( channel_enum=cls.channel_enum2)) # print(channel_config) # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.DEPOSIT).get_channel_limit() limit_min, limit_max = ChannelListHelper.get_channel_limit_range( merchant=cls.merchant, payment_way=PayTypeEnum.DEPOSIT, ) # print('limit_min: %s, limit_max: %s' % (limit_min, limit_max)) assert 0 != limit_min assert 0 != limit_max if not cls.get_withdraw_channel2(): # 提款代付通道配置 withdraw_item = dict( fee="1.3", fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER, limit_per_min="300", limit_per_max="10000", limit_day_max="500000", trade_begin_hour="0", trade_begin_minute="0", trade_end_hour="0", trade_end_minute="0", maintain_begin=DateTimeKit.str_to_datetime( "2019-09-07 09:00:00"), maintain_end=DateTimeKit.str_to_datetime( "2019-09-07 09:00:00"), state=ChannelStateEnum.TESTING if cls.merchant.is_test else ChannelStateEnum.ONLINE, banks=[ PaymentBankEnum.ZHONGGUO, PaymentBankEnum.GONGSHANG, PaymentBankEnum.JIANSHE, ]) ProxyChannelConfig.update_channel(cls.channel_enum2, **withdraw_item) channel_config = ProxyChannelConfig.query_latest_one( query_fields=dict(channel_enum=cls.channel_enum2)) # print(channel_config) # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.WITHDRAW).get_channel_limit() limit_min, limit_max = ChannelListHelper.get_channel_limit_range( merchant=cls.merchant, payment_way=PayTypeEnum.WITHDRAW, ) # print('limit_min: %s, limit_max: %s' % (limit_min, limit_max)) assert 0 != limit_min assert 0 != limit_max