当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_graphql_content函数代码示例

本文整理汇总了Python中tests.api.utils.get_graphql_content函数的典型用法代码示例。如果您正苦于以下问题:Python get_graphql_content函数的具体用法?Python get_graphql_content怎么用?Python get_graphql_content使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_graphql_content函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_menu_query

def test_menu_query(user_api_client, menu):
    query = """
    query menu($id: ID, $menu_name: String){
        menu(id: $id, name: $menu_name) {
            name
        }
    }
    """

    # test query by name
    variables = {"menu_name": menu.name}
    response = user_api_client.post_graphql(query, variables)
    content = get_graphql_content(response)
    assert content["data"]["menu"]["name"] == menu.name

    # test query by id
    menu_id = graphene.Node.to_global_id("Menu", menu.id)
    variables = {"id": menu_id}
    response = user_api_client.post_graphql(query, variables)
    content = get_graphql_content(response)
    assert content["data"]["menu"]["name"] == menu.name

    # test query by invalid name returns null
    variables = {"menu_name": "not-a-menu"}
    response = user_api_client.post_graphql(query, variables)
    content = get_graphql_content(response)
    assert not content["data"]["menu"]
开发者ID:mirumee,项目名称:saleor,代码行数:27,代码来源:test_menu.py

示例2: test_digital_content_create_mutation_default_settings

def test_digital_content_create_mutation_default_settings(
        monkeypatch, staff_api_client, variant, permission_manage_products):
    query = """
    mutation digitalCreate($variant: ID!, 
        $input: DigitalContentUploadInput!) {
        digitalContentCreate(variantId: $variant, input: $input) {
            variant {
                id
            }
        }
    }
    """

    image_file, image_name = create_image()

    variables = {
        'variant': graphene.Node.to_global_id('ProductVariant', variant.id),
        'input': {
            'useDefaultSettings': True,
            'contentFile': image_name
        }
    }

    body = get_multipart_request_body(query, variables, image_file, image_name)
    response = staff_api_client.post_multipart(
        body, permissions=[permission_manage_products])
    get_graphql_content(response)
    variant.refresh_from_db()
    assert variant.digital_content.content_file
    assert variant.digital_content.use_default_settings
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:30,代码来源:test_digital_content.py

示例3: test_digital_content_delete_mutation

def test_digital_content_delete_mutation(
        monkeypatch, staff_api_client, variant, digital_content,
        permission_manage_products):
    query = """
    mutation digitalDelete($variant: ID!){
        digitalContentDelete(variantId:$variant){
            variant{
              id
            }
        }
    }
    """

    variant.digital_content = digital_content
    variant.digital_content.save()

    assert hasattr(variant, 'digital_content')
    variables = {
        'variant': graphene.Node.to_global_id('ProductVariant', variant.id)
    }

    response = staff_api_client.post_graphql(
        query, variables, permissions=[permission_manage_products])
    get_graphql_content(response)
    variant = ProductVariant.objects.get(id=variant.id)
    assert not hasattr(variant, 'digital_content')
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:26,代码来源:test_digital_content.py

示例4: test_digital_content_url_create

def test_digital_content_url_create(
        monkeypatch, staff_api_client, variant, permission_manage_products,
        digital_content):
    query = """
    mutation digitalContentUrlCreate($input: DigitalContentUrlCreateInput!) {
        digitalContentUrlCreate(input: $input) {
            digitalContentUrl {
                id
                url
            }
            errors {
                field
                message
            }
        }
    }
    """

    variables = {
        'input': {
            'content': graphene.Node.to_global_id(
                'DigitalContent', digital_content.id),
        }
    }

    assert digital_content.urls.count() == 0
    response = staff_api_client.post_graphql(
        query, variables, permissions=[permission_manage_products])
    get_graphql_content(response)

    digital_content.refresh_from_db()
    assert digital_content.urls.count() == 1
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:32,代码来源:test_digital_content.py

示例5: test_use_checkout_billing_address_as_payment_billing

def test_use_checkout_billing_address_as_payment_billing(
        user_api_client, cart_with_item, address):
    cart = cart_with_item
    checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)
    variables = {
        'checkoutId': checkout_id,
        'input': {
            'gateway': 'DUMMY',
            'token': 'sample-token',
            'amount': str(cart.get_total().gross.amount)}}
    response = user_api_client.post_graphql(CREATE_QUERY, variables)
    content = get_graphql_content(response)
    data = content['data']['checkoutPaymentCreate']

    # check if proper error is returned if address is missing
    assert data['errors'][0]['field'] == 'billingAddress'

    # assign the address and try again
    address.street_address_1 = 'spanish-inqusition'
    address.save()
    cart.billing_address = address
    cart.save()
    response = user_api_client.post_graphql(CREATE_QUERY, variables)
    content = get_graphql_content(response)
    data = content['data']['checkoutPaymentCreate']

    cart.refresh_from_db()
    assert cart.payments.count() == 1
    payment = cart.payments.first()
    assert payment.billing_address_1 == address.street_address_1
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:30,代码来源:test_payment.py

