Beispiel #1
0
def __get_DynamicPage(context,project_id,design_mode=0,version=1):
	"""
	step3 获得Page右边个人配置JSON
	"""
	get_dynamicPage_response = context.client.get('/apps/api/dynamic_pages/get/',{'project_id':project_id})
	bdd_util.assert_api_call_success(get_dynamicPage_response)
	return get_dynamicPage_response
Beispiel #2
0
def __Search_Vote(context, search_dic):
    """
	搜索投票活动

	输入搜索字典
	返回数据列表
	"""

    design_mode = 0
    version = 1
    page = 1
    enable_paginate = 1
    count_per_page = 10

    #分页情况,更新分页参数
    if hasattr(context, "paging"):
        paging_dic = context.paging
        count_per_page = paging_dic['count_per_page']
        page = paging_dic['page_num']

    name = search_dic["name"]
    start_time = search_dic["start_time"]
    end_time = search_dic["end_time"]
    status = search_dic["status"]
    prize_type = search_dic['prize_type']

    search_url = "/apps/vote/api/votes/?design_mode={}&version={}&name={}&status={}&prize_type={}&start_time={}&end_time={}&count_per_page={}&page={}&enable_paginate={}".format(
        design_mode, version, name, status, prize_type, start_time, end_time,
        count_per_page, page, enable_paginate)

    search_response = context.client.get(search_url)
    bdd_util.assert_api_call_success(search_response)
    return search_response
Beispiel #3
0
def step_impl(context, user, powerme_name):
    powerme_page_id, powerme_id = __powerme_name2id(powerme_name)  #纯数字
    url = '/apps/powerme/api/powerme_participances_export/?_method=get&export_id=%s' % (
        powerme_id)
    url = bdd_util.nginx(url)
    response = context.client.get(url)
    bdd_util.assert_api_call_success(response)
def __update_prducts_by_name(context, product_name, action, user):
    ACTION2TYPE = {
        u'上架': 'onshelf',
        u'下架': 'offshelf',
        u'回收站': 'recycled',
        u'永久删除': 'delete',
        u'删除': 'delete',
        u'彻底删除': 'delete',
    }
    action = ACTION2TYPE[action]
    if action == 'offshelf':
        time.sleep(1)  #处理下架时睡眠一秒,避免测试结果不准
    data = {'shelve_type': action}

    user_id = User.objects.get(username=user).id
    if isinstance(product_name, list):
        data['ids'] = []
        for product_name in product_name:
            product_id = mall_models.Product.objects.get(owner_id=user_id,
                                                         name=product_name).id
            data['ids'].append(product_id)
    else:
        data['ids'] = mall_models.Product.objects.get(owner_id=user_id,
                                                      name=product_name).id
        context.product_name = product_name

    response = context.client.post('/mall2/api/product_list/?_method=post',
                                   data)
    bdd_util.assert_api_call_success(response)
Beispiel #5
0
def __Search_Powerme_Result(context, search_dic):
    """
	搜索,微助力参与结果

	输入搜索字典
	返回数据列表
	"""

    design_mode = 0
    version = 1
    page = 1
    enable_paginate = 1
    count_per_page = 10

    id = search_dic["id"]
    participant_name = search_dic["participant_name"]
    start_time = search_dic["start_time"]
    end_time = search_dic["end_time"]

    search_url = "/apps/powerme/api/powerme_participances/?design_mode={}&version={}&id={}&participant_name={}&start_time={}&end_time={}&count_per_page={}&page={}&enable_paginate={}".format(
        design_mode, version, id, participant_name, start_time, end_time,
        count_per_page, page, enable_paginate)

    search_response = context.client.get(search_url)
    bdd_util.assert_api_call_success(search_response)
    return search_response
def step_add_red_envelope_rule(context, user):
    rules = json.loads(context.text)
    for rule in rules:
        limit_money = rule.get('limit_money', 0)
        if limit_money == u'无限制':
            limit_money = 0
        receive_method = rule.get('receive_method', 0)
        if receive_method == u'下单领取':
            receive_method = False #下单领取
        else:
            receive_method = '' #图文领取,receive-method-order为空
        params = {
            'owner': context.client.user,
            'name': rule.get('name', ''),
            'coupon_rule': __get_coupon_rule_id(rule.get('prize_info', '')),
            'start_date': __get_date(rule.get('start_date', default_date)),
            'end_date': __get_date(rule.get('end_date', default_date)),
            'receive-method-order': receive_method,
            'limit_money': limit_money,
            'detail': rule.get('detail', ''),
            'share_pic': rule.get('share_pic', ''),
            'remark': rule.get('remark', '')
        }
        response = context.client.post('/apps/red_envelope/api/red_envelope_rule/?_method=put', params)
        bdd_util.assert_api_call_success(response)
