Example #1
0
def step_impl(context, user, order_type):
    user_id = User.objects.get(username=user).id
    mall_type = UserProfile.objects.get(user_id=user_id).webapp_type
    if user != context.client.user.username:
        context.client.logout()
        context.client = bdd_util.login(user)

    if order_type == '退款中':
        url = '/mall2/api/order_list/?design_mode=0&version=1&belong=audit&orderSupplierType=undefined&order_status=6&count_per_page=9999'

    elif order_type == '退款成功':
        url = '/mall2/api/order_list/?design_mode=0&version=1&belong=audit&orderSupplierType=undefined&order_status=7&date_interval_type=1&count_per_page=9999'
    elif order_type == '全部':
        url = '/mall2/api/order_list/?design_mode=0&version=1&belong=audit&orderSupplierType=undefined&order_status=-1&date_interval_type=1&count_per_page=9999'

    query_params = dict()
    if hasattr(context, 'query_params'):
        query_params = context.query_params
        delattr(context, 'query_params')
    response = context.client.get(url, query_params)

    items = json.loads(response.content)['data']['items']

    actual_orders = __get_order_items_for_self_order(items)

    expected = json.loads(context.text)
    for order in expected:
        if 'actions' in order:
            order['actions'] = set(order['actions'])  # 暂时不验证顺序

    bdd_util.assert_list(expected, actual_orders)
Example #2
0
def step_impl(context, user):
    user_id = User.objects.get(username=user).id
    mall_type = UserProfile.objects.get(user_id=user_id).webapp_type
    if user != context.client.user.username:
        context.client.logout()
        context.client = bdd_util.login(user)

    url = '/mall2/api/order_list/'

    query_params = dict()

    if hasattr(context, 'query_params'):
        query_params = context.query_params
        query_params['count_per_page'] = 99999
        delattr(context, 'query_params')
    response = context.client.get(url, query_params)

    items = json.loads(response.content)['data']['items']
    actual_orders = __get_order_items_for_self_order(items)

    expected = json.loads(context.text)
    for order in expected:
        # if order.get('payment_time',''):
        #     del order['payment_time']
        if 'actions' in order:
            order['actions'] = order['actions']  # 暂时不验证顺序

    bdd_util.assert_list(expected, actual_orders)
Example #3
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)
Example #4
0
def step_get_all_info_of_order(context, user):
    filter_value = dict()
    if hasattr(context, 'export_query_params'):
        filter_value = context.export_query_params
        filter_value["bdd"] = 1
        #print "filter_value---------------",filter_value
        delattr(context, 'export_query_params')
    from cStringIO import StringIO
    import csv

    url = '/mall2/order_export/?bdd=1'
    response = context.client.get(url, filter_value)
    reader = csv.reader(StringIO(response.content))
    # 去掉表头信息
    csv_items = [row for row in reader]
    context.last_csv_order_info = csv_items[-1]
    all_info = context.last_csv_order_info
    expect_info = json.loads(context.text)
    actual = dict([(info.split(':')[0].encode('utf-8'), info.split(':')[1])
                   for info in all_info[1:]])
    actual_encode = {}
    for x, y in actual.items():
        x = x.encode('utf-8')
        actual_encode[unicode(x)] = y

    bdd_util.assert_list(expect_info, [actual_encode])
Example #5
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)
def step_impl(context, user):
    # client = context.client
    pay_interfaces = json.loads(context.text)
    # data = {}
    context.client.get('/mall2/pay_interface_list/')
    for pay_interface in pay_interfaces:
        __add_pay_interface(context, pay_interface)
Example #7
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)
Example #8
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)
def step_impl(context, user):
    client = context.client
    pay_interfaces = json.loads(context.text)
    data = {}
    context.client.get('/mall2/pay_interface_list/')
    is_only_one_pay_interface = len(pay_interfaces) == 1
    for pay_interface in pay_interfaces:
        __add_pay_interface(context, pay_interface)
        if is_only_one_pay_interface:
            break
Example #10
0
def step_impl(context, user):
    """TODO 弃用 改用 @when(u"{webapp_user_name}购买{webapp_owner_name}的商品")
    """
    if not hasattr(context.client.user, 'profile'):
        context.client.logout()
        context.client = bdd_util.login(user)
    profile = context.client.user.profile
    # webapp_id = context.client.user.profile.webapp_id

    context.orders = json.loads(context.text)
    for order in context.orders:
        steps_db_util.set_order_dict(order, profile)