示例6: test_use_checkout_billing_address_as_payment_billing

def test_use_checkout_billing_address_as_payment_billing(
    user_api_client, checkout_with_item, address
):
    checkout = checkout_with_item
    checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
    variables = {
        "checkoutId": checkout_id,
        "input": {
            "gateway": "DUMMY",
            "token": "sample-token",
            "amount": str(checkout.get_total().gross.amount),
        },
    }
    response = user_api_client.post_graphql(CREATE_QUERY, variables)
    content = get_graphql_content(response)
    data = content["data"]["checkoutPaymentCreate"]

    # check if proper error is returned if address is missing
    assert data["errors"][0]["field"] == "billingAddress"

    # assign the address and try again
    address.street_address_1 = "spanish-inqusition"
    address.save()
    checkout.billing_address = address
    checkout.save()
    response = user_api_client.post_graphql(CREATE_QUERY, variables)
    content = get_graphql_content(response)
    data = content["data"]["checkoutPaymentCreate"]

    checkout.refresh_from_db()
    assert checkout.payments.count() == 1
    payment = checkout.payments.first()
    assert payment.billing_address_1 == address.street_address_1
开发者ID:mirumee,项目名称:saleor,代码行数:33,代码来源:test_payment.py

示例7: test_staff_query_unpublished_page

def test_staff_query_unpublished_page(staff_api_client, page, permission_manage_pages):
    page.is_published = False
    page.save()

    # query by ID
    variables = {"id": graphene.Node.to_global_id("Page", page.id)}
    response = staff_api_client.post_graphql(PAGE_QUERY, variables)
    content = get_graphql_content(response)
    assert content["data"]["page"] is None
    # query by slug
    variables = {"slug": page.slug}
    response = staff_api_client.post_graphql(PAGE_QUERY, variables)
    content = get_graphql_content(response)
    assert content["data"]["page"] is None

    # query by ID with page permissions
    variables = {"id": graphene.Node.to_global_id("Page", page.id)}
    response = staff_api_client.post_graphql(
        PAGE_QUERY,
        variables,
        permissions=[permission_manage_pages],
        check_no_permissions=False,
    )
    content = get_graphql_content(response)
    assert content["data"]["page"] is not None
    # query by slug with page permissions
    variables = {"slug": page.slug}
    response = staff_api_client.post_graphql(
        PAGE_QUERY,
        variables,
        permissions=[permission_manage_pages],
        check_no_permissions=False,
    )
    content = get_graphql_content(response)
    assert content["data"]["page"] is not None
开发者ID:mirumee,项目名称:saleor,代码行数:35,代码来源:test_page.py

示例8: test_shop_fetch_tax_rates

def test_shop_fetch_tax_rates(
        mock_call_command, staff_api_client, permission_manage_settings,
        settings):
    settings.VATLAYER_ACCESS_KEY = 'KEY'
    staff_api_client.user.user_permissions.add(permission_manage_settings)
    response = staff_api_client.post_graphql(
        MUTATION_SHOP_FETCH_TAX_RATES)
    get_graphql_content(response)
    mock_call_command.assert_called_once_with('get_vat_rates')
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:9,代码来源:test_shop.py

示例9: test_assign_menu

def test_assign_menu(
    staff_api_client,
    menu,
    permission_manage_menus,
    permission_manage_settings,
    site_settings,
):
    query = """
    mutation AssignMenu($menu: ID, $navigationType: NavigationType!) {
        assignNavigation(menu: $menu, navigationType: $navigationType) {
            errors {
                field
                message
            }
            menu {
                name
            }
        }
    }
    """

    # test mutations fails without proper permissions
    menu_id = graphene.Node.to_global_id("Menu", menu.pk)
    variables = {"menu": menu_id, "navigationType": NavigationType.MAIN.name}
    response = staff_api_client.post_graphql(query, variables)
    assert_no_permission(response)

    staff_api_client.user.user_permissions.add(permission_manage_menus)
    staff_api_client.user.user_permissions.add(permission_manage_settings)

    # test assigning main menu
    response = staff_api_client.post_graphql(query, variables)
    content = get_graphql_content(response)
    assert content["data"]["assignNavigation"]["menu"]["name"] == menu.name
    site_settings.refresh_from_db()
    assert site_settings.top_menu.name == menu.name

    # test assigning secondary menu
    variables = {"menu": menu_id, "navigationType": NavigationType.SECONDARY.name}
    response = staff_api_client.post_graphql(query, variables)
    content = get_graphql_content(response)
    assert content["data"]["assignNavigation"]["menu"]["name"] == menu.name
    site_settings.refresh_from_db()
    assert site_settings.bottom_menu.name == menu.name

    # test unasigning menu
    variables = {"id": None, "navigationType": NavigationType.MAIN.name}
    response = staff_api_client.post_graphql(query, variables)
    content = get_graphql_content(response)
    assert not content["data"]["assignNavigation"]["menu"]
    site_settings.refresh_from_db()
    assert site_settings.top_menu is None
