Esempio n. 1
0
def step_impl(context):
    """
	"""
    # 获取页面上返回的数据
    client = context.client
    context.response = client.get(
        '/stats/api/activity_analysis/?type=qrcode&sort_attr=name&count_per_page=%d&page=1&enable_paginate=1'
        % (100))
    bdd_util.assert_api_call_success(context.response)
    #print("content: {}".format(context.response.content))
    results = json.loads(context.response.content)
    assert results.has_key('data')
    items = results['data']['items']  # 结果列表
    #print("items: {}".format(items))

    index = 0
    for row in context.table:
        real = items[index]
        index += 1

        # 按照row.headings()构造2个dict
        #print("row: {}".format(row))
        #print("headings: {}".format(row.headings))
        expected_dict = {key: row[key] for key in row.headings}
        real_dict = {key: real[key] for key in row.headings}
        # 特殊字段特殊处理
        #expected_dict['start_at'] = dateutil.get_date_string(expected_dict['start_at'])
        #expected_dict['end_at'] = dateutil.get_date_string(expected_dict['end_at'])
        #real_dict['start_at'] = dateutil.get_date_string(real_dict['start_at'])

        print("real_dict: {}".format(real_dict))
        print("expected_dict: {}".format(expected_dict))
        bdd_util.assert_dict(expected_dict, real_dict)
Esempio n. 2
0
def step_impl(context):
    """
	"""
    items = context.data['items']  # 结果列表
    print("items: {}".format(items))

    index = 0
    for row in context.table:
        real = items[index]
        index += 1

        # 按照row.headings()构造2个dict
        #print("row: {}".format(row))
        #print("headings: {}".format(row.headings))
        expected_dict = {key: row[key] for key in row.headings}
        #real_dict = {key: real[key] for key in row.headings}
        real_dict = real
        # 特殊字段特殊处理
        expected_dict['start_at'] = dateutil.get_date_string(
            expected_dict['start_at'])
        expected_dict['end_at'] = dateutil.get_date_string(
            expected_dict['end_at'])

        print("real_dict: {}".format(real_dict))
        print("expected_dict: {}".format(expected_dict))
        bdd_util.assert_dict(expected_dict, real_dict)
Esempio n. 3
0
def step_impl(context, user, record_name):
    expected_data = json.loads(context.text)
    app = get_app_by_name(rebate_models.Rebate, record_name)
    #首先进入活动列表页面
    url = "/apps/rebate/rebates/"
    get_response(context, url)
    #获取列表
    response = get_response(
        context, {
            "app": "apps/rebate",
            "resource": "rebates",
            "method": "get",
            "type": "api",
            "args": {
                "count_per_page": 10,
                "page": 1,
                "enable_paginate": 1
            }
        })
    items = json.loads(response.content)['data']['items']
    actual_data = {}
    for item in items:
        if item['name'] == expected_data['code_name']:
            item['code_name'] = item['name']
            actual_data = item
            break
    bdd_util.assert_dict(expected_data, actual_data)
Esempio n. 4
0
def step_impl(context, user, days):
    if u'天' in days:
        days = days[:-1]

    url = '/mall2/api/outline/?type=purchase_trend&days=%s' % days
    response = context.client.get(url)
    data = json.loads(response.content)['data']
    dates = data['xAxis']['data']
    product_counts = data['series'][1]['data']
    money_list = data['series'][0]['data']
    date2info = {}
    for i, date in enumerate(dates):
        date2info[date] = {
            "product_count": product_counts[i],
            "money": money_list[i]
        }
    actual = date2info

    date2info = {}
    for row in context.table:
        date = bdd_util.get_date(row['date']).strftime('%Y-%m-%d')
        date2info[date] = {
            "product_count": int(row['product_count']),
            "money": float(row['money'])
        }
    expected = date2info

    bdd_util.assert_dict(expected, actual)
