def step_impl(context, user): url = '/mall/shippers/?_method=get' expected = json.loads(context.text) response = context.client.get(url, {"corp_id": context.corp.id}) shippers = response.data['shippers'] actuals = [] for shipper in shippers: province = ID2PROVINCE[int(shipper['province'])] city = ID2CITY[int(shipper['city'])] district = ID2DISTRICT[int(shipper['district'])] actuals.append({ 'shipper': shipper['name'], 'province': province, 'city': city, 'district': district, 'particular_address': shipper['address'], 'post_code': shipper['postcode'], 'business_name': shipper['company_name'], 'mobile_num': shipper['tel_number'], 'remark': shipper['remark'], }) bdd_util.assert_list(expected, actuals)
def step_impl(context, user, classification_name): classification = mall_models.Classification.select().dj_where( name=classification_name).get() data = {'corp_id': context.corp.id, 'classification_id': classification.id} response = context.client.get('/mall/child_product_classifications/', data) table_datas = context.table if context.table: actual = [] for classification in response.data['product_classifications']: actual.append({ 'classfication_name': classification['name'], 'product_count': classification['product_count'] }) expected = [] for row in table_datas: expected.append({ 'classfication_name': row['classfication_name'], 'product_count': row['product_count'] }) bdd_util.assert_list(expected, actual) else: actual = {} for classification in response.data['product_classifications']: actual[classification['name']] = True expected = {} for item in json.loads(context.text): expected[item] = True bdd_util.assert_dict(expected, actual)
def step_impl(context, user): expected = bdd_util.table2list(context) for one in expected: if one.has_key('operation'): one['operation'] = one['operation'].split(',') actual = __view_classification_list(context, user) bdd_util.assert_list(expected, actual)
def step_webapp_user_get_product_review(context, webapp_user, product_name): """ @see 原Webapp的`webapp_product_review_steps.py` """ context.client = bdd_util.login(webapp_user) product = bdd_util.get_product_by(product_name) url = "/mall/product/" #response = context.client.get(bdd_util.nginx(url), follow=True) response = context.client.get( url, { # 'woid': context.webapp_owner_id, 'product_id': product.id }) bdd_util.assert_api_call_success(response) data = response.data logging.debug('response.data: {}'.format(data)) product_review_list = data['product_reviews'] actual = [] if product_review_list: for i in product_review_list: data = {} #data['member'] = i.member_name member = bdd_util.get_member_by_id(i['member_id']) data['member'] = member.username data['review_detail'] = i['review_detail'] actual.append(data) else: actual.append({}) expected = json.loads(context.text) if len(actual) > 2: actual = actual[:2] bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = bdd_util.table2list(context) response = context.client.get('/product/pre_products/', {'corp_id': context.corp.id}) actual = response.data['rows'] new_rows = [] for row in actual: if row['status'] == mall_models.PRODUCT_STATUS['SUBMIT'] and row[ 'is_accepted']: new_rows.append({ 'id': row['id'], 'owner_name': u'jobs', 'operation': u'商品更新 驳回修改', 'name': row['name'], 'price': __format_price_area(row['price_info']), 'stocks': __get_stocks_area(row['stocks']), 'status': __get_product_status_text(row['status'], row['is_accepted']), 'classification': row['classification_nav'] }) bdd_util.assert_list(expected, new_rows)
def step_impl(context, webapp_user, product_name): """ @see 原Webapp的`webapp_product_review_steps.py` """ product = bdd_util.get_product_by(product_name) expected = json.loads(context.text) #url = "/workbench/jqm/preview/?woid=%d&module=mall&model=product&rid=%d" % (context.webapp_owner_id, product.id) url = "/mall/product_reviews/" #response = context.client.get(bdd_util.nginx(url), follow=True) response = context.client.get(url, { 'woid': context.webapp_owner_id, 'product_id': product.id }) bdd_util.assert_api_call_success(response) data = response.data logging.debug('response.data: {}'.format(data)) product_review_list = data['reviews'] actual = [] if product_review_list: for i in product_review_list: data = {} #data['member'] = i.member_name member = bdd_util.get_member_by_id(i['member_id']) data['member'] = member.username data['review_detail'] = i['review_detail'] actual.append(data) else: actual.append({}) bdd_util.assert_list(expected, actual)
def step_impl(context, user, type_name): actual = __get_products(context, user, type_name) context.products = actual if hasattr(context, 'caller_step_text'): expected = json.loads(context.caller_step_text) delattr(context, 'caller_step_text') else: if context.table: expected = [] for product in context.table: product = product.as_dict() if 'barCode' in product: product['bar_code'] = product['barCode'] del product['barCode'] product['categories'] = product['categories'].split(',') # 处理空字符串分割问题 if product['categories'][0] == '': product['categories'] = [] # 处理table中没有验证库存的行 if 'stocks' in product and product['stocks'] == '': del product['stocks'] # 处理table中没有验证条码的行 if 'bar_code' in product and product['bar_code'] == '': del product['bar_code'] expected.append(product) else: expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_get_p_from_category(context, user, category_name): try: existed_product_category = mall_models.ProductCategory.select( ).dj_where(owner=context.corp.id, name=category_name).get() category_id = existed_product_category.id except: category_id = 0 data = { "corp_id": context.corp.id, "category_id": category_id, "filters": '{}' } response = context.client.get('/mall/category_candidate_products/', data) for product in response.data['products']: if product['status'] == 'off_shelf': product['status'] = u'待售' elif product['status'] == 'on_shelf': product['status'] = u'在售' else: pass actual = response.data['products'] expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user): url = '/mall/limit_zones/' response = context.client.get(url, {"corp_id": context.corp.id}) limit_zones = response.data['limit_zones'] expected = json.loads(context.text) actual = [] for limit_zone in limit_zones: template_data = {} template_data['name'] = limit_zone['name'] limit_area = [] for zone in limit_zone['zones']: zone_data = {} if zone['zone_name'] in [u'直辖市', u'其它']: zone_data['area'] = zone['zone_name'] province_list = [] for province in zone['provinces']: province_list.append(province['province_name']) zone_data['province'] = province_list limit_area.append(zone_data) else: for province in zone['provinces']: zone_data = {} zone_data['area'] = province['zone_name'] zone_data['province'] = province['province_name'] zone_data['city'] = [] for city in province['cities']: zone_data['city'].append(city['city_name']) limit_area.append(zone_data) template_data['limit_area'] = limit_area actual.append(template_data) bdd_util.assert_list(expected, actual)
def step_impl(context, weixin_user): expected = json.loads(context.text) webapp_owner_id = context.webapp_owner_id response = context.client.get('/member/collected_products/', {}) expected = json.loads(context.text) actual = response.body['data']['products'] logging.info("weixin_user: {}".format(weixin_user)) bdd_util.assert_list(expected, actual)
def step_impl(context, user): url = '/mall/image_groups/?corp_id=%d' % context.corp.id response = context.client.get(url) actual = response.data['image_groups'] for image_group in actual: for image in image_group['images']: image['path'] = image['url'] expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user): response = context.client.get('/mall/product_categories/', { 'at': context.client.user.token, 'woid': context.client.woid }) expected = json.loads(context.text) actual = response.body['data'] bdd_util.assert_list(expected, actual)
def step_get_property_list(context, user): response = context.client.get('/product/property_templates/?corp_id=%d' % context.corp.id) actual = response.data['templates'] for template in actual: for template_property in template['properties']: template_property['description'] = template_property['value'] expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = bdd_util.table2list(context) response = context.client.get('/mall/product_label_groups/', {'corp_id': bdd_util.get_user_id_for(user)}) actual = response.data['product_label_groups'] for data in expected: tmp_list = [] if data['labels'] == '': data['labels'] = tmp_list else: for label in data['labels'].split(','): tmp_list.append({'label_name': label}) data['labels'] = tmp_list bdd_util.assert_list(expected, actual)
def step_impl(context, webapp_user_name, webapp_owner_name): webapp_id = bdd_util.get_webapp_id_for(webapp_owner_name) member = bdd_util.get_member_for(webapp_user_name, webapp_id) integral_logs = list(member_models.MemberIntegralLog.select().dj_where( member_id=member.id).order_by(-member_models.MemberIntegralLog.id)) json_data = json.loads(context.text) actual_list = [] for data in integral_logs: actual_list.append({ "content": data.event_type, "integral": data.integral_count }) bdd_util.assert_list(actual_list, json_data)
def step_get_user_thanks_page(context, webapp_user): expected = json.loads(context.text) actual = [] if hasattr(context,'has_waiting_review'): if context.has_waiting_review: actual.append({ "title1": "继续评价", "title2": "返回首页" }) else: actual.append({ "title2": "返回首页" }) bdd_util.assert_list(expected, actual)
def step_impl(context, user): url = '/mall/shippers/?_method=get' expected = json.loads(context.text) response = context.client.get(url, {"corp_id": context.corp.id}) shippers = response.data['shippers'] actuals = [] for shipper in shippers: is_use = shipper['is_active'] actuals.append({ 'shipper': shipper['name'], 'is_use': is_use, }) bdd_util.assert_list(expected, actuals)
def step_product_review_should(context, webapp_user, text): response = context.client.get('/member/reviewed_products/', { }) expected = json.loads(context.text) #actual = response.body['data']['reviewed_products'] # 实际的输出 actual = [] product_review_list = response.body['data']['reviewed_products'] for i in product_review_list: product_review = {} product_review['review_detail'] = i['review_detail'] product_review['product_name'] = i['product']['name'] actual.append(product_review) print("-"*10, 'actual', "-"*10, actual) print("-"*10, 'expected', "-"*10, expected) bdd_util.assert_list(expected, actual)
def step_get_model_property_list(context, user): response = context.client.get('/product/model_properties/?corp_id=%d' % context.corp.id) expected = json.loads(context.text) actual = [] model_properties = response.data['product_model_properties'] for model_property in model_properties: data = { "name": model_property['name'], "type": u'图片' if model_property['type'] == 'image' else u'文字' } data['values'] = model_property['values'] for value in data['values']: value['image'] = value['pic_url'] actual.append(data) bdd_util.assert_list(expected, actual)
def step_impl(context, user): """ 只列出支付方式列表 """ expected = json.loads(context.text) response = context.client.get('/mall/pay_interfaces/?corp_id=%d' % context.corp.id) interfaces = list(response.data['pay_interfaces']) actual = [] for pay_interface in interfaces: _actual = { 'type': __type_to_name(pay_interface['type']), 'is_active': u'启用' if pay_interface['is_active'] else u'停用' } actual.append(_actual) bdd_util.assert_list(expected, actual)
def step_impl(context, user, classification_name): table = context.table response = context.client.get( '/mall/product_classifications/', { 'corp_id': bdd_util.get_user_id_for(user), 'father_id': __classification_name2father_id(classification_name) }) datas = response.data['product_classifications'] actual = [] expected = [] for data in datas: if data['name'] == classification_name: actual = data['qualification_infos'] for row in table: expected.append({'name': row['qualification_name']}) bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = bdd_util.table2list(context) response = context.client.get('/product/pre_products/', {'corp_id': context.corp.id}) actual = response.data['rows'] for row in actual: row['classification'] = row['classification_nav'] row['created_time'] = u'创建时间' row['operation'] = __get_operations(context, row['status'], row['is_accepted']) row['status'] = __get_product_status_text(row['status'], row['is_accepted']) row['stock'] = __get_stocks_area(row['stocks']) row['price'] = __format_price_area(row['price_info']) row['owner_name'] = 'jobs' #TODO bdd_util.assert_list(expected, actual)
def step_impl(context, user): url = '/mall/express_bill_accounts/?_method=get' expected = json.loads(context.text) response = context.client.get(url, {"corp_id": context.corp.id}) express_bill_accounts = response.data['express_bill_accounts'] actuals = [] for express_bill_account in express_bill_accounts: actuals.append({ "name": express_bill_account['express_name'], "Customer_name": express_bill_account['customer_name'], "Custome_password": express_bill_account['customer_pwd'], "monthcode": express_bill_account['logistics_number'], "send_site": express_bill_account['sendsite'], "remark": express_bill_account['remark'], }) bdd_util.assert_list(expected, actuals)
def step_impl(context, webapp_user_name): if context.table: expected = [] for promotion in context.table: promotion = promotion.as_dict() expected.append(promotion) else: expected = json.loads(context.text) if hasattr(context, 'searching_product_name') and context.searching_product_name: searching_product_name = context.searching_product_name url = '/mall/products/?woid=%s&category_id=%s&product_name=%s' % (context.webapp_owner_id, 0,searching_product_name) response = context.client.get(bdd_util.nginx(url), follow=True) actual = response.data['products'] context.searching_product_name = None else: actual = context.response.data['products'] for product in actual: product['price'] = float('%.2f' % float(product['display_price'])) bdd_util.assert_list(expected, actual)
def step_get_presonal_review_list(context, webapp_user): context.client = bdd_util.login(webapp_user) expected = json.loads(context.text) url = "/member/waiting_review_products" response = context.client.get(url, {}) # response = context.client.get(bdd_util.nginx(url), follow=True) orders = response.body['data']['orders'] actual = [] if orders: for order in orders: #logging.error(order['order_is_reviewed']) if not order['order_is_reviewed']: data = {} data['order_no'] = order['order_id'] data['products'] = [] for product in order['products']: # logging.error('>>>>>>>>>>>.1') # logging.error(product) # logging.error('>>>>>>>>>>>.2') if not product['has_review'] or not product['has_picture']: p_data = {} p_data['product_name'] = product['name'] if product['model']['property_values']: for mode in product['model']['property_values']: p_data['product_model_name'] = mode['name'] # p_model_name = product['product_model_name'] # if p_model_name: # the_model_name = "" # for model in p_model_name: # the_model_name += model['property_value'] # p_data['product_model_name'] = the_model_name data['products'].append(p_data) actual.append(data) else: actual.append({}) if not actual: actual.append({}) # logging.error(actual) # logging.error(expected) bdd_util.assert_list(expected, actual)
def step_get_category(context, user): response = context.client.get('/mall/suppliers/?corp_id=%d' % context.corp.id) actual = response.data['suppliers'] for supplier in actual: if supplier['type'] == 'fixed': supplier['type'] = u'固定低价' elif supplier['type'] == 'divide': supplier['type'] = u'首月55分成' supplier['divide_info'] = supplier['divide_type_info'] elif supplier['type'] == 'retail': supplier['type'] = u'零售返点' supplier['retail_info'] = supplier['retail_type_info'] else: pass expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user, classification_name): expected = json.loads(context.text) classification_id = __classification_name2id(classification_name) response = context.client.get( '/mall/product_classification_label/', { 'corp_id': bdd_util.get_user_id_for(user), 'classification_id': classification_id }) resp_datas = response.data['relations'] actual = [] for data in resp_datas: label_group_name = label_group_id2name(data['label_group_id']) data['label_ids'].sort() label_ids = map(lambda x: label_id2name(x), data['label_ids']) actual.append({ 'label_group_name': label_group_name, 'labels': label_ids }) bdd_util.assert_list(expected, actual)
def step_get_category(context, user): response = context.client.get( '/mall/categories/?corp_id=%d&category_id=0&return_product=true' % context.corp.id) for category in response.data['categories']: for product in category['products']: if product['status'] == 'off_shelf': product['status'] = u'待售' elif product['status'] == 'on_shelf': product['status'] = u'在售' else: pass if product['display_index'] == 9999999: product['display_index'] = 0 actual = response.data['categories'] expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user): client = context.client response = context.client.get('/mall/postage_configs/?corp_id=%d' % context.corp.id) actual = response.data['postage_configs'] for item in actual: item['postage_items'] = [] default_config = item['default_config'] if 'special_configs' in item: item['special_area'] = item['special_configs'] for special_config in item['special_area']: special_config['to_the'] = special_config['destinations'] item['postage_items'].append(special_config) if len(item['postage_items']) > 0: default_config['to_the'] = u'其他地区' else: default_config['to_the'] = u'全国' item['postage_items'].append(default_config) expected = json.loads(context.text) bdd_util.assert_list(expected, actual)
def step_impl(context, user): expected = bdd_util.table2list(context) response = context.client.get('/account/corps/', {}) expected_corp_names = [e['name'] for e in expected] actual = response.data['rows'] new_rows = [] for row in actual: if row['name'] not in expected_corp_names: continue row['classifications'] = __classification_ids2names(row['classification_ids']) row['axe_sales_name'] = u'渠道' row['created_time'] = u'创建时间' row['operation'] = u'编辑' row['settlement_type'] = __purchase_type_num2str(row['settlement_type']) row['clear_period'] = __clear_period_num2str(row['clear_period']) new_rows.append(row) bdd_util.assert_list(expected, new_rows)