Example #1
0
def test_configure_get(client, app):
    response = client.get('/configuration')

    set_playlists = "playlists = " + json.dumps(all_playlist_titles)
    assert set_playlists.encode() in response.data
    set_zones = "zones = " + json.dumps(all_zones_names)
    assert set_zones.encode() in response.data

    with app.app_context():
        button_accessor = ButtonAccessor()
        # noinspection PyPep8Naming
        set_buttonsByZone = "buttonsByZone = " + json.dumps(button_accessor.get_all_buttons_by_zone())
        assert set_buttonsByZone.encode() in response.data
        # noinspection PyPep8Naming
        set_lastModifiedZone = "lastModifiedZone = " + json.dumps(button_accessor.last_modified_button().zone)
        assert set_lastModifiedZone.encode() in response.data
Example #2
0
def configure():
    button_accessor = ButtonAccessor()
    if request.method == 'POST':
        updated = 0
        zone = request.form['zone']
        buttons = button_accessor.get_buttons_for_zone(zone)
        for button in buttons:
            button_id_form_name = "button_id_{}".format(button.id)
            if button_id_form_name in request.form:
                action = request.form[button_id_form_name]
                updated += button_accessor.update_action(button, action)
            else:
                flash("missing action for button id {}".format(button.id))

        new_buttons = []
        for key in request.form.keys():
            if key.startswith("new_"):
                button_index = key[len("new_"):]
                if not button_index.isdigit():
                    flash("button index must be a number {}".format(key))
                else:
                    new_buttons.append((int(button_index), request.form[key]))

        new_buttons.sort()
        for new_button_num, action in new_buttons:
            button_accessor.new(zone, new_button_num, action)
        flash("updated action for {} buttons. created {} new buttons".format(updated, len(new_buttons)))

    buttons_by_zone = button_accessor.get_all_buttons_by_zone()
    #
    sonoser = SonosAccessor()
    playlist_titles = [p.title for p in sonoser.playlists]
    playlist_titles.sort()
    zone_names = [z.player_name for z in sonoser.zones]
    zone_names.sort()

    last_modified_button = button_accessor.last_modified_button()
    last_modified_zone = last_modified_button.zone if last_modified_button else zone_names[0]

    return render_template(
        'button/configure.html',
        buttons_by_zone=buttons_by_zone,
        playlists=playlist_titles,
        zones=zone_names,
        selected_zone=last_modified_zone
    )
def test_last_modified_button(app):
    with app.app_context():
        button_accessor = ButtonAccessor()
        button = button_accessor.last_modified_button()
        assert_button_properties(button, 'four_zone_4', zone_4, 4)