Beispiel #7
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)
def _put_product_will_sale(context, user, product_names, sync_time=None):
    user_id = User.objects.get(username=user).id
    product_name2product_id = dict([
        (product.name, product.id) for product in Product.objects.filter(
            name__in=product_names, supplier_user_id=0, is_deleted=False)
    ])

    url = '/mall2/api/product_pool/?method=put'
    args = {
        'product_ids': json.dumps(product_name2product_id.values()),
        '_method': 'put'
    }
    response = context.client.post(url, args)
    bdd_util.assert_api_call_success(response)
    if sync_time:
        for product_name, product_id in product_name2product_id.items():
            sync_product = Product.objects.get(name=product_name,
                                               owner_id=user_id,
                                               is_deleted=False)
            sync_product_id = sync_product.id
            sync_product.created_at = sync_time
            sync_product.save()

            WeizoomHasMallProductRelation.objects.filter(
                mall_product_id=product_id,
                weizoom_product_id=sync_product_id).update(sync_time=sync_time)
def __post_PageJson(context, post_args, project_id, design_mode=0, version=1):
    """
	step5 POST,PageJSON到Mongo,返回Page_id

	参数:
	termite_post_args={
		"field":"page_content",
		"id":project_id,
		"page_id":"1",
		"page_json": "",
	}

	"""
    termite_url = "/termite2/api/project/?design_mode={}&project_id={}&version={}".format(
        design_mode, project_id, version)
    if post_args:
        termite_post_args = post_args
    else:
        termite_post_args = {
            "field": "page_content",
            "id": project_id,
            "page_id": "1",
            "page_json": "",
        }
    post_termite_response = context.client.post(termite_url, termite_post_args)
    bdd_util.assert_api_call_success(post_termite_response)
    return post_termite_response
Beispiel #10
0
def add_supplier(context, user):
    client = context.client
    context.suppliers = json.loads(context.text)
    for supplier in context.suppliers:
        response = client.post('/mall2/api/supplier_info/?_method=put',
                               supplier)
        bdd_util.assert_api_call_success(response)
def __Search_Group(context, search_dic):
    """
    搜索团购活动

    输入搜索字典
    返回数据列表
    """

    design_mode = 0
    version = 1
    page = 1
    enable_paginate = 1
    count_per_page = 10

    group_name = unicode(search_dic["group_name"])
    product_name = unicode(search_dic["product_name"])
    start_time = search_dic["start_time"]
    end_time = search_dic["end_time"]
    status = __name2status(search_dic["status"])

    search_url = "/apps/group/api/groups/?design_mode={}&version={}&group_name={}&product_name={}&status={}&start_time={}&end_time={}&count_per_page={}&page={}&enable_paginate={}".format(
        design_mode, version, group_name, product_name, status, start_time,
        end_time, count_per_page, page, enable_paginate)

    search_response = context.client.get(search_url)
    bdd_util.assert_api_call_success(search_response)
    return search_response
def create_issuing_coupons_record(context):
    url = "/mall2/api/issuing_coupons_record/?_method=put"
    data = json.loads(context.text)
    coupon_rule_name = data['name']
    pre_person_count = data['count']
    members = data['members']

    member_ids = []
    for name in members:
        member_ids.append(
            Member.objects.get(username_hexstr=byte_to_hex(name)).id)

    coupon_rule_id = promotion_models.CouponRule.objects.get(
        name=coupon_rule_name).id
    post_data = {
        'member_id': json.dumps(member_ids),
        'coupon_rule_id': coupon_rule_id,
        'pre_person_count': pre_person_count
    }
    response = context.client.post(url, post_data)
    try:
        bdd_util.assert_api_call_success(response)
        return True
    except:
        context.response = response
        return False
Beispiel #13
0
def __Search_Lottery_Result(context, search_dic):
    """
	搜索,抽奖参与结果

	输入搜索字典
	返回数据列表
	"""

    design_mode = 0
    version = 1
    page = 1
    enable_paginate = 1
    count_per_page = 10

    id = search_dic["id"]
    participant_name = search_dic["participant_name"]
    start_time = search_dic["start_time"]
    end_time = search_dic["end_time"]
    prize_type = __name2type(search_dic['prize_type'])
    status = __name2coupon_status(search_dic['status'])

    search_url = "/apps/lottery/api/lottery_participances/?design_mode={}&version={}&id={}&participant_name={}&start_time={}&end_time={}&prize_type={}&status={}&count_per_page={}&page={}&enable_paginate={}".format(
        design_mode, version, id, participant_name, start_time, end_time,
        prize_type, status, count_per_page, page, enable_paginate)

    search_response = context.client.get(search_url)
    bdd_util.assert_api_call_success(search_response)
    return search_response