def step_impl(context, user, test_delivery_plan):
	existed_delivery_plans = DeliveryPlan.objects.get(name=test_delivery_plan)

	expected = json.loads(context.text)
	response = context.client.get('/market_tools/delivery_plan/delivery_plan/update/%d/' % existed_delivery_plans.id)
	delivery_plan = response.context['delivery_plan']

	product_name = Product.objects.get(id=existed_delivery_plans.product_id).name
	if(delivery_plan.type==2):
		delivery_plan.type = u'月'
	elif(delivery_plan.type==1):
		delivery_plan.type = u'周'
	else:
		delivery_plan.type = u'天'

	actual = {
		"name": delivery_plan.name,
		"product": product_name,
		"type": delivery_plan.type,
		"frequency": str(delivery_plan.frequency),
		"times": str(delivery_plan.times),
		"price": str(int(delivery_plan.price))
	}
	expected['product'] = expected['name']
	bdd_util.assert_dict(expected, actual)
Esempio n. 6
0
def step_impl(context, user):
	expected_data = json.loads(context.text)
	url = '/member/member_qrcode/'
	
	client = context.client
	response = client.get(url)
	member_qrcode_settings = response.context['member_qrcode_settings']

	award_content = response.context['award_content']

	current_data = {}
	if award_content.award_type == 0:
		current_data['prize_type'] = u'无'
		current_data['page_description'] = member_qrcode_settings.detail
	elif award_content.award_type == 1:
		current_data['prize_type'] = u'优惠券'
		current_data['page_description'] = member_qrcode_settings.detail
		coupon_rule = CouponRule.objects.get(id=award_content.award_content)
		current_data['coupon'] = coupon_rule.name
	elif award_content.award_type == 3:
		current_data['prize_type'] = u'积分'
		current_data['page_description'] = member_qrcode_settings.detail
		current_data['integral'] = int(award_content.award_content)

	bdd_util.assert_dict(expected_data, current_data)
	context.member_qrcode_settings = member_qrcode_settings
Esempio n. 7
0
def step_impl(context, webapp_user_name):
    order, order_has_products = steps_db_util.get_order_has_products(context)
    actual_order = order
    actual_order.ship_area = actual_order.area
    actual_order.status = ORDERSTATUS2TEXT[actual_order.status]
    actual_order.methods_of_payment = PAYTYPE2NAME[
        actual_order.pay_interface_type]  #兼容feature
    actual_order.pay_interface_type = PAYTYPE2NAME[
        actual_order.pay_interface_type]

    actual_order.order_no = order.order_id
    actual_order.order_time = str(order.created_at)

    # 获取order的products
    actual_order.products = []
    for relation in order_has_products:
        product = relation.product
        product.price = relation.price
        product.count = relation.number
        product.model = relation.product_model_name
        # product.fill_specific_model('standard')
        actual_order.products.append(product)

    expected = json.loads(context.text)
    if 'products' in expected:
        for product in expected['products']:
            if 'model' in product:
                product['model'] = steps_db_util.get_product_model_keys(
                    product['model'])
    bdd_util.assert_dict(expected, actual_order)
Esempio n. 8
0
def step_impl(context, user, vote_name):
    existed_vote = Vote.objects.get(name=vote_name)

    expected = json.loads(context.text)
    response = context.client.get('/market_tools/vote/update/%d/' %
                                  existed_vote.id)
    vote = response.context['vote']

    actual = {
        "name": vote.name,
        "detail": vote.detail,
        "is_non_member": u"可参与" if vote.is_non_member else u"不可参与",
        "show_style": u"不带图片" if vote.show_style else u"带图片",
        "prize_info": __translate_data_prize_info(vote.award_prize_info),
        "vote_options": []
    }
    existed_vote_options = VoteOption.objects.filter(
        vote=existed_vote).order_by('id')
    for option in existed_vote_options:
        one_option = {"name": option.name}
        if not vote.show_style:
            one_option['pic_url'] = option.pic_url
        actual["vote_options"].append(one_option)

    bdd_util.assert_dict(expected, actual)