Example #11
0
def step_impl(context, user, order_id):
    order = json.loads(context.text)
    express_value = express_util.get_value_by_name(order['logistics'])
    data_order_id = __get_order(context, order['order_no']).id
    if 'name' in order:
        express_value = order['name']
    url = '/mall2/api/delivery/'
    data = {
        'order_id': data_order_id,
        'express_company_name': express_value,
        'express_number': order['number'],
        'leader_name': 'aa' if 'shipper' not in order else order['shipper'],
        'is_update_express': 'true'
    }
    response = context.client.post(url, data)
Example #12
0
def step_imple(context, user, order_code):
    url = '/mall2/api/refunding_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

    a = json.loads(context.text)
    data = {
        'order_id': order_id,
        'delivery_item_id': delivery_item_id,
        'cash': a.get('cash', 0),
        'weizoom_card_money': a.get('weizoom_card', 0),
        'integral': a.get('integral', 0),
        'coupon_money': a.get('coupon_money', 0)
    }

    response = context.client.post(url, data)
    bdd_util.assert_api_call_success(response)
def step_impl(context, user):
    """
    只列出支付方式列表
    """
    expected = json.loads(context.text)

    response = context.client.get('/mall2/pay_interface_list/')
    interfaces = list(response.context['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)
Example #14
0
def step_impl(context, user):
    # if hasattr(context, 'client'):
    #     context.client.logout()

    # context.client = bdd_util.login(user)
    profile = context.client.user.profile
    webapp_id = context.client.user.profile.webapp_id

    expected = json.loads(context.text)

    order_id = steps_db_util.get_order_by_order_id(expected['order_no']).id
    response = context.client.get('/mall2/order/?order_id=%d' % order_id)

    order = response.context['order']
    actual_order = dict()
    actual_order['order_no'] = order.order_id
    actual_order['status'] = ORDERSTATUS2TEXT[order.status]

    bdd_util.assert_dict(expected, actual_order)
def step_impl(context, user, pay_interface_name):
    data = json.loads(context.text)

    pay_interface_type = __name_to_type(pay_interface_name)
    owner_id = bdd_util.get_user_id_for(user)
    interface = PayInterface.objects.get(owner_id=owner_id, type=pay_interface_type)

    # response = context.client.get('/mall2/pay_interface/', {'id': interface.id})
    # pay_interface = response.context['pay_interface'] # 参考pay_interface.py'

    param = {}
    if pay_interface_type == PAY_INTERFACE_WEIXIN_PAY:
        # 微信支付
        # weixin_pay_config = pay_interface.related_config
        if 'version' in data:
            param["pay_version"] = 0 if data['version'] == 'v2' else 1  # V3=>1

        if data.get('version', 'v2') == 'v2':
            param['type'] = pay_interface_type
            param['app_id'] = data.get('weixin_appid', '11')
            param['partner_id'] = data.get('weixin_partner_id', '22')
            param['partner_key'] = data.get('weixin_partner_key', '33')
            param['paysign_key'] = data.get('weixin_sign', '44')
        else:
            param['type'] = pay_interface_type
            param['app_id'] = data.get('weixin_appid', '11')
            param['app_secret'] = data.get('app_secret', '22')
            param['mch_id'] = data.get('mch_id', '33')  # mch_id
            param['api_key'] = data.get('api_key', '44')  # api_key
            # param['paysign_key'] = data.get('paysign_key', '55')

    elif pay_interface_type == PAY_INTERFACE_ALIPAY:
        param['type'] = pay_interface_type
        param['key'] = data['key']
        param['partner'] = data['partner']
        param['ali_public_key'] = data['ali_public_key']
        param['private_key'] = data['private_key']
        param['seller_email'] = data['seller_email']

    response = context.client.post('/mall2/pay_interface/?id=%d' % interface.id, param)
Example #16
0
def step_impl(context, user, order_code):
    order_db_id = bdd_util.get_order_by_order_no(order_code).id
    response = context.client.get('/mall2/order/?order_id=%d' % order_db_id)

    expected = json.loads(context.text)
    #expected.pop('total_save')
    order = response.context['order']
    child_orders = response.context['child_orders']

    order.order_no = order.order_id
    order.invoice = order.bill
    order.business_message = order.remark
    order.methods_of_payment = order.pay_interface_name
    order.weizoom_card = order.weizoom_card_money
    order.actions = [action.get('name', '') for action in order.actions]

    sub_orders = []

    for sub_order in child_orders:
        supplier_name = Supplier.objects.get(id=sub_order.supplier).name
        sub_order.order_no = u'{}-{}'.format(order.order_id, supplier_name)
        sub_order.status = sub_order.get_status_text()
        sub_order.products = []

        sub_orders.append(sub_order)

    _products = []
    order.refund_details = {
        'cash': order.refund_info['total_cash'],
        'weizoom_card': order.refund_info['total_weizoom_card_money'],
        'coupon_money': order.refund_info['total_coupon_money'],
        'integral_money': order.refund_info['total_integral_money'],
    }

    order.original_cash = order.refund_info['origin_final_price']
    order.original_weizoom_card = order.refund_info[
        'origin_weizoom_card_money']
    order.original_final_price = order.refund_info['origin_pay_money']
    order.refund_money = order.refund_info['refund_money']

    for p in order.products:
        p['supplier_id'] = p['supplier']
        p['supplier'] = p['supplier_name']
        # if p['promotion']:
        #     p['single_save'] = p['promotion']['promotion_saved_money']
        # else:
        #     p['single_save'] = 0

        _products.append(p)

    for p in _products:
        for o in sub_orders:
            if o.supplier == p['supplier_id']:
                o.products.append(p)

    print('-------------------------------------------', repr(_products))
    order.group = sub_orders
    final_price = order.final_price
    order.final_price = order.pay_money
    order.product_price = order.total_price
    order.cash = final_price
    order.products_count = order.number
    order.ship_area = order.area
    order.total_save = order.save_money
    order.status = order.get_status_text()

    bdd_util.assert_dict(expected, order)
Example #17
0
def step_get_specify_order(context, user):
    """
    """

    filter_value = dict()
    if hasattr(context, 'query_params'):
        filter_value = context.query_params
        filter_value["bdd"] = 1
    from cStringIO import StringIO
    import csv

    url = '/mall2/order_export/?bdd=1'
    response = context.client.get(url, filter_value)
    reader = csv.reader(StringIO(response.content))
    csv_items = [row for row in reader]
    csv_items[0] = [
        'order_no', 'order_time', 'pay_time', 'product_name', 'model',
        'product_unit_price', 'count', 'sales_money', 'weight',
        'methods_of_payment', 'money_total', 'money', 'money_wcard', 'postage',
        'integral', 'coupon_money', 'coupon_name', 'status', 'member',
        'ship_name', 'ship_tel', 'ship_province', 'ship_address', 'shipper',
        'leader_remark', 'sources', 'logistics', 'number', 'delivery_time',
        'remark', 'customer_message', 'customer_source',
        'customer_recommender', 'is_older_mermber', 'purchase_price',
        'purchase_costs'
    ]
    actual = []
    for row in csv_items[1:]:
        # if reader.line_num :
        item = dict(
            map(None, csv_items[0], [str(r).decode('utf8') for r in row]))
        item['ship_address'] = '' if not item.get(
            'ship_address') else item.get('ship_address').replace(' ', ',')
        if '' != item.get('pay_time') and '已完成' not in item.get(
                'pay_time').encode('utf-8'):
            data = datetime.strptime(item['pay_time'], '%Y-%m-%d %H:%M')
            item['pay_time'] = '%s 00:00' % data.strftime('%Y-%m-%d')
        if None != item.get('delivery_time') and '' != item.get(
                'delivery_time'):
            data = datetime.strptime(item['delivery_time'], '%Y-%m-%d %H:%M')
            item['delivery_time'] = '%s 00:00' % data.strftime('%Y-%m-%d')
        actual.append(item)
    context.last_csv_order_info = csv_items[-1]
    # remove statistical information
    actual.pop()
    expected_order = []
    if context.table:
        for row in context.table:
            order = row.as_dict()
            if 'order_time' in order:
                if order['order_time'] != '':
                    order['order_time'] = bdd_util.get_datetime_no_second_str(
                        order['order_time'])
                else:
                    del order['order_time']

            if 'pay_time' in order:
                if order['pay_time'] != '':
                    order['pay_time'] = bdd_util.get_datetime_no_second_str(
                        order['pay_time'])
                else:
                    del order['pay_time']

            if 'delivery_time' in order:
                if order['delivery_time'] != '':
                    order[
                        'delivery_time'] = bdd_util.get_datetime_no_second_str(
                            order['delivery_time'])
                else:
                    del order['delivery_time']
            if '-' in order['order_no']:

                order_no_info = order['order_no'].split('-')
                if len(order_no_info) > 2:
                    order['order_no'] = '%s^%s-%s' % (
                        order_no_info[0],
                        Supplier.objects.get(name=order_no_info[1]).id,
                        order_no_info[2])
                else:
                    order_no_info = order['order_no'].split('-')
                    if u'' != order['edit_money']:
                        order['order_no'] = '%s-%s' % (order_no_info[0],
                                                       order_no_info[1])
                    else:
                        order['order_no'] = '%s^%s' % (
                            order_no_info[0],
                            Supplier.objects.get(name=order_no_info[1]).id)

            expected_order.append(order)
        for row in expected_order:
            if 'edit_money' in row:
                del row['edit_money']  # 不校验该字段,无效字段,只用来判断order_no的格式
    else:

        expected_order = json.loads(context.text)

    bdd_util.assert_list(expected_order, actual)
    del StringIO
    del csv
Example #18
0
def step_look_for_order(context, user):
    """根据给定条件查询订单

    context: {
        "order_no":          # 订单编号            e.g.:
        "ship_name":         # 收货人姓名          e.g.:
        "ship_tel":          # 收货人电话          e.g.:
        "product_name":      # 商品名称            e.g.:
        "date_interval":     # 查询时间段          e.g.: 今天 3天前  or  "2014-10-07|2014-10-08",
        "date_interval_type":# 时间类型            e.g.: 1 下单时间 2 付款时间 3 发货时间
        "pay_type":          # 支付方式            e.g.:
        "express_number":    # 物流单号            e.g.:
        "order_source":      # 订单来源            e.g.:
        "order_status":      # 订单状态            e.g.:
        "isUseWeizoomCard":  # 仅显示微众卡抵扣订单  e.g.:
        "is_first_order":        # 订单是不是首单
    }
    """
    query_params = {
        'pay_type': u'全部',
        'order_source': u'全部',
        'order_status': u'全部',
        'order_type': u'全部',
        'is_first_order': u'全部',
        'belong': 'all',
        "date_interval": "",
        "date_interval_type": 1,
        "product_name": "",
    }

    query_params_c = json.loads(context.text)
    query_params.update(query_params_c)
    if query_params.get('order_no'):
        query_params['query'] = query_params['order_no']
        query_params.pop('order_no')

    if query_params.get('date_interval'):
        query_params['date_interval']

    query_params['pay_type'] = PAYNAME2ID[query_params['pay_type']]
    if query_params['pay_type'] == -1:
        query_params.pop('pay_type')

    query_params['order_source'] = ORDER_SOURCE2ID[
        query_params['order_source']]
    if query_params['order_source'] == -1:
        query_params.pop('order_source')

    query_params['order_type'] = ORDER_TYPE[query_params['order_type']]
    if query_params['order_type'] == -1:
        query_params.pop('order_type')

    query_params['order_status'] = ORDER_STATUS2ID[
        query_params['order_status']]
    if query_params['order_status'] == -1:
        query_params.pop('order_status')

    #惠惠卡处理首单非首单
    # if query_params.get('is_first_order'):
    #     query_params['is_first_order'] = IS_FIRST_ORDER[query_params['is_first_order']]
    #     if query_params['is_first_order'] == -1:
    #         query_params.pop('is_first_order')
    is_first_order = True if (query_params.get('is_first_order')
                              in ('true', 'yes', 'True', 'Yes',
                                  True)) else False
    is_not_first_order = True if (query_params.get('is_not_first_order')
                                  in ('true', 'yes', 'True', 'Yes',
                                      True)) else False
    if query_params.get('is_not_first_order'):
        query_params.pop('is_not_first_order')
    if (is_first_order and is_not_first_order) or (not is_first_order
                                                   and not is_not_first_order):
        query_params.pop('is_first_order')
    if is_first_order and not is_not_first_order:
        query_params['is_first_order'] = '1'
    if not is_first_order and is_not_first_order:
        query_params['is_first_order'] = '0'
    #惠惠卡处理首单非首单
    if query_params.get('date'):
        query_params['date_interval_type'] = 1
        query_params['date_interval'] = bdd_util.get_date_to_time_interval(
            query_params.get('date'))
    if query_params.get('payment_time'):
        query_params['date_interval_type'] = 2
        query_params['date_interval'] = bdd_util.get_date_to_time_interval(
            query_params.get('payment_time'))
    if query_params.get('delivery_time'):
        query_params['date_interval_type'] = 3
        query_params['date_interval'] = bdd_util.get_date_to_time_interval(
            query_params.get('delivery_time'))

    if query_params.get('isUseWeizoomCard'):
        query_params['isUseWeizoomCard'] = 1 if query_params[
            'isUseWeizoomCard'] == 'true' else 0

    if query_params.get('supplier_type'):
        if query_params.get('supplier_type') == u'全部':
            del query_params['supplier_type']
            query_params['orderSupplierType'] = -1
        elif query_params.get('supplier_type') == u'同步供货商':
            del query_params['supplier_type']
            query_params['orderSupplierType'] = 0
        elif query_params.get('supplier_type') == u'自建供货商':
            del query_params['supplier_type']
            query_params['orderSupplierType'] = 1

    context.query_params = query_params
    context.export_query_params = query_params
Example #19
0
def step_impl(context, user, order_id):
    user_id = User.objects.get(username=user).id
    mall_type = UserProfile.objects.get(user_id=user_id).webapp_type
    real_id = bdd_util.get_order_by_order_no(order_id).id
    response = context.client.get('/mall2/order/?order_id=%d' % real_id)
    actual_order = response.context['order']

    actual_order.actions = get_order_action_set(actual_order.actions)

    source_dict = {0: u'本店', 1: u'商城'}
    actual_order.order_no = actual_order.order_id
    # actual_order.member = actual_order.buyer_name
    leader_name_and_remark = actual_order.leader_name.split('|')
    actual_order.shipper = leader_name_and_remark[0]
    if len(leader_name_and_remark) > 1:
        actual_order.leader_remark = leader_name_and_remark[1]
    actual_order.order_time = str(actual_order.created_at)
    actual_order.methods_of_payment = actual_order.pay_interface_name
    actual_order.sources = source_dict[actual_order.order_source]
    actual_order.status = STATUS2TEXT[actual_order.status]
    if actual_order.edit_money:
        actual_order.order_no = actual_order.order_no + "-" +\
            str(actual_order.edit_money).replace('.', '').replace('-', '')

    for product in actual_order.products:
        if 'supplier_store_name' in product:
            if product['supplier_store_name']:
                product['supplier'] = product['supplier_store_name']
        if 'supplier_name' in product:
            if product['supplier_name']:
                product['supplier'] = product['supplier_name']

    if '^' in actual_order.order_no:
        user_id = actual_order.order_no.split('^')[1][:-1]
        store_name = UserProfile.objects.get(user_id=user_id).store_name
        actual_order.order_no = '%s-%s' % (actual_order.order_no.split('^')[0],
                                           store_name)
        actual_order.sources = u'商城'
        actual_order.final_price = actual_order.total_purchase_price
    else:
        actual_order.sources = u'本店'

    expected = []
    if context.table:
        for order in context.table:
            expected.append(order.as_dict())
    else:
        expected = json.loads(context.text)
    if "logistics" in expected:
        express_value = express_util.get_value_by_name(expected['logistics'])
        expected['logistics'] = express_value
    if "actions" in expected:
        expected["actions"] = set(expected["actions"])

    if 'products' in expected:
        for product in expected['products']:
            if 'is_sync_supplier' in product:
                del product['is_sync_supplier']
    if mall_type and 'customer_message' in expected:
        expected['customer_message'] = __get_customer_message_str(
            expected['customer_message']).values()
        actual_order.customer_message = actual_order.customer_message

    # 会员详情页无会员信息
    if "member" in expected:
        del expected["member"]
    if actual_order.express_company_name:
        actual_order.logistics = actual_order.express_company_name
    # 字段名称不匹配,order中有number属性
    actual_order.number = actual_order.express_number
    bdd_util.assert_dict(expected, actual_order)
def step_impl(context, user):
    """
    列出支付方式的详细信息
    """
    url = '/mall2/pay_interface_list/'
    response = context.client.get(url)
    # print("pay_interface_list: {}".format(response.context['pay_interfaces']))

    expected = json.loads(context.text)
    if expected['type'] == u'微信支付':
        pay_interface_type = PAY_INTERFACE_WEIXIN_PAY
    elif expected['type'] == u'货到付款':
        pay_interface_type = PAY_INTERFACE_COD
    elif expected['type'] == u'微众卡支付':
        pay_interface_type = PAY_INTERFACE_WEIZOOM_COIN
    elif expected['type'] == u'支付宝':
        pay_interface_type = PAY_INTERFACE_ALIPAY

    target_pay_interface = None
    for this_pay_interface in response.context['pay_interfaces']:
        if this_pay_interface.type == pay_interface_type:
            target_pay_interface = this_pay_interface
            break

    actual = target_pay_interface
    actual.is_active = u'启用' if actual.is_active else u'停用'

    configs = {}
    if hasattr(actual, 'configs'):
        for actual_config in actual.configs:
            the_key = actual_config['name']
            the_value = actual_config['value']
            configs[the_key] = the_value
    if actual.type == PAY_INTERFACE_WEIXIN_PAY:
        actual.type = u'微信支付'
        if configs.get(u'接口版本','v2') == 'v2':
            actual.weixin_appid = configs[u"AppID"]
            actual.weixin_partner_id = configs[u"合作商户ID"]
            actual.weixin_partner_key = configs[u"合作商户密钥"]
            actual.weixin_sign = configs[u"支付专用签名串"]
            actual.version = configs[u"接口版本"]
        else:
            actual.version = configs[u"接口版本"]
            actual.weixin_appid = configs[u"AppID"]
            actual.mch_id = configs[u"商户号MCHID"]
            actual.api_key = configs[u'APIKEY密钥']
            # actual.paysign_key =
    elif actual.type == PAY_INTERFACE_ALIPAY:
        actual.type = u'支付宝'
        actual.description = u'我的支付宝'
        actual.partner = configs[u'合作者身份ID']
        actual.key = configs[u'交易安全检验码']
        actual.ali_public_key = configs[u'支付宝公钥']
        actual.private_key = configs[u'商户私钥']
        actual.seller_email = configs[u'邮箱']

    elif actual.type == PAY_INTERFACE_COD:
        actual.type = u'货到付款'
    elif actual.type == PAY_INTERFACE_WEIZOOM_COIN:
        actual.type = u'微众卡支付'
    else:
        pass

    # print("expected: {}".format(expected))
    # print("actual: {}".format(actual))

    bdd_util.assert_dict(expected, actual)
Example #21
0
def step_impl(context, user):
    user_id = User.objects.get(username=user).id
    mall_type = UserProfile.objects.get(user_id=user_id).webapp_type
    if user != context.client.user.username:
        context.client.logout()
        context.client = bdd_util.login(user)
    # client = context.client
    query_params = dict()
    if hasattr(context, 'query_params'):
        query_params = context.query_params
        delattr(context, 'query_params')
    response = context.client.get('/mall2/api/order_list/', query_params)
    items = json.loads(response.content)['data']['items']

    actual_orders = []
    source = {'mine_mall': u'本店', 'weizoom_mall': u'商城'}

    for order_item in items:
        sync_order = False
        if 'u' in order_item['order_id']:
            sync_order = True
            user_id = order_item['order_id'].split('^')[1][:-1]
            store_name = UserProfile.objects.get(user_id=user_id).store_name
            order_item['order_id'] = '%s-%s' % (
                order_item['order_id'].split('^')[0], store_name)
        actual_order = {}
        actual_order['order_no'] = order_item['order_id']
        actual_order['order_time'] = order_item['created_at']
        actual_order['ship_name'] = order_item['ship_name']
        actual_order['ship_tel'] = order_item['ship_tel']
        actual_order["sources"] = u'商城' if sync_order else u'本店'
        actual_order["member"] = order_item['buyer_name'] if order_item[
            'member_is_subscribed'] else '非会员'
        actual_order["methods_of_payment"] = order_item['pay_interface_name']
        actual_order["logistics"] = express_util.get_name_by_value(
            order_item['express_company_name'])
        actual_order["number"] = order_item['express_number']
        actual_order["shipper"] = order_item['leader_name']
        actual_order["integral"] = order_item['integral']
        actual_order['status'] = order_item['status']
        actual_order['price'] = order_item['pay_money']
        actual_order['payment_time'] = order_item['payment_time']
        actual_order['final_price'] = order_item['pay_money']
        actual_order['customer_message'] = order_item['customer_message']
        actual_order['buyer'] = order_item['buyer_name']
        actual_order['postage'] = order_item['postage']
        actual_order['save_money'] = '' if sync_order or not order_item[
            'save_money'] else order_item['save_money']
        actual_order['is_first_order'] = 'true' if order_item[
            'is_first_order'] else 'false'
        actual_order['is_group_buying'] = 'true' if order_item[
            'is_group_buying'] else 'false'

        if 'edit_money' in order_item and order_item['edit_money']:
            actual_order["order_no"] = actual_order["order_no"] + "-" + str(
                order_item['edit_money']).replace('.', '').replace('-', '')

        children_order_action = True
        if order_item['parent_action']:
            actual_order['actions'] = get_order_action_set(
                order_item['parent_action'])
        else:
            actual_order['actions'] = get_order_action_set(
                order_item['groups'][0]['fackorder']['actions'])

        if len(order_item['groups']) <= 1 or order_item['status'] == 0:
            children_order_action = False

        # order_list的接口数据返回格式已经更新,上面的代码可以改为如下代码:
        buy_product_results = []
        for group in order_item['groups']:
            for buy_product in group['products']:
                total_price = buy_product.get(
                    'total_price',
                    round(
                        float(buy_product.get('price')) *
                        buy_product.get('count'), 2))
                buy_product_result = {}
                buy_product_result['product_name'] = buy_product['name']
                buy_product_result['name'] = buy_product['name']
                buy_product_result['count'] = buy_product['count']
                buy_product_result['total_price'] = total_price
                buy_product_result[
                    'price'] = '' if sync_order else buy_product.get('price')
                buy_product_result['img_url'] = buy_product['thumbnails_url']
                buy_product_result['promotion'] = buy_product['promotion']
                if 'supplier_store_name' in buy_product:
                    if buy_product['supplier_store_name']:
                        buy_product_result['supplier'] = buy_product[
                            'supplier_store_name']
                if 'supplier_name' in buy_product:
                    if buy_product['supplier_name']:
                        buy_product_result['supplier'] = buy_product[
                            'supplier_name']
                buy_product_result['status'] = group['fackorder']['status']
                if children_order_action:
                    buy_product_result['actions'] = get_order_action_set(
                        group['fackorder']['actions'])
                buy_product_results.append(buy_product_result)
        actual_order['products'] = buy_product_results
        actual_order['products_count'] = len(buy_product_results)
        actual_orders.append(actual_order)

    expected = json.loads(context.text)
    for order in expected:
        if 'actions' in order:
            order['actions'] = set(order['actions'])  # 暂时不验证顺序
        for pro in order.get('products', []):
            if 'supplier' in pro and order.get('status', None) == u'待支付':
                del pro['supplier']
            if 'actions' in pro:
                pro['actions'] = set(pro['actions'])
            if 'is_sync_supplier' in pro:
                del pro['is_sync_supplier']
        if mall_type and order.get('customer_message'):
            order['customer_message'] = json.dumps(
                __get_customer_message_str(order['customer_message']))
            actual_order['products'] = sorted(actual_order['products'],
                                              key=lambda p: p['name'])
    # for i in range(len(expected)):
    #     # print expected[i]['order_no'], '++++', actual_orders[i]['order_no']
    #     # for j in range(len(expected[i]['products'])):
    #     #     print expected[i]['products'][j].get('actions',""), '****', actual_orders[i]['products'][j].get('actions',"")
    #     #     print expected[i]['products'][j].get('actions',"") == actual_orders[i]['products'][j].get('actions',"")
    #     print expected[i]['order_no'], '++++', actual_orders[i]['order_no']
    #     print expected[i]['price'], actual_orders[i]['price']
    # for i in range(len(expected[0]['products'])):
    #     print expected[0]['products'][i]['name'], "+++++++" ,actual_orders[0]['products'][i]['name']
    #     print expected[0]['products'][i]['price'], "+++++++" ,actual_orders[0]['products'][i]['price']
    bdd_util.assert_list(expected, actual_orders)