Exemplo n.º 1
0
def test_channel_query(old_client):
    old_client.channels.create(
        models.ChannelDraft(
            key="test-channel1", roles=[models.ChannelRoleEnum.INVENTORY_SUPPLY]
        )
    )
    old_client.channels.create(
        models.ChannelDraft(
            key="test-channel2", roles=[models.ChannelRoleEnum.INVENTORY_SUPPLY]
        )
    )

    # single sort query
    result = old_client.channels.query(sort="id asc")
    assert len(result.results) == 2
    assert result.total == 2

    # multiple sort queries
    result = old_client.channels.query(sort=["id asc", "name asc"])
    assert len(result.results) == 2
    assert result.total == 2
def test_store_channel_create(commercetools_api,
                              ct_platform_client: PlatformClient, store_draft):
    channel = (ct_platform_client.with_project_key("foo").channels().post(
        models.ChannelDraft(
            key="FOO", roles=[models.ChannelRoleEnum.PRODUCT_DISTRIBUTION])))
    store_draft.distribution_channels = [
        models.ChannelResourceIdentifier(key="FOO")
    ]

    store = ct_platform_client.with_project_key("foo").stores().post(
        store_draft)

    assert store.distribution_channels[0].id == channel.id
Exemplo n.º 3
0
def test_channel_get_by_id(old_client):
    channel = old_client.channels.create(
        models.ChannelDraft(
            key="test-channel", roles=[models.ChannelRoleEnum.INVENTORY_SUPPLY]
        )
    )

    assert channel.id
    assert channel.key == "test-channel"

    channel = old_client.channels.get_by_id(channel.id)
    assert channel.id
    assert channel.key == "test-channel"

    with pytest.raises(HTTPError):
        old_client.channels.get_by_id("invalid")
def test_raises_exception(ct_platform_client: PlatformClient):
    channel = (ct_platform_client.with_project_key("foo").channels().post(
        models.ChannelDraft(key="test-channel2",
                            roles=[models.ChannelRoleEnum.INVENTORY_SUPPLY])))

    result = (ct_platform_client.with_project_key("foo").channels().with_id(
        channel.id).post(
            models.ChannelUpdate(
                version=4,
                actions=[
                    models.ChannelSetRolesAction(
                        roles=[models.ChannelRoleEnum.PRIMARY])
                ],
            ),
            options={"force_version": True},
        ))

    result = (ct_platform_client.with_project_key("foo").channels().with_id(
        channel.id).delete(version=1, options={"force_version": True}))
def test_channel_errors(commercetools_api, ct_platform_client: PlatformClient,
                        store_draft):
    store = ct_platform_client.with_project_key("foo").stores().post(
        store_draft)

    ct_platform_client.with_project_key("foo").channels().post(
        models.ChannelDraft(key="BAR",
                            roles=[models.ChannelRoleEnum.INVENTORY_SUPPLY]))

    with pytest.raises(CommercetoolsError):
        (ct_platform_client.with_project_key("foo").stores().with_id(
            store.id).post(
                models.StoreUpdate(
                    version=store.version,
                    actions=[
                        models.StoreSetDistributionChannelsAction(
                            distribution_channels=[
                                models.ChannelResourceIdentifier(key="BAR")
                            ])
                    ],
                )))
Exemplo n.º 6
0
def test_channel_update(old_client):
    """Test the return value of the update methods.

    It doesn't test the actual update itself.
    TODO: See if this is worth testing since we're using a mocking backend
    """
    channel = old_client.channels.create(
        models.ChannelDraft(
            key="test-channel",
            name=models.LocalizedString(nl="nl-channel"),
            roles=[models.ChannelRoleEnum.INVENTORY_SUPPLY],
        )
    )
    assert channel.key == "test-channel"

    channel = old_client.channels.update_by_id(
        id=channel.id,
        version=channel.version,
        actions=[
            models.ChannelChangeNameAction(
                name=models.LocalizedString(nl="nl-channel2")
            )
        ],
    )
def test_channels_are_set(commercetools_api,
                          ct_platform_client: PlatformClient, store_draft):
    store = ct_platform_client.with_project_key("foo").stores().post(
        store_draft)

    assert store.distribution_channels == []

    channel = (ct_platform_client.with_project_key("foo").channels().post(
        models.ChannelDraft(
            key="FOO", roles=[models.ChannelRoleEnum.PRODUCT_DISTRIBUTION])))

    store = (ct_platform_client.with_project_key("foo").stores().with_id(
        store.id, ).post(
            models.StoreUpdate(
                version=store.version,
                actions=[
                    models.StoreSetDistributionChannelsAction(
                        distribution_channels=[
                            models.ChannelResourceIdentifier(key="FOO")
                        ])
                ],
            )))

    assert store.distribution_channels[0].id == channel.id