Exemple #1
0
def test_simple_button_registration(mock_route):
    server.clear_buttons()
    button.simple("this is a button")(do_nothing)
    expected = {"text": "this is a button",
                "type": "button.simple",
                "state": None,
                "id": 0}
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0",
                                       ["POST", "OPTIONS"],
                                       IgnoredArgument())
Exemple #2
0
def test_colorpicker(mock_route):
    server.clear_buttons()
    input_methods.colorpicker("Color Picker", lambda: rgb)(set_color)
    expected = {
        "text": "Color Picker",
        "type": "input.colorpicker",
        "groups": [],
        "state": (10, 20, 30),
        "id": 0
    }
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"],
                                       IgnoredArgument())
Exemple #3
0
def test_leftright_arrows(mock_route):
    server.clear_buttons()
    input_methods.left_right_arrows("Left/Right")(set_input_value)
    expected = {
        "text": "Left/Right",
        "type": "input.leftright",
        "groups": [],
        "state": None,
        "id": 0
    }
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"],
                                       IgnoredArgument())
Exemple #4
0
def test_slider(mock_route):
    server.clear_buttons()
    input_methods.slider("Slider text", lambda: input_value)(set_input_value)
    expected = {
        "text": "Slider text",
        "type": "input.slider",
        "groups": [],
        "state": 0,
        "min": 0,
        "max": 100,
        "id": 0
    }
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0", ["POST", "OPTIONS"],
                                       IgnoredArgument())
Exemple #5
0
def test_toggle_button_registration(mock_route):
    server.clear_buttons()
    button.toggle("Toggle Button", do_nothing)(set_bool)
    expected = {"text": "Toggle Button",
                "type": "button.toggle",
                "state": False,
                "id": 0}

    mock_route.side_effect = mock_call
    assert server.get_buttons_registered() == {"buttons": [expected]}

    global bool_value
    bool_value = True
    expected["state"] = True
    assert server.get_buttons_registered() == {"buttons": [expected]}

    mock_route.assert_called_once_with("/buttons/0",
                                       ["POST", "OPTIONS"],
                                       IgnoredArgument())
Exemple #6
0
def test_toggle_button_registration_with_invalid_args(mock_route):
    server.clear_buttons()
    with pytest.raises(server.InvalidArgumentsException):
        button.toggle("Toggle Button", do_nothing)(do_nothing)
    assert server.get_buttons_registered() == {'buttons': []}
    mock_route.assert_not_called()
Exemple #7
0
def test_multigroup_simple_button_registration(mock_route):
    server.clear_buttons()
    button.simple("Group Button", ["Group A", "Group B"])(do_nothing)
    groups = server.get_buttons_registered()["buttons"][0]["groups"]
    assert groups == ["Group A", "Group B"]
Exemple #8
0
def test_simple_button_registration_fails_when_arguments(mock_route):
    server.clear_buttons()
    with pytest.raises(server.InvalidArgumentsException):
        button.simple("this is a button")(set_bool)
    assert server.get_buttons_registered() == {'buttons': []}
    mock_route.assert_not_called()
Exemple #9
0
def test_toggle_button_registration(mock_route):
    server.clear_buttons()
    button.toggle("Toggle Button", do_nothing, "Group A")(set_bool)
    groups = server.get_buttons_registered()["buttons"][0]["groups"]
    assert groups == ["Group A"]