Esempio n. 9
0
def step_impl(context, user):
    order = steps_db_util.get_latest_order()
    context.latest_order_id = order.id
    # client = context.client
    response = context.client.get('/mall2/order/?order_id=%d' %
                                  context.latest_order_id)

    order = response.context['order']
    order.order_no = order.order_id
    # order.order_type = ORDER_TYPE2TEXT[order.type]
    order.order_type = ''
    order.total_price = float(order.final_price)
    order.ship_area = order.area  # + ' ' + order.ship_address

    order.actions = get_order_action_set(order.actions)
    for product in order.products:
        product['price'] = float(product['price'])
    order.status = STATUS2TEXT[order.status]
    for product in order.products:
        if 'custom_model_properties' in product and product[
                'custom_model_properties']:
            product['model'] = ' '.join([
                property['property_value']
                for property in product['custom_model_properties']
            ])
        product['supplier'] = product.get('supplier_name', '')
        product['status'] = product.get('order_status', '')
    actual = order
    actual.reason = order.reason

    expected = json.loads(context.text)
    expected['order_type'] = ''
    if 'actions' in expected:
        expected['actions'] = set(expected['actions'])
    bdd_util.assert_dict(expected, actual)
Esempio n. 10
0
def step_impl(context, user, weizoom_card_id):
    context.client = bdd_util.login(user)
    client = context.client
    card = WeizoomCard.objects.get(weizoom_card_id=weizoom_card_id)
    response = client.get(
        '/market_tools/weizoom_card/weizoom_card/%s/expense_record/' % card.id)
    card = response.context['card']
    expense_records = response.context['expense_records']

    expected_json = json.loads(context.text)
    status, _ = _get_status(expected_json['status'])
    actual_data = {
        "status": int(status),
        "price": float(expected_json['price'])
    }
    expected = {"status": int(card.status), "price": float(card.money)}
    # 是否需要验证日志
    if expected_json.get('log'):
        actual_data['log'] = expected_json.get('log')
        expected['log'] = _get_weizoom_card_log(expense_records)

    # print("*"*80, "能获取微众卡")
    # from pprint(import pprint)
    # pprint(expected)
    # pprint(actual_data)
    # print("*"*120)

    bdd_util.assert_dict(expected, actual_data)
Esempio n. 11
0
def step_impl(context, user, promotion_name):
    promotion = Promotion.objects.get(name=promotion_name)
    response = context.client.get('/mall2/premium_sale/?id=%d' % promotion.id)
    promotion = response.context['promotion']

    if promotion.member_grade_id == 0:
        member_grade = u'全部会员'
    else:
        member_grade = promotion.member_grade_name

    actual = {
        "main_product": [],
        "premium_products": [],
        "name": promotion.name,
        "promotion_title": promotion.promotion_title,
        "start_date": promotion.start_date,
        "end_date": promotion.end_date,
        "member_grade": member_grade,
        "count": promotion.detail['count'],
        "is_enable_cycle_mode": promotion.detail['is_enable_cycle_mode']
    }
    main_product = {}
    premium_products = {}
    for product in promotion.products:
        actual["main_product"].append(product)

    for premium_product in promotion.detail["premium_products"]:
        actual["premium_products"].append(premium_product)

    expected = json.loads(context.text)
    expected['start_date'] = bdd_util.get_datetime_str(expected['start_date'])
    expected['end_date'] = bdd_util.get_datetime_str(expected['end_date'])

    bdd_util.assert_dict(expected, actual)
Esempio n. 12
0
def step_impl(context, user):
    expected = json.loads(context.text)
    # if not expected.get(u'客单价', None):
    #	expected[u'客单价'] = str(expected[u'客单价'])
    actual = {}
    data = context.stats_data
    order_num = data['order_num']
    paid_amount = data['paid_amount']
    if order_num > 0:
        unit_price = '%.2f' % float(float(paid_amount) / float(order_num))
    else:
        unit_price = '0.00'

    actual[u'成交订单'] = order_num
    actual[u'成交金额'] = paid_amount
    actual[u'客单价'] = unit_price
    actual[u'成交商品'] = data['product_num']
    actual[u'优惠抵扣'] = '%.2f' % float(data['discount_amount'])
    actual[u'总运费'] = '%.2f' % float(data['postage_amount'])
    actual[u'在线支付订单'] = data['online_order_num']
    actual[u'在线支付金额'] = '%.2f' % float(data['online_paid_amount'])
    actual[u'货到付款订单'] = data['cod_order_num']
    actual[u'货到付款金额'] = '%.2f' % float(data['cod_amount'])

    bdd_util.assert_dict(expected, actual)