Beispiel #14
0
def step_impl(context, user, template_name):
    user = User.objects.filter(username=user)
    template_id = ProductLimitZoneTemplate.objects.filter(
        owner=user, name=template_name).first().id

    data = json.loads(context.text)
    url = '/mall2/api/product_limit_zone_template/'

    template_name = data['name']
    provinces = []
    cities = []
    for limit_area in data['limit_area']:
        if type(limit_area['province']) is types.UnicodeType:
            provinces.append(limit_area['province'])
        if type(limit_area['province']) is types.ListType:
            provinces += limit_area['province']
        if limit_area.has_key('city'):
            cities += limit_area['city']
    province_ids = []

    for province in provinces:
        province_ids.append(
            str(Province.objects.filter(name__contains=province).first().id))
    city_ids = City.objects.filter(name__in=cities).values_list('id',
                                                                flat=True)
    args = {
        'template_id': template_id,
        'template_name': template_name,
        'province_ids': json.dumps(province_ids),
        'city_ids': json.dumps([str(id) for id in city_ids])
    }
    response = context.client.post(url, args)
    bdd_util.assert_api_call_success(response)
def step_impl(context, user):
	start_date = bdd_util.get_date_str(context.date_dict['start_date'])
	end_date = bdd_util.get_date_str(context.date_dict['end_date'])

	url = '/stats/api/member_detail_data/?start_date=%s&end_date=%s' % (start_date, end_date)
	response = context.client.get(url)
	bdd_util.assert_api_call_success(response)
	results = json.loads(response.content)
	print("results: {}".format(results))
	actual = results['data']['items']

	expected = []
	for row in context.table:
		expected_dict = {}
		expected_dict['date'] = bdd_util.get_date_str(row['date'])
		expected_dict['new_member_count'] = row['new_member']
		expected_dict['binding_phone_member_count'] = row['mobile_phone_member']
		expected_dict['share_url_member_count'] = row['launch_share_link_member']
		expected_dict['member_from_share_url_count'] = row['share_link_new_member']
		expected_dict['ori_qrcode_member_count'] = row['launch_spreading_code_member']
		expected_dict['member_from_qrcode_count'] = row['spreading_code_new_member']
		expected_dict['bought_member_count'] = row['order_member']

		expected.append(expected_dict)

	bdd_util.assert_list(expected, actual)
Beispiel #16
0
def step_impl(context, user):
    data = json.loads(context.text)
    grade_name = data['grade']
    grade_id = MemberGrade.objects.get(webapp_id=context.webapp_id,
                                       name=grade_name).id
    tag_ids = []
    if data.has_key('tags'):
        for tag_name in data['tags']:
            tag_ids.append(
                str(
                    MemberTag.objects.get(webapp_id=context.webapp_id,
                                          name=tag_name).id))
    if data.has_key('sex'):
        if data['sex'] == '未知':
            sex = 0
        elif data['sex'] == '男':
            sex = 1
        elif data['sex'] == '女':
            sex = 2
    else:
        sex = 0
    args = {
        'member_id': context.member_id,
        'grade_id': grade_id,
        'member_remarks': data['remarks'],
        'name': data['name'],
        'sex': sex,
        'phone_number': data['phone'],
        'tag_ids': '_'.join(tag_ids)
    }

    response = context.client.post('/member/api/detail/', args)
    bdd_util.assert_api_call_success(response)
Beispiel #17
0
def __finish_fobidden_coupon_product(context, ids):
    data = {
        'id': json.dumps(ids),
    }
    url = '/mall2/api/forbidden_coupon_product/?_method=post'
    response = context.client.post(url, data)
    bdd_util.assert_api_call_success(response)
Beispiel #18
0
def __get_Keywords(context):
	"""
	step4 获得关键字JSON
	"""
	keyword_response = context.client.get('/apps/sign/api/sign/')
	bdd_util.assert_api_call_success(keyword_response)
	return keyword_response
