def step_impl(context, user): expected = json.loads(context.text) response = context.client.get('/product/api/product_relation/') actual_response = json.loads(response.content)['data']['rows'] actual = [] for item in actual_response: weapp = [] if item['relations']: relations = json.loads(item['relations']) for relation in relations: weapp_relation = {} weapp_name = relation['self_first_name'] weapp_id = '%s'%relation['weapp_product_id'] weapp_relation[weapp_name] = weapp_id weapp.append(weapp_relation) tmp = { "name":item['product_name'], "sales":item['total_sales'], "account_name":item['customer_name'], "weapp_id": weapp } actual.append(tmp) print("expected: {}".format(expected)) print("actual_data: {}".format(actual)) bdd_util.assert_list(expected, actual)
def step_impl(context): expected = json.loads(context.text) response = context.client.get('/account/users/') users = response.context['frontend_data'].get('users') filter_username_set = set(['zhouxun', 'yangmi', 'leijun', 'yaochen']) actual = [ user for user in users if not user['name'] in filter_username_set ] for user in actual: user['real_name'] = user['realName'] bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = json.loads(context.text) response = context.client.get('/manager/api/account/') actual_response = json.loads(response.content)['data']['rows'] actual = [] for item in actual_response: tmp = {"account_name": item['name'], "login_account": item['username']} actions_array = __get_actions(item['status']) tmp["actions"] = actions_array actual.append(tmp) print("expected: {}".format(expected)) print("actual_data: {}".format(actual)) bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = json.loads(context.text) response = context.client.get('/product/api/product_list/') actual_response = json.loads(response.content)['data']['rows'] actual = [] for item in actual_response: tmp = { "name":item['product_name'], "sales":item['sales'], "price":item['product_price'], "status":item['status'] } tmp["actions"] = [u"编辑",u"彻底删除"] actual.append(tmp) print("expected: {}".format(expected)) print("actual_data: {}".format(actual)) bdd_util.assert_list(expected, actual)
def step_impl(context, user): data = {} if not (hasattr('context', 'count_per_page') and hasattr('context', 'cur_page')): data['count_per_page'] = context.count_per_page data['cur_page'] = context.cur_page del context.count_per_page del context.cur_page data['woid'] = context.woid data['access_token'] = context.openapi_access_token data['apiserver_access_token'] = context.apiserver_access_token, actual_list = [] expected_list = [] expected_orders = json.loads(context.text) for expected_order in expected_orders: order = {} order['final_price'] = float(expected_order['final_price']) order['order_status'] = ORDER_STATUS2ID[expected_order['status']] order['product_count'] = expected_order['products_count'] order['products'] = [] for supplier_group in expected_order['group']: for product in supplier_group['products']: order['products'].append({ 'price': product['price'], 'product_name': product['name'], 'product_count': product['count'] }) expected_list.append(order) resp = Resource.use('openapi').get({ 'resource': 'mall.order_list', 'data': data }) if resp: code = resp['code'] if code == 200: actual_list = resp['data']['orders'] bdd_util.assert_list(expected_list, actual_list)
def step_impl(context, user): context_json = table_to_list(context) filter_dict = {} user_id = User.objects.get(username=user).id app_status = account_models.UserProfile.objects.get( user_id=user_id).app_status actual_list = [] response = context.client.get('/application_audit/api/applications/') actual = json.loads(response.content)['data']['rows'] for data in actual: status_value = data.get('status_value', '') appid = u'审核后自动生成' appsecret = u'审核后自动生成' if status_value == 1: operation = u'确认通过/驳回修改' if status_value == 3: operation = data.get('reason', '') if status_value == 2: operation = u'暂停停用' appid = u'随机生成' appsecret = u'随机生成' if status_value == 4: operation = u'启用' appid = u'随机生成' appsecret = u'随机生成' ip_address = (',').join(data.get('serverIp', '')) actual_list.append({ "account_main": data.get('displayName', ''), "application_name": data.get('appName', ''), "appid": appid, "appsecret": appsecret, "dev_name": data.get('DeveloperName', ''), "mob_number": data.get('phone', ''), "email_address": data.get('email', ''), "ip_address": ip_address, "interface_address": data.get('interfaceUrl', ''), "status": data.get('status', ''), "operation": operation }) bdd_util.assert_list(context_json, actual_list)
def step_impl(context, user): actual = [] response = context.client.get('/config/api/users/?' + context.query_url) rows = json.loads(response.content)['data']['rows'] for row in rows: p_dict = OrderedDict() p_dict[u"account_name"] = row['username'] p_dict[u"main_name"] = row['displayName'] p_dict[u"create_time"] = bdd_util.__datetime2str(row['createdAt']) p_dict[u"status"] = row['AppStatus'] p_dict[u"operation"] = __get_actions(row['status']) actual.append((p_dict)) logging.info(actual) expected = [] if context.table: for row in context.table: cur_p = row.as_dict() expected.append(cur_p) else: expected = json.loads(context.text) print("expected: {}".format(expected)) bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = json.loads(context.text) bdd_util.assert_list(expected, context.actual_product_list)