def step_create_premium_sale(context, user): if context.table: promotions = [promotion.as_dict() for promotion in context.table] else: promotions = json.loads(context.text) if type(promotions) == dict: promotions = [promotions] for promotion in promotions: product_ids = [] db_product = ProductFactory(name=promotion['product_name']) product_ids = [{'id': db_product.id}] premium_products = [] for premium_product in promotion.get('premium_products', [{ "name": u"赠品" }]): product_name = premium_product['name'] db_product = ProductFactory(name=product_name) premium_products.append({ 'id': db_product.id, 'count': premium_product.get('count', 1), 'unit': premium_product.get('unit', '') }) data = { 'name': promotion['name'], 'promotion_title': promotion.get('promotion_title', ''), 'member_grade': __get_member_grade(promotion, context.webapp_id), 'start_date': bdd_util.get_datetime_no_second_str(promotion['start_date']), 'end_date': bdd_util.get_datetime_no_second_str(promotion['end_date']), 'products': json.dumps(product_ids), 'count': promotion.get('count', 1), 'is_enable_cycle_mode': "true" if promotion.get('is_enable_cycle_mode', False) else "false", 'premium_products': json.dumps(premium_products) } url = '/mall2/api/premium_sale/?_method=put' response = context.client.post(url, data) bdd_util.assert_api_call_success(response)
def step_impl(context, user, product_name): db_product = ProductFactory(name=product_name) ids = [] forbidden_id = __get_fobidden_id(db_product.id) if forbidden_id: ids.append(forbidden_id) __finish_fobidden_coupon_product(context, ids)
def step_impl(context, user): forbidden_coupon_products = json.loads(context.text) ids = [] for product in forbidden_coupon_products: db_product = ProductFactory(name=product['product_name']) forbidden_id = __get_fobidden_id(db_product.id) if forbidden_id: ids.append(forbidden_id) __finish_fobidden_coupon_product(context, ids)
def step_impl(context, user): datas = json.loads(context.text) product_ids = [] for data in datas: product_name = data['name'] product = ProductFactory(name=product_name) product_ids.append(str(product.id)) product_ids = ','.join(product_ids) context.product_ids = product_ids
def update_product_display_index(context, user, product_name, pos): data = { "id": ProductFactory(name=product_name).id, "update_type": "update_pos", "pos": pos } response = context.client.post('/mall2/api/product_pos/?_method=post', data) bdd_util.assert_api_call_success(response)
def step_impl(context, user): if context.table: forbidden_coupon_products = [ forbidden_coupon_product.as_dict() for forbidden_coupon_product in context.table ] else: forbidden_coupon_products = json.loads(context.text) for forbidden_coupon_product in forbidden_coupon_products: products = [] if type(forbidden_coupon_product['products']) == list: for product in forbidden_coupon_product['products']: db_product = ProductFactory(name=product['name']) products.append({'id': db_product.id}) else: db_product = ProductFactory( name=forbidden_coupon_product['products']) products.append({'id': db_product.id}) start_date = forbidden_coupon_product.get('start_date', None) end_date = forbidden_coupon_product.get('end_date', None) is_permanant_active = int( forbidden_coupon_product.get('is_permanant_active', '')) if not is_permanant_active: start_date = bdd_util.get_datetime_str(start_date) end_date = bdd_util.get_datetime_str(end_date) else: start_date = None end_date = None data = { 'products': json.dumps(products), 'is_permanant_active': is_permanant_active } if start_date and end_date: data['start_date'] = start_date data['end_date'] = end_date url = '/mall2/api/forbidden_coupon_product/?_method=put' response = context.client.post(url, data) bdd_util.assert_api_call_success(response)
def step_impl(context, user, category_name, product_name, position): product = ProductFactory(name=product_name) category = ProductCategoryFactory(name=category_name) url = '/mall2/api/category_list/' data = { "category_id": category.id, "product_id": product.id, "position": position } context.client.post(url, data)
def step_impl(context, user): if context.table: promotions = [promotion.as_dict() for promotion in context.table] else: promotions = json.loads(context.text) if type(promotions) == dict: promotions = [promotions] for promotion in promotions: product_ids = [] for product in promotion['products']: db_product = ProductFactory(name=product) product_ids.append({'id': db_product.id}) data = { 'name': promotion['name'], 'promotion_title': promotion.get('promotion_title', ''), 'member_grade': __get_member_grade(promotion, context.webapp_id), 'start_date': bdd_util.get_datetime_no_second_str(promotion['start_date']), 'end_date': bdd_util.get_datetime_no_second_str(promotion['end_date']), 'products': json.dumps(product_ids), 'price_threshold': promotion['price_threshold'], 'cut_money': promotion['cut_money'], 'is_enable_cycle_mode': "true" if promotion.get('is_enable_cycle_mode', False) else "false", } url = '/mall2/api/price_cut/?_method=put' response = context.client.post(url, data) bdd_util.assert_api_call_success(response)
def step_impl(context, user, product_name, error): detail = context.response_json['data']['detail'] context.tc.assertEquals(error, detail[0]['short_msg']) pro_id = ProductFactory(name=product_name).id context.tc.assertEquals(pro_id, detail[0]['id'])