def test_channel_query(client):
    client.channels.create(
        types.ChannelDraft(key="test-channel1",
                           roles=[types.ChannelRoleEnum.INVENTORY_SUPPLY]))
    client.channels.create(
        types.ChannelDraft(key="test-channel2",
                           roles=[types.ChannelRoleEnum.INVENTORY_SUPPLY]))

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

    # multiple sort queries
    result = client.channels.query(sort=["id asc", "name asc"])
    assert len(result.results) == 2
    assert result.total == 2
Exemplo n.º 2
0
def test_store_channel_create(commercetools_api, client, store_draft):
    channel = client.channels.create(
        types.ChannelDraft(
            key="FOO", roles=[types.ChannelRoleEnum.PRODUCT_DISTRIBUTION]
        )
    )
    store_draft.distribution_channels = [types.ChannelResourceIdentifier(key="FOO")]

    store = client.stores.create(store_draft)

    assert store.distribution_channels[0].id == channel.id
def test_channel_get_by_id(client):
    channel = client.channels.create(
        types.ChannelDraft(key="test-channel",
                           roles=[types.ChannelRoleEnum.INVENTORY_SUPPLY]))

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

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

    with pytest.raises(HTTPError):
        client.channels.get_by_id("invalid")
Exemplo n.º 4
0
def test_channel_errors(commercetools_api, client, store_draft):
    store = client.stores.create(store_draft)

    client.channels.create(
        types.ChannelDraft(key="BAR", roles=[types.ChannelRoleEnum.INVENTORY_SUPPLY])
    )

    with pytest.raises(CommercetoolsError):
        client.stores.update_by_id(
            store.id,
            store.version,
            actions=[
                types.StoresSetDistributionChannelsAction(
                    distribution_channels=[types.ChannelResourceIdentifier(key="BAR")]
                )
            ],
        )
Exemplo n.º 5
0
def test_channels_are_set(commercetools_api, client, store_draft):
    store = client.stores.create(store_draft)

    assert store.distribution_channels == []

    channel = client.channels.create(
        types.ChannelDraft(
            key="FOO", roles=[types.ChannelRoleEnum.PRODUCT_DISTRIBUTION]
        )
    )

    store = client.stores.update_by_id(
        store.id,
        store.version,
        actions=[
            types.StoresSetDistributionChannelsAction(
                distribution_channels=[types.ChannelResourceIdentifier(key="FOO")]
            )
        ],
    )

    assert store.distribution_channels[0].id == channel.id
def test_channel_update(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 = client.channels.create(
        types.ChannelDraft(
            key="test-channel",
            name=types.LocalizedString(nl="nl-channel"),
            roles=[types.ChannelRoleEnum.INVENTORY_SUPPLY],
        ))
    assert channel.key == "test-channel"

    channel = client.channels.update_by_id(
        id=channel.id,
        version=channel.version,
        actions=[
            types.ChannelChangeNameAction(name=types.LocalizedString(
                nl="nl-channel2"))
        ],
    )
Exemplo n.º 7
0
 def post_load(self, data, **kwargs):
     return types.ChannelDraft(**data)