예제 #1
0
def test_default_item(item_value):
    with pytest.raises(exceptions.InvalidProtocolError):
        DataItem()
    with pytest.raises(exceptions.InvalidProtocolError):
        DataItem(key="a key")
    with pytest.raises(exceptions.InvalidProtocolError):
        DataItem(value="a value")
    item = DataItem(key="one key", value=item_value)
    assert item.key == "one key"
    assert item.value == item_value
예제 #2
0
async def test_item(loop):
    key = "my key"
    label = "my label"
    description = "my description"
    item_type = "boolean"
    item_value = True
    display_order = 2

    item = Item(
        SchemaItem(
            key=key,
            label=label,
            description=description,
            type=item_type,
            displayOrder=display_order,
        ),
        DataItem(key=key, value=item_value),
    )

    assert item.key == key
    assert item.label == label
    assert item.description == description
    assert item.type == item_type
    assert item.value == item_value

    assert item.new_data_cb is None

    assert await item.get() == item_value
예제 #3
0
def create_item(item_type, item_value):
    key = "some key"
    return Item(
        SchemaItem(key=key,
                   label="a label",
                   description="a description",
                   type=item_type,
                   displayOrder=2), DataItem(key=key, value=item_value))
예제 #4
0
async def test_set_new_value(item_type, item_value_to_set, expected_value,
                             mocker):  # pylint: disable=W0613
    mock_method = mocker.Mock(return_value=future_with_result(""))
    item = create_item(item_type, None)
    item.new_data_cb = mock_method
    assert await item.get() is None
    await item.set(item_value_to_set)
    mock_method.assert_called_with(DataItem(key=item.key,
                                            value=expected_value))
def create_items_list(key_item_value_tuples):
    schemas = SchemaItemsList({
        key: SchemaItem(
            key=key,
            label="a label",
            description="a description",
            type=item_type,
            displayOrder=2,
        )
        for (key, item_type, _) in key_item_value_tuples
    })
    payloads = DataItemsList({
        key: DataItem(key=key, value=item_value)
        for key, _, item_value in key_item_value_tuples
    })
    return ItemsList(schemas, payloads)
async def test_set_new_value(
    user_id: int,
    project_id: str,
    node_uuid: str,
    item_type: str,
    item_value_to_set: ItemConcreteValue,
    expected_value: ItemConcreteValue,
    mocker,
):
    mock_method = mocker.AsyncMock(return_value="")
    item = create_item(user_id, project_id, node_uuid, item_type, None)
    item.new_data_cb = mock_method
    assert await item.get() is None
    await item.set(
        value=item_value_to_set,
    )
    mock_method.assert_called_with(DataItem(key=item.key, value=expected_value))
def create_item(
    user_id: int,
    project_id: str,
    node_uuid: str,
    item_type: str,
    item_value: DataItemValue,
) -> Item:
    key = "some key"
    return Item(
        user_id,
        project_id,
        node_uuid,
        SchemaItem(
            key=key,
            label="a label",
            description="a description",
            type=item_type,
            displayOrder=2,
        ),
        DataItem(key=key, value=item_value),
    )