Esempio n. 13
0
def step_impl(context, webapp_usr_name, order_id):
    # 为获取完可顺利支付
    context.created_order_id = order_id

    url = '/workbench/jqm/preview/?woid=%s&module=mall&model=order&action=pay&order_id=%s' % (
        context.webapp_owner_id, order_id)
    response = context.client.get(bdd_util.nginx(url), follow=True)
    has_sub_order = response.context['has_sub_order']
    actual = response.context['order']
    actual.order_no = actual.order_id
    actual.order_time = (str(actual.created_at))
    actual.methods_of_payment = response.context['pay_interface']
    actual.member = actual.buyer_name
    actual.status = ORDERSTATUS2MOBILETEXT[actual.status]
    actual.ship_area = actual.area

    if has_sub_order:
        products = []
        orders = response.context['orders']
        for i, order in enumerate(orders):
            product_dict = {
                u"包裹" + str(i + 1): order.products,
                'status': ORDERSTATUS2MOBILETEXT[order.status]
            }
            products.append(product_dict)

        actual.products = products

    expected = json.loads(context.text)
    bdd_util.assert_dict(expected, actual)
Esempio n. 14
0
def step_impl(context, webapp_user_name):
	expected = json.loads(context.text)

	actual = context.product
	actual.stock_type = u'无限' if actual.stock_type == PRODUCT_STOCK_TYPE_UNLIMIT else u'有限'
	actual.shelve_type = u'上架' if actual.shelve_type == PRODUCT_SHELVE_TYPE_ON else u'下架'
	actual.swipe_images = json.loads(actual.swipe_images_json)

	#填充model信息
	actual.model = {'property':{}}
	if actual.is_use_custom_model:
		pass
	else:
		product_models = actual.models
		models = {}
		for product_model in product_models:
			if product_model['name'] == 'standard':
				models['standard'] = {
					"price": product_model['price'],
					"market_price": product_model['market_price'],
					"weight": product_model['weight'],
					"market_price": "" if product_model['market_price'] == 0 else product_model['market_price'],
					"stock_type": u'无限' if product_model['stock_type'] == PRODUCT_STOCK_TYPE_UNLIMIT else u'有限',
					"stocks": product_model['stocks']
				}
		actual.model['models'] = models

	bdd_util.assert_dict(expected, actual)
Esempio n. 15
0
def step_impl(context, user, sign_name):
    """
	feature数据生成Page,与数据库Page比较
	"""
    # feature数据
    if context.text:
        sign_json = json.loads(context.text)

    else:
        sign_json = {}

    status = sign_json.get('status', "")
    name = sign_json.get('name', "")
    sign_describe = sign_json.get('sign_describe', "")
    share = {
        "img": sign_json.get("share_pic", ""),
        "desc": sign_json.get("share_describe", "")
    }

    # 方案1:核对Page
    # 问题:模板组建的变化,也许需要更改组件
    # 发现一个坑,python中的True在Mongo中被保存为'true',需要在字典中手动修改
    # 尝试自己写增强的判断函数,连带着各种麻烦,在这里留个戳,告诉后来人
    json_page = json.loads(context.json_page)  #dict
    db_page = __get_DB_DynamicPages(context.project_id)[0]  #永远是list第一项dict型

    if db_page["is_new_created"]:
        db_page["is_new_created"] = "true"
    else:
        db_page["is_new_created"] = "false"
    bdd_util.assert_dict(json_page, db_page)
Esempio n. 16
0
def step_impl(context, user):
    if hasattr(context, 'client'):
        context.client.logout()
    context.client = bdd_util.login(user)
    client = context.client

    response = client.get('/new_weixin/follow_rules/')
    print(response.context['rule'])

    rule = response.context['rule']
    if rule == None:
        actual = {"answer": '', "material_id": 0, "type": 'text'}
    else:
        try:
            answers = json.loads(rule.answer)
            if len(answers) > 0:
                rule.answer = answers[0]['content']
        except:
            pass

        actual = {
            "answer": rule['answer']['content'],
            "material_id": rule['material_id'],
            "type": "news" if rule['type'] == NEWS_TYPE else 'text'
        }
    expected = json.loads(context.text)
    bdd_util.assert_dict(expected, actual)
