def test_add_market(self, with_login): user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() e_api = ExchangeManagementApi() s_api = SponsorApi() venture_api = VentureApi() va_api = VentureAccountApi() project_api = ProjectApi() contacts_api = ContactsApi() tam_api = TenantAssetManagementApi() v_api = VerificationApi() ma_api = MainExchangeApi() vc = VentureContactsApi() pm = ProjectManagementApi() token = with_login('tenant', [ pm, vc, ma_api, v_api, contacts_api, project_api, m_api, e_api, va_api, s_api, venture_api, tam_api ], email, password) # 授权 res = PostPlatFormRegisterRequest() va_api.create_platform(body=res) # 交易币种 rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_api = SponsorApi() sponsor_token = get_sponsor_token(account, password, email='test') set_login_status(sponsor_api, sponsor_token) project = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project) application_id = rv.id # 查看申请详情 rv = venture_api.applications_id_get(application_id) assert rv.status == 'undone' # 查看申请裂表 rv = venture_api.applications_get(page=1) assert len(rv.items) == 1 item = rv.items[0] assert item.project_name == project['projectName'] assert item.fullname == project['fullName'] assert item.short_name == project['shortName'] rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 1 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id, {'sponsorId': sponsor['id']}) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_id_get(application_id) assert rv.status == 'under_review' project_name = project['projectName'] sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) rv = sponsor_project_api.projects_get(page=1, project_name=project_name) assert len(rv.items) >= 1 rv = sponsor_project_api.projects_id_get(id=application_id) assert rv # 保健通过 sponsor_project_api.projects_sponsor_put({ 'id': application_id, 'status': 1, 'remark': 'test' }) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 1 rv = venture_api.applications_id_get(application_id) assert rv.status == 'passed' # 保鉴成功列表 rv = sponsor_project_api.sponsor_record_success_get( page=1, coin_name=project['shortName']) assert len(rv.items) == 1 assert rv.items[0].full_name == project['fullName'] # 项目列表 rv = venture_api.projects_get(page=1) project_id = rv.items[0].project_id self.data['project_id'] = project_id # 设置接入方式 setting = PutProjectRequestSetting(access_method='verification', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) # 获取项目详情 rv = venture_api.projects_id_get(project_id) exchange_id = TestMarket1.data['exchange_id'] # 初始化项目 s_api = SystemManagementApi() staff_project_api = StaffProjectApi() asset_management_api = AssetManagementApi() admin_token = get_admin_token() set_login_status(staff_project_api, admin_token) set_login_status(asset_management_api, admin_token) set_login_status(s_api, admin_token) coin_name = project['shortName'] rv = asset_management_api.asset_mgmt_coins_get(coin_name=coin_name) coin_id = rv.items[0].coin_id coin_config_id = rv.items[0].id # 修改币种配置 res = PutSystemCoinsInitRequest() res.usdt_price = '1251' res.rc_times = 8 res.wc_times = 8 res.withdraw_rate = 0.1 res.min_withdraw = 100 res.min_withdraw_fee = 0.1 res.max_withdraw = 1000 res.min_recharge = 10 res.address_tag_switch = True res.day_withdraw_total = 125564 res.address_type = 'OX' res.address_url = 'http://unknown.com' res.txid_url = 'http://unknown.com' # asset_management_api.asset_mgmt_coins_id_put(coin_id, res) asset_management_api.asset_mgmt_coins_id_init_put( coin_config_id, res) rv = s_api.system_trading_pair_get(name=project['shortName'], partition_id=b_coin.id) # 对接币种 req = { 'exchangeId': exchange_id, 'projectId': project_id, 'sponsor': 'tenant' } contacts_api.contacts_post(req) rv = contacts_api.contacts_check_get(project_id, exchange_id) rv = pm.projects_id_contacts_get(project_id, 'tenant') # 处理对接邀请 contact_id = rv.items[0].contact_id vc.contacts_put({'contactId': contact_id, 'status': 'accepted'}) rv = contacts_api.contacts_check_get(project_id=project_id, exchange_id=exchange_id) assert rv.result rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin s_coin = seller_coin[0] # 主平台获取买卖方币种列表 rv = ma_api.exchanges_exchange_coin_exchange_id_get(exchange_id) assert rv.seller_coin[0].name == project['shortName'] self.data['s_coin'] = s_coin self.data['b_coin'] = b_coin res = PostOrderMarketRequest() res.seller_coin_id = s_coin.id res.buyer_coin_id = b_coin.id res.allotted_time = AllottedTime._6month res.fee_rate = TestMarket1.fee_rate now = datetime.now() create_at = now.strftime("%Y-%m") disabled_at = now + relativedelta(months=AllottedTime._6month) disabled_at = disabled_at.strftime("%Y-%m") rv = e_api.exchange_exchange_coin_get() # 配置交易对市场 rv = e_api.exchange_order_market_post(res) order_id = rv.order_id usdt_id = b_coin.id # 充钱 free_charge(token, usdt_id, self.data['account_id']) rv = tam_api.asset_mgmt_assets_get() # 临时接口充币 rv = tam_api.asset_mgmt_balance_coin_id_get(usdt_id) data = { "challenge": "048ebbe51f829995db76ac4b81546403", "seccode": "048ebbe51f829995db76ac4b81546403", "validate": "true", "account": "mailto:[email protected]", "code": "666666", "secondCode": "Ls1w1w", "type": "pay" } rv = v_api.accounts_verify_post(data) p = PutOrderMarketRequest(order_id=order_id, token=rv.token) e_api.exchange_order_market_put(p) # 获取交易对市场 rv = m_api.markets_get() items = rv.items assert len(items) == 1 item = items[0] sell_coin_name = s_coin.name buy_coin_name = b_coin.name # total_rate = TestMarket1.fee_rate + float(TestMarket1.service_rate) # assert item.total_rate == 0.00011 # todo暂时不测这个 # assert item.fee_rate == TestMarket1.fee_rate # todo暂时不测这个 assert item.status == 'running' assert item.trading_pair == f'{sell_coin_name}/{buy_coin_name}' assert item.created_at.strftime('%Y-%m') == create_at assert item.disabled_at.strftime('%Y-%m') == disabled_at # 获取交易所总数据 rv = ma_api.exchanges_total_data_get() assert float(rv.exchange_amount) >= 1 # 批量修改交易币对单价 s_api.system_trading_pair_update_list_put(1111, True, True) rv = s_api.system_trading_pair_get(partition_id=b_coin.id) for each in rv.items: assert float(each.price) == 1111
def test_applications(self): faker = Faker() manager = PlatformManager("venture") email = random_email() password = faker.password() country = random_get_country_ob() manager.register(email=email, password=password, promotion_code=None, verification_code="666666", nationality_code=country.get("k")) token = manager.login(account=email, password=password) # 创建保荐方账号 staff_api = SponsorsManagermentApi() staff_token = get_admin_token() set_login_status(staff_api, staff_token) sponsor = { "account": get_random_name(6, 25), "password": faker.password(), "name": faker.user_name(), "email": email, "phone": faker.phone_number() } staff_api.staff_sponsors_post(post_sponsor=sponsor) # 保荐方登 sponsor_api = SponsorsProjectApi() get_sponsor_token(account=sponsor.get("account"), password=sponsor.get("password"), email=sponsor.get("email"), api_list=[sponsor_api]) # 获取项目申请列表 res = sponsor_api.projects_get(page=1) assert not res.meta # 个人实名认证 individual_verify(platform="venture", id_number=get_random_id_number(), token=token) # 申请项目 project_name = get_random_name(2, 16) short_name = "P" + str(random.randint(10000, 99999)) full_name = get_random_name(2, 16) project_api = ProjectApi() set_login_status(project_api, token) pay = copy.deepcopy(dict(payload)) pay.update({ 'project_name': project_name, 'short_name': short_name, 'full_name': full_name }) req = ApplicationRequest(**pay) res = project_api.applications_post(body=req) project_apply_id = res.id # 项目方获取保健列表 venture_api = SMApi() set_login_status(venture_api, token) res = venture_api.sponsors_get(page=1, name=sponsor.get("name")) item = res.items.pop() sponsor_id = item.id # 项目方设置保健方 project_api.applications_id_set_sponsor_put( id=project_apply_id, sponsor_request={"sponsorId": sponsor_id}) # 获取项目申请列表 res = sponsor_api.projects_get(page=1) assert res.meta.total_count == 1
def test_add_market2(self, with_login): user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() e_api = ExchangeManagementApi() s_api = SponsorApi() venture_api = VentureApi() va_api = VentureAccountApi() project_api = ProjectApi() contacts_api = ContactsApi() tam_api = TenantAssetManagementApi() v_api = VerificationApi() ma_api = MainExchangeApi() vc = VentureContactsApi() pm = ProjectManagementApi() tenant_ca = TenantContactsApi() token = with_login('tenant', [ pm, vc, ma_api, v_api, contacts_api, project_api, m_api, e_api, va_api, s_api, venture_api, tam_api, tenant_ca ], email, password) # 交易币种 rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_api = SponsorApi() sponsor_token = get_sponsor_token(account, password, email='test') set_login_status(sponsor_api, sponsor_token) project = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project) application_id = rv.id # 查看申请列表 rv = venture_api.applications_get(page=1, order='desc') assert len(rv.items) == 2 item = rv.items[0] assert item.project_name == project['projectName'] assert item.fullname == project['fullName'] assert item.short_name == project['shortName'] rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 1 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id, {'sponsorId': sponsor['id']}) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 project_name = project['projectName'] sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) rv = sponsor_project_api.projects_get(page=1, project_name=project_name) assert len(rv.items) >= 1 rv = sponsor_project_api.projects_id_get(id=application_id) assert rv sponsor_project_api.projects_sponsor_put({ 'id': application_id, 'status': 1, 'remark': 'test' }) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='turn_down') assert int(rv.result) == 1 # 保鉴成功列表 rv = sponsor_project_api.sponsor_record_success_get( page=1, coin_name=project['shortName']) # 项目列表 rv = venture_api.projects_get(page=1) project_id = rv.items[0].project_id self.data['project_id'] = project_id # 设置接入方式 setting = PutProjectRequestSetting(access_method='accept', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) # 获取项目详情 rv = venture_api.projects_id_get(project_id) exchange_id = TestMarket1.data['exchange_id'] rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 0 # 初始化项目 s_api = SystemManagementApi() staff_project_api = StaffProjectApi() asset_management_api = AssetManagementApi() admin_token = get_admin_token() set_login_status(staff_project_api, admin_token) set_login_status(asset_management_api, admin_token) set_login_status(s_api, admin_token) coin_name = project['shortName'] rv = asset_management_api.asset_mgmt_coins_get(coin_name=coin_name) coin_id = rv.items[0].coin_id coin_config_id = rv.items[0].id # 修改币种配置 res = PutSystemCoinsInitRequest() res.usdt_price = '1251' res.rc_times = 8 res.wc_times = 8 res.withdraw_rate = 0.1 res.min_withdraw = 100 res.min_withdraw_fee = 0.1 res.max_withdraw = 1000 res.min_recharge = 10 res.address_tag_switch = True res.day_withdraw_total = 125564 res.address_type = 'OX' res.address_url = 'http://unknown.com' res.txid_url = 'http://unknown.com' # asset_management_api.asset_mgmt_coins_id_put(coin_id, res) asset_management_api.asset_mgmt_coins_id_init_put( coin_config_id, res) rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 1 setting = PutProjectRequestSetting(access_method='refuse', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) # refuse rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 0 setting = PutProjectRequestSetting(access_method='verification', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 1 rv = s_api.system_trading_pair_get(name=project['shortName'], partition_id=b_coin.id) # 对接币种 req = { 'exchangeId': exchange_id, 'projectId': project_id, 'sponsor': 'tenant' } contacts_api.contacts_post(req) rv = pm.projects_id_exchanges_get(project_id) rv = pm.projects_id_contacts_get(project_id, 'tenant') assert rv.items[0].exchange_id == exchange_id rv1 = contacts_api.contacts_check_get(project_id=project_id, exchange_id=exchange_id) assert rv1.result r1 = contacts_api.contacts_project_id_status_get(project_id) assert r1.status == 'pending' # 处理对接邀请 contact_id = rv.items[0].contact_id r = tenant_ca.contacts_projects_exchange_id_get( exchange_id, 'pending') assert not r.items vc.contacts_put({'contactId': contact_id, 'status': 'accepted'}) rv = contacts_api.contacts_check_get(project_id=project_id, exchange_id=exchange_id) assert rv.result rv = contacts_api.contacts_project_id_status_get(project_id) assert rv.status == 'accepted' rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin s_coin = seller_coin[0] # 主平台获取买卖方币种列表 rv = ma_api.exchanges_exchange_coin_exchange_id_get(exchange_id) assert rv.seller_coin[0].name == project['shortName'] self.data['s_coin'] = s_coin self.data['b_coin'] = b_coin res = PostOrderMarketRequest() res.seller_coin_id = s_coin.id res.buyer_coin_id = b_coin.id res.allotted_time = AllottedTime._6month res.fee_rate = TestMarket1.fee_rate now = datetime.now() disabled_at = now + relativedelta(months=AllottedTime._6month) rv = e_api.exchange_exchange_coin_get() # 配置交易对市场 rv = e_api.exchange_order_market_post(res) order_id = rv.order_id usdt_id = b_coin.id data = { "challenge": "048ebbe51f829995db76ac4b81546403", "seccode": "048ebbe51f829995db76ac4b81546403", "validate": "true", "account": "mailto:[email protected]", "code": "666666", "secondCode": "Ls1w1w", "type": "pay" } rv = v_api.accounts_verify_post(data) p = PutOrderMarketRequest(order_id=order_id, token=rv.token)
def test_get_project(self, with_login): """1.新增项目——获取所有项目——获取项目详情""" sponsor = get_sponsors() venture_api = VentureApi() user_data = register_with_login('venture', with_login, [venture_api]) TestProject.data['user'] = user_data project = get_project() TestProject.data['project'] = project req = ApplicationRequest(**project) rv = venture_api.applications_post(req) project_id = rv.id TestProject.data['project_id'] = project_id # 设置接入方式 setting = PutProjectRequestSetting(access_method='accept') project_info = PutProjectRequestProjectInfo(access_method='accept') req = PutProjectRequest(project_info=project_info, setting=setting) venture_api.projects_id_put(req) # 设置保健机构 venture_api.applications_id_set_sponsor_put(project_id, {'sponsorId': sponsor.id}) project_name = project['project_name'] sponsor_api = SponsorsProjectApi() manager = PlatformManager('sponsor') token = manager.login(sponsor_account, sponsor_pwd) sponsor_api.api_client.set_default_header("Authentication-Token", token) rv = sponsor_api.projects_get(page=1, project_name=project_name) assert len(rv.items) == 1 assert rv.items[0].id == project_id rv = sponsor_api.projects_id_get(id=project_id) assert rv.project_info.project_name == project['project_name'] assert rv.coin_info.short_name == project['short_name'] # 保健通过 sponsor_api.projects_sponsor_put({ 'id': project_id, 'status': 1, 'remark': 'test' }) project_api = ProjectApi() project_api.api_client.set_default_header("Authentication-Token", user_data['token']) rv = project_api.projects_get() assert len(rv.items) == 1 p = rv.items[0] assert p.project_id == project_id # 获取项目详情 rv = project_api.projects_id_get(id=project_id) assert rv.sponsor_info.sponsor_id == sponsor.id assert rv.project_info.id == project_id assert rv.coin_info.short_name == project['short_name'] # 合并测试用例 """1.新增项目——获取项目列表——收藏——收藏列表(项目)""" token = user_data['token'] account_api = AccountApi() account_api.api_client.set_default_header("Authentication-Token", token) account_info = account_api.accounts_account_info_get() account_id = account_info.accountInfo.accountId f_api = FavoriteManagementApi() f_api.api_client.set_default_header("Authentication-Token", token) req = PostFavoriterRequest() req.favorite_id = project_id req.type = 'project' f_api.favorites_post(req) # 收藏列表 flag = False pages = Pager(f_api.favorites_get) favorite_record_id = None for page in pages: for record in page.items: if record.favorite_id == project_id: if record.type == 'project': flag = True favorite_record_id = record.id break if flag: break assert flag # 合并测试用例 """5.收藏项目成功——收藏列表(项目)——取消收藏""" # 取消收藏 req = DeleteFavoriterRequest() req.id_items = [favorite_record_id] f_api.favorites_ids_delete(req) rv = f_api.favorites_is_favorite_get(favorite_id=project_id, type='project') assert not rv.status
def test_add_market1(self, with_login): user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() e_api = ExchangeManagementApi() s_api = SponsorApi() venture_api = VentureApi() va_api = VentureAccountApi() project_api = ProjectApi() contacts_api = ContactsApi() tam_api = TenantAssetManagementApi() v_api = VerificationApi() ma_api = MainExchangeApi() vc = VentureContactsApi() pm = ProjectManagementApi() token = with_login('tenant', [ pm, vc, ma_api, v_api, contacts_api, project_api, m_api, e_api, va_api, s_api, venture_api, tam_api ], email, password) # 授权 res = PostPlatFormRegisterRequest() va_api.create_platform(body=res) # 交易币种 rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_api = SponsorApi() sponsor_token = get_sponsor_token(account, password, email='test') set_login_status(sponsor_api, sponsor_token) project = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project) application_id = rv.id # 查看申请列表 rv = venture_api.applications_get(page=1) assert len(rv.items) == 1 item = rv.items[0] assert item.project_name == project['projectName'] assert item.fullname == project['fullName'] assert item.short_name == project['shortName'] rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 1 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id, {'sponsorId': sponsor['id']}) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 project_name = project['projectName'] sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) rv = sponsor_project_api.projects_get(page=1, project_name=project_name) assert len(rv.items) >= 1 rv = sponsor_project_api.projects_id_get(id=application_id) assert rv # 保健不通过 sponsor_project_api.projects_sponsor_put({ 'id': application_id, 'status': 0, 'remark': 'test' }) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='turn_down') assert int(rv.result) == 1 # 保鉴成功列表 rv = sponsor_project_api.sponsor_record_success_get( page=1, coin_name=project['shortName']) assert not rv.items # 项目列表 rv = venture_api.projects_get(page=1) assert len(rv.items) == 0