Beispiel #19
0
def __Search_Powerme(context, search_dic):
    """
	搜索微助力活动

	输入搜索字典
	返回数据列表
	"""

    design_mode = 0
    version = 1
    page = 1
    enable_paginate = 1
    count_per_page = 10

    name = search_dic["name"]
    start_time = search_dic["start_time"]
    end_time = search_dic["end_time"]
    status = __name2status(search_dic["status"])

    search_url = "/apps/powerme/api/powermes/?design_mode={}&version={}&name={}&status={}&start_time={}&end_time={}&count_per_page={}&page={}&enable_paginate={}".format(
        design_mode, version, name, status, start_time, end_time,
        count_per_page, page, enable_paginate)

    search_response = context.client.get(search_url)
    bdd_util.assert_api_call_success(search_response)
    return search_response
Beispiel #20
0
def step_impl(context, user, order_code):
    url = '/mall2/api/order/'
    post_data = json.loads(context.text)
    order_real_id = bdd_util.get_order_by_order_no(order_code).id
    post_data['order_id'] = order_real_id
    response = context.client.post(url, post_data)
    bdd_util.assert_api_call_success(response)
Beispiel #21
0
def step_impl(context, user, template_name):
    user = User.objects.filter(username=user)
    template_id = ProductLimitZoneTemplate.objects.filter(
        owner=user, name=template_name).first().id
    url = "/mall2/api/product_limit_zone/?_method=delete"

    response = context.client.post(url, {'template_id': template_id})
    bdd_util.assert_api_call_success(response)
def step_delete_image_group(context, user, image_group_name):
    db_image_group = mall_models.ImageGroup.objects.get(
        owner_id=context.webapp_owner_id, name=image_group_name)

    data = {"id": db_image_group.id}
    url = '/mall2/api/image_group/?_method=delete'
    response = context.client.post(url, data)
    bdd_util.assert_api_call_success(response)
Beispiel #23
0
def step_impl(context, action, user, order_code):
    url = '/mall2/api/refund_successful_sub_order/?_method=put'
    order_id = bdd_util.get_order_by_order_no(order_code).origin_order_id
    delivery_item_id = bdd_util.get_order_by_order_no(order_code).id

    data = {'order_id': order_id, 'delivery_item_id': delivery_item_id}
    response = context.client.post(url, data)
    bdd_util.assert_api_call_success(response)
Beispiel #24
0
def step_impl(context, user):
    client = context.client
    navbar = json.loads(context.text)

    data = {"is_enable": "1", "data": __process_navbar_data(navbar)}

    response = context.client.post('/webapp/api/global_navbar/update/', data)
    bdd_util.assert_api_call_success(response)
Beispiel #25
0
def step_delete_model_property(context, user, product_model_property_name):
    user_id = bdd_util.get_user_id_for(user)
    db_model_property = mall_models.ProductModelProperty.objects.get(
        owner_id=user_id, name=product_model_property_name, is_deleted=False)

    url = '/mall2/api/model_property/?_method=delete'
    response = context.client.post(url, {'id': db_model_property.id})
    bdd_util.assert_api_call_success(response)
def create_postage(context, user):
    client = context.client
    context.postages = json.loads(context.text)
    spcial_area_index = -1
    for postage in context.postages:
        data = __get_post_data_postage(postage)
        response = client.post('/mall2/api/postage/?_method=put', data)
        bdd_util.assert_api_call_success(response)
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_delete_p_in_categroy(context, user, category_name, product_name):
    existed_product_category = ProductCategoryFactory(name=category_name)
    existed_product = mall_models.Product.objects.get(name=product_name)
    data = {
        'category_id': existed_product_category.id,
        'product_id': existed_product.id
    }
    url = '/mall2/api/category/?_method=delete'
    response = context.client.post(url, data)
    bdd_util.assert_api_call_success(response)
def step_impl(context):
	client = context.client
	date_dict = context.date_dict[0]
	begin_date = bdd_util.get_date(date_dict['begin_date'])
	end_date = bdd_util.get_date(date_dict['end_date'])

	url = u'/stats/api/manage_summary/?design_mode=0&version=1&start_date={}&end_date={}&count_per_page=10&page=1&enable_paginate=1'.format(util_dateutil.date2string(begin_date), util_dateutil.date2string(end_date))
	context.response = client.get(url)
	bdd_util.assert_api_call_success(context.response)
	context.data = json.loads(context.response.content)['data']
def step_update_category(context, user, category_name):
    client = context.client
    existed_product_category = ProductCategoryFactory(name=category_name)
    new_product_category = json.loads(context.text)
    data = {
        'id': existed_product_category.id,
        'name': new_product_category['name']
    }
    url = '/mall2/api/category/'
    response = client.post(url, data)
    bdd_util.assert_api_call_success(response)