Esempio n. 17
0
def step_impl(context, webapp_user_name):
    try:
        #抽奖成功获得奖励
        expected = json.loads(context.text)
        lottery_result = context.lottery_result['data']

        type2name = {
            'integral': u'积分',
            'coupon': u'优惠券',
            'entity': u'实物',
            'no_prize': u'谢谢参与'
        }
        # 构造实际数据
        actual = {
            "prize_grade": lottery_result['result'],
            "prize_type": type2name[lottery_result['prize_type']],
            "prize_name": lottery_result['prize_name']
        }

        bdd_util.assert_dict(expected, actual)
    except:
        #抽奖失败获得错误提示
        expected = context.text.strip()
        errMsg = context.lottery_result['errMsg']
        if errMsg == u'该抽奖码已经被使用过~':
            errMsg = u'该抽奖码已使用'

        context.tc.assertEquals(expected, errMsg)
Esempio n. 18
0
def _get_product_model_name_from_ids(webapp_owner_id, ids):
	if ids is None or ids == "standard":
		return "standard"
	return get_custom_model_id_from_name(webapp_owner_id ,ids)

# jz 2015-09-02
# @then(u"{webapp_user_name}成功创建订单")
# def step_impl(context, webapp_user_name):
# 	order_id = context.created_order_id
# 	if order_id == -1:
# 		print('Server Error: ', json.dumps(json.loads(context.response.content), indent=True))
# 		assert False, "order_id must NOT be -1"
# 		return
# @then(u"{webapp_user_name}成功创建订单")
# def step_impl(context, webapp_user_name):
# 	order_id = context.created_order_id
# 	if order_id == -1:
# 		print('Server Error: ', json.dumps(json.loads(context.response.content), indent=True))
# 		assert False, "order_id must NOT be -1"
# 		return
#
# 	order = Order.objects.get(order_id=order_id)
#
# 	url = '/workbench/jqm/preview/?woid=%s&module=mall&model=order&action=pay&order_id=%s' % (context.webapp_owner_id, order_id)
# 	response = context.client.get(bdd_util.nginx(url), follow=True)
# 	actual_order = response.context['order']
# 	actual_order.ship_area = actual_order.area
# 	actual_order.status = ORDERSTATUS2TEXT[actual_order.status]
# 	#获取coupon规则名
# 	if (actual_order.coupon_id != 0) and (actual_order.coupon_id != -1):
# 		coupon = Coupon.objects.get(id=actual_order.coupon_id)
# 		actual_order.coupon_id = coupon.coupon_rule.name
#
# 	for product in actual_order.products:
# 		# print('---product---', product)
# 		if 'custom_model_properties' in product and product['custom_model_properties']:
# 			product['model'] = ' '.join([property['property_value'] for property in product['custom_model_properties']])
#
# 	# print('---actual_order---', actual_order)
# 	expected = json.loads(context.text)
# 	bdd_util.assert_dict(expected, actual_order)
	url = '/workbench/jqm/preview/?woid=%s&module=mall&model=order&action=pay&order_id=%s' % (context.webapp_owner_id, order_id)
	response = context.client.get(bdd_util.nginx(url), follow=True)
	actual_order = response.context['order']
	actual_order.ship_area = actual_order.area
	actual_order.status = ORDERSTATUS2TEXT[actual_order.status]
	#获取coupon规则名
	if (actual_order.coupon_id != 0) and (actual_order.coupon_id != -1):
		coupon = Coupon.objects.get(id=actual_order.coupon_id)
		actual_order.coupon_id = coupon.coupon_rule.name

	for product in actual_order.products:
		# print('---product---', product)
		if 'custom_model_properties' in product and product['custom_model_properties']:
			product['model'] = ' '.join([property['property_value'] for property in product['custom_model_properties']])

	# print('---actual_order---', actual_order)
	expected = json.loads(context.text)
	bdd_util.assert_dict(expected, actual_order)