开发者ID:mirumee,项目名称:saleor,代码行数:52,代码来源:test_menu.py

示例10: test_customer_query_unpublished_page

def test_customer_query_unpublished_page(user_api_client, page):
    page.is_published = False
    page.save()

    # query by ID
    variables = {'id': graphene.Node.to_global_id('Page', page.id)}
    response = user_api_client.post_graphql(PAGE_QUERY, variables)
    content = get_graphql_content(response)
    assert content['data']['page'] is None

    # query by slug
    variables = {'slug': page.slug}
    response = user_api_client.post_graphql(PAGE_QUERY, variables)
    content = get_graphql_content(response)
    assert content['data']['page'] is None
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:15,代码来源:test_page.py

示例11: test_attribute_translation

def test_attribute_translation(user_api_client, color_attribute):
    color_attribute.translations.create(language_code='pl', name='Kolor')

    query = """
    query {
        attributes(first: 1) {
            edges {
                node {
                    translation(languageCode: PL) {
                        name
                        language {
                            code
                        }
                    }
                }
            }
        }
    }
    """

    response = user_api_client.post_graphql(query)
    data = get_graphql_content(response)['data']

    attribute = data['attributes']['edges'][0]['node']
    assert attribute['translation']['name'] == 'Kolor'
    assert attribute['translation']['language']['code'] == 'pl'
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:26,代码来源:test_translations.py

示例12: test_translations_query_inline_fragment

def test_translations_query_inline_fragment(user_api_client, product):
    product.translations.create(language_code='pl', name='Produkt testowy')

    query = """
    {
        translations(kind: PRODUCT, first: 1) {
            edges {
                node {
                    ... on Product {
                        name
                        translation(languageCode: PL) {
                            name
                        }
                    }
                }
            }
        }
    }
    """

    response = user_api_client.post_graphql(query)
    data = get_graphql_content(response)['data']['translations']['edges'][0]

    assert data['node']['name'] == 'Test product'
    assert data['node']['translation']['name'] == 'Produkt testowy'
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:25,代码来源:test_translations.py

示例13: test_shop_update_translation

def test_shop_update_translation(
        staff_api_client, site_settings, permission_manage_translations):
    site_settings.translations.create(
        language_code='pl', header_text='Nagłówek')

    query = """
    mutation shopSettingsTranslate {
        shopSettingsTranslate(
                languageCode: PL, input: {headerText: "Nagłówek PL"}) {
            shop {
                translation(languageCode: PL) {
                    headerText
                    language {
                        code
                    }
                }
            }
        }
    }
    """

    response = staff_api_client.post_graphql(
        query, permissions=[permission_manage_translations])
    data = get_graphql_content(response)['data']['shopSettingsTranslate']

    assert data['shop']['translation']['headerText'] == 'Nagłówek PL'
    assert data['shop']['translation']['language']['code'] == 'pl'
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:27,代码来源:test_translations.py

示例14: test_menu_item_update_translation

def test_menu_item_update_translation(
        staff_api_client, menu_item, permission_manage_translations):
    menu_item.translations.create(language_code='pl', name='Odnośnik')

    query = """
    mutation menuItemTranslate($menuItemId: ID!) {
        menuItemTranslate(
                id: $menuItemId, languageCode: PL,
                input: {name: "Odnośnik PL"}) {
            menuItem {
                translation(languageCode: PL) {
                    name
                    language {
                        code
                    }
                }
            }
        }
    }
    """

    menu_item_id = graphene.Node.to_global_id('MenuItem', menu_item.id)
    response = staff_api_client.post_graphql(
        query, {'menuItemId': menu_item_id},
        permissions=[permission_manage_translations])
    data = get_graphql_content(response)['data']['menuItemTranslate']

    assert data['menuItem']['translation']['name'] == 'Odnośnik PL'
    assert data['menuItem']['translation']['language']['code'] == 'pl'
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:29,代码来源:test_translations.py

示例15: test_shipping_method_update_translation

def test_shipping_method_update_translation(
        staff_api_client, shipping_method, permission_manage_translations):
    shipping_method.translations.create(language_code='pl', name='DHL')

    query = """
    mutation shippingPriceTranslate($shippingMethodId: ID!) {
        shippingPriceTranslate(
                id: $shippingMethodId, languageCode: PL,
                input: {name: "DHL PL"}) {
            shippingMethod {
                translation(languageCode: PL) {
                    name
                    language {
                        code
                    }
                }
            }
        }
    }
    """

    shipping_method_id = graphene.Node.to_global_id(
        'ShippingMethod', shipping_method.id)
    response = staff_api_client.post_graphql(
        query, {'shippingMethodId': shipping_method_id},
        permissions=[permission_manage_translations])
    data = get_graphql_content(response)['data']['shippingPriceTranslate']

    assert data['shippingMethod']['translation']['name'] == 'DHL PL'
    assert data['shippingMethod']['translation']['language']['code'] == 'pl'
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:30,代码来源:test_translations.py


注:本文中的tests.api.utils.get_graphql_content函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。