Exemplo n.º 1
0
def test_user_config_move_snapin_before(mocker, move_id, before_id, result):
    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    del user_config.snapins[:]
    user_config.snapins.extend([
        UserSidebarSnapin.from_snapin_type_id("admin"),
        UserSidebarSnapin.from_snapin_type_id("views"),
        UserSidebarSnapin.from_snapin_type_id("tactical_overview"),
    ])

    try:
        move = user_config.get_snapin(move_id)
    except KeyError as e:
        if result is None:
            assert "does not exist" in "%s" % e
            return
        raise

    try:
        before = user_config.get_snapin(
            before_id)  # type: Optional[UserSidebarSnapin]
    except KeyError:
        before = None

    user_config.move_snapin_before(move, before)
    assert user_config.snapins == result
Exemplo n.º 2
0
def test_ajax_openclose_close(module_wide_request_context, mocker,
                              origin_state, set_state):
    html.request.set_var("name", "tactical_overview")
    html.request.set_var("state", set_state)
    m_config = mocker.patch.object(config.user,
                                   "load_file",
                                   return_value={
                                       "fold":
                                       False,
                                       "snapins": [
                                           ("tactical_overview", origin_state),
                                           ("views", "open"),
                                       ],
                                   })
    m_save = mocker.patch.object(config.user, "save_file")

    sidebar.ajax_openclose()

    snapins = [
        UserSidebarSnapin.from_snapin_type_id("views"),
    ]

    if set_state != "off":
        snapins.insert(
            0,
            UserSidebarSnapin.from_config({
                "snapin_type_id": "tactical_overview",
                "visibility": set_state
            }))

    m_config.assert_called_once()
    m_save.assert_called_once_with("sidebar", {
        "fold": False,
        "snapins": [e.to_config() for e in snapins],
    })
Exemplo n.º 3
0
def test_load_default_config(monkeypatch):
    user_config = sidebar.UserSidebarConfig(user, config.sidebar)
    assert user_config.folded is False
    assert user_config.snapins == [
        UserSidebarSnapin.from_snapin_type_id("tactical_overview"),
        UserSidebarSnapin.from_snapin_type_id("bookmarks"),
        UserSidebarSnapin(sidebar.snapin_registry["master_control"],
                          sidebar.SnapinVisibility.CLOSED),
    ]
Exemplo n.º 4
0
def test_load_legacy_list_user_config(monkeypatch):
    monkeypatch.setattr(sidebar.UserSidebarConfig, "_user_config",
                        lambda x: [("tactical_overview", "open"), ("views", "closed")])

    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    assert user_config.folded is False
    assert user_config.snapins == [
        UserSidebarSnapin.from_snapin_type_id('tactical_overview'),
        UserSidebarSnapin(sidebar.snapin_registry["views"], sidebar.SnapinVisibility.CLOSED),
    ]
Exemplo n.º 5
0
def test_user_config_get_snapin():
    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    del user_config.snapins[:]
    snapin = UserSidebarSnapin.from_snapin_type_id("tactical_overview")
    user_config.add_snapin(snapin)

    assert user_config.get_snapin("tactical_overview") == snapin
Exemplo n.º 6
0
def test_load_user_config(monkeypatch):
    monkeypatch.setattr(
        sidebar.UserSidebarConfig, "_user_config", lambda x: {
            "fold": True,
            "snapins": [
                ("search", "closed"),
                ("views", "open"),
            ]
        })

    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    assert user_config.folded is True
    assert user_config.snapins == [
        UserSidebarSnapin(sidebar.snapin_registry["search"], sidebar.SnapinVisibility.CLOSED),
        UserSidebarSnapin.from_snapin_type_id('views'),
    ]
Exemplo n.º 7
0
def test_load_legacy_off_user_config(monkeypatch):
    monkeypatch.setattr(sidebar.UserSidebarConfig, "_user_config", lambda x: [("search", "off"),
                                                                              ("views", "closed")])

    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    assert user_config.folded is False
    assert user_config.snapins == [
        UserSidebarSnapin(sidebar.snapin_registry["views"], sidebar.SnapinVisibility.CLOSED),
    ]
Exemplo n.º 8
0
def test_load_skip_not_existing(monkeypatch):
    monkeypatch.setattr(
        sidebar.UserSidebarConfig, "_user_config", lambda x: {
            "fold": False,
            "snapins": [("bla", "closed"), ("views", "closed")]
        })

    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    assert user_config.folded is False
    assert user_config.snapins == [
        UserSidebarSnapin(sidebar.snapin_registry["views"], sidebar.SnapinVisibility.CLOSED),
    ]
Exemplo n.º 9
0
def test_load_skip_not_permitted(monkeypatch, register_builtin_html):
    monkeypatch.setattr(
        sidebar.UserSidebarConfig, "_user_config", lambda x: {
            "fold": False,
            "snapins": [("tactical_overview", "closed"), ("views", "closed")]
        })
    monkeypatch.setattr(config.user, "may", lambda x: x != "sidesnap.tactical_overview")

    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    assert user_config.folded is False
    assert user_config.snapins == [
        UserSidebarSnapin(sidebar.snapin_registry["views"], sidebar.SnapinVisibility.CLOSED),
    ]
Exemplo n.º 10
0
def test_load_default_config(monkeypatch):
    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    assert user_config.folded is False
    assert user_config.snapins == [
        UserSidebarSnapin.from_snapin_type_id('tactical_overview'),
        UserSidebarSnapin.from_snapin_type_id('search'),
        UserSidebarSnapin.from_snapin_type_id('views'),
        UserSidebarSnapin(sidebar.snapin_registry["reports"],
                          sidebar.SnapinVisibility.CLOSED),
        UserSidebarSnapin.from_snapin_type_id('bookmarks'),
        UserSidebarSnapin.from_snapin_type_id('admin'),
        UserSidebarSnapin(sidebar.snapin_registry["master_control"],
                          sidebar.SnapinVisibility.CLOSED),
    ]
Exemplo n.º 11
0
def test_user_config_get_not_existing_snapin():
    user_config = sidebar.UserSidebarConfig(config.user, config.sidebar)
    del user_config.snapins[:]

    with pytest.raises(KeyError) as e:
        user_config.get_snapin("tactical_overview")
    msg = "%s" % e
    assert "does not exist" in msg


@pytest.mark.parametrize(
    "move_id,before_id,result",
    [
        ("tactical_overview", "views", [
            UserSidebarSnapin.from_snapin_type_id("admin"),
            UserSidebarSnapin.from_snapin_type_id("tactical_overview"),
            UserSidebarSnapin.from_snapin_type_id("views"),
        ]),
        ("tactical_overview", "admin", [
            UserSidebarSnapin.from_snapin_type_id("tactical_overview"),
            UserSidebarSnapin.from_snapin_type_id("admin"),
            UserSidebarSnapin.from_snapin_type_id("views"),
        ]),
        ("not_existing", "admin", None),
        # TODO: Shouldn't this also be handled?
        #("admin",  "not_existing", [
        #    ("admin", "open"),
        #    ("views", "open"),
        #    ("tactical_overview", "open"),
        #]),
Exemplo n.º 12
0
def test_user_config_add_snapin():
    user_config = sidebar.UserSidebarConfig(user, active_config.sidebar)
    del user_config.snapins[:]
    snapin = UserSidebarSnapin.from_snapin_type_id("tactical_overview")
    user_config.add_snapin(snapin)
    assert user_config.snapins == [snapin]