Esempio n. 19
0
def step_impl(context, user):
    expected = json.loads(context.text)
    actual = {}
    data = context.stats_data
    actual[u'初次购买'] = data['order_num'] - data['repeated_num']
    actual[u'重复购买'] = data['repeated_num']

    bdd_util.assert_dict(expected, actual)
Esempio n. 20
0
def step_impl(context, user, page_count):
	user = context.client.user
	json_data = __get_pages_list(context)
	max_page = json_data['pageinfo']['max_page']

	actual = {"page_count": max_page}
	expected = {"page_count": page_count}
	bdd_util.assert_dict(expected, actual)
Esempio n. 21
0
def step_impl(context, user, sign_name, sign_tag):
    status2name = {u'开启': 1, u'关闭': 0}
    exsign_id = context.exsign_id
    db_sign = exSign.objects(id=exsign_id)[0]

    sign_status = {'status': status2name[sign_tag]}
    db_status = {'status': db_sign['status']}
    bdd_util.assert_dict(sign_status, db_sign)
Esempio n. 22
0
def step_impl(context, webapp_user_name):
    product_detail_page = context.page

    product_detail_page.show_purchase_panel()
    actual = product_detail_page.get_product_info()
    expected = json.loads(context.text)

    bdd_util.assert_dict(expected, actual)
def step_impl(context, user, coupon_id):
    expected = json.loads(context.text)

    coupon = _get_coupon_by_coupon_id(coupon_id)
    actual_product = dict()
    actual_product['coupon_code'] = coupon.coupon_id
    actual_product['coupon_status'] = _get_coupon_status_by(coupon)

    bdd_util.assert_dict(expected, actual_product)
Esempio n. 24
0
def step_get_product_stock(context, user, product_name):
    expected = json.loads(context.text)
    response = get_product_response_from_web_page(context, product_name)
    product = response.context['product']
    actual_product = dict()
    actual_product['name'] = product.name
    actual_product['stocks'] = product.stocks

    bdd_util.assert_dict(expected, actual_product)
Esempio n. 25
0
def step_impl(context, user, pay_interface_description):
	pay_interface_list_page = PayInterfaceListPage(context.driver)
	pay_interface_list_page.load()
	edit_pay_interface_page = pay_interface_list_page.enter_edit_pay_interface_page(pay_interface_description)

	actual = edit_pay_interface_page.get_pay_interface()
	expected = json.loads(context.text)

	bdd_util.assert_dict(expected, actual)
def step_impl(context, webapp_user_name):
    expected = json.loads(context.text)

    # profile = context.client.user.profile
    member = bdd_util.get_member_for(webapp_user_name, context.webapp_id)
    actual_data = dict()
    actual_data['integral'] = str(member.integral)

    bdd_util.assert_dict(expected, actual_data)
Esempio n. 27
0
def step_impl(context, user):
    expected = json.loads(context.text)
    response = context.client.get('/mall2/api/order_list/')
    total_orders_count = json.loads(
        response.content)['data']['order_return_count']

    actual = {'total_orders_count': total_orders_count}

    bdd_util.assert_dict(expected, actual)
Esempio n. 28
0
def step_impl(context, user):
    expected = json.loads(context.text)
    actual = {}
    data = context.stats_data['order_trend_stats']
    actual[u'待发货'] = data['not_shipped_num']
    actual[u'已发货'] = data['shipped_num']
    actual[u'已完成'] = data['succeeded_num']

    bdd_util.assert_dict(expected, actual)
Esempio n. 29
0
def step_impl(context, user, product_model_property_name):
	product_model_list_page = ProductModelListPage(context.driver)
	product_model_list_page.load()

	edit_product_model_page = product_model_list_page.enter_edit_product_model_page(product_model_property_name)
	actual = edit_product_model_page.get_product_model()

	expected = json.loads(context.text)
	bdd_util.assert_dict(expected, actual)
Esempio n. 30
0
def step_impl(context, webapp_owner_name):
    db_order = steps_db_util.get_latest_order()
    response = context.client.get('/mall2/order/?order_id=%d' % db_order.id,
                                  follow=True)

    order = response.context['order']

    expected = json.loads(context.text)
    bdd_util.assert_dict(expected, order)