Ejemplo n.º 1
0
def messagesummary_fixtures(request):
    """
    Fixture for messagesummary tests.

    :return: view for messagesummary.
    :rtype: prewikka.view.View
    """
    backup_parameters = deepcopy(env.request.parameters)

    view = load_view_for_fixtures(request.param)
    view.process_parameters()

    heartbeat = create_heartbeat(_heartbeat_id)
    env.dataprovider._backends["heartbeat"]._db.insert(heartbeat)

    alert = create_alert(_alert_id)
    env.dataprovider._backends["alert"]._db.insert(alert)

    correlation_alert = create_correlation_alert(_correlation_alert_id,
                                                 'correlation_alert_1',
                                                 _alert_id)
    env.dataprovider._backends["alert"]._db.insert(correlation_alert)

    def tear_down():
        """
        TearDown
        """
        env.request.parameters = backup_parameters
        env.dataprovider._backends["alert"]._db.remove('alert.messageid')

    request.addfinalizer(tear_down)

    return view
Ejemplo n.º 2
0
def datasearch_fixtures(request):
    """
    Fixture for datasearch tests.

    :return: view for alerts.
    :rtype: prewikka.view.View
    """
    backup_parameters = deepcopy(env.request.parameters)

    view = load_view_for_fixtures(request.param)
    view.process_parameters()

    alert_id = '79e0ce14-46b6-11e7-9ab4'
    correlation_alert = create_correlation_alert(alert_id,
                                                 'correlation_alert_1')
    env.dataprovider._backends["alert"]._db.insert(correlation_alert)

    def tear_down():
        """
        TearDown
        """
        env.request.parameters = backup_parameters
        env.dataprovider._backends["alert"]._db.remove('alert.messageid')

    request.addfinalizer(tear_down)

    return view
Ejemplo n.º 3
0
def test_mainmenu_parameters():
    """
    Test `prewikka.view.GeneralParameters` class.
    """
    view = load_view_for_fixtures('BaseView.render')
    mainmenu = GeneralParameters(view, {})
    mainmenu.register()
    mainmenu.normalize()
Ejemplo n.º 4
0
def test_save():
    """
    Test `prewikka.views.usermanagement.save` view.
    """
    view = load_view_for_fixtures("usersettings.save")
    backup_parameters = deepcopy(env.request.parameters)

    # valid
    params = {
        'language': next(iter(localization.get_languages().keys())),
        'timezone': localization.get_timezones()[0],
    }
    env.request.parameters = params

    view.render(name=env.request.user.name)

    # FIXME
    # valid with new email
    # params_email = deepcopy(params)
    # params_email['email'] = '*****@*****.**'
    # env.request.parameters = params_email

    # view.render()

    # valid with new theme (reload page)
    params_email = deepcopy(params)
    params_email['theme'] = 'dark'
    env.request.parameters = params_email

    view.render(name=env.request.user.name)

    # FIXME
    # valid with different user
    # params_user = deepcopy(params)
    # params_user['name'] = 'test_different'
    # env.request.parameters = params_user

    # view.modify()

    # invalid language
    with pytest.raises(PrewikkaUserError):
        params_invalid = deepcopy(params)
        params_invalid['language'] = None
        env.request.parameters = params_invalid

        view.render(name=env.request.user.name)

    # invalid timezone
    with pytest.raises(PrewikkaUserError):
        params_invalid = deepcopy(params)
        params_invalid['timezone'] = None
        env.request.parameters = params_invalid

        view.render(name=env.request.user.name)

    # clean
    env.request.parameters = backup_parameters
Ejemplo n.º 5
0
def filter_fixtures(request):
    """
    Fixture for filter tests.

    :return: view for filter.
    :rtype: prewikka.view.View
    """
    from prewikka.plugins.filter.filter import FilterDatabase, Filter  # prevent import error

    view = load_view_for_fixtures(request.param)
    view.process_parameters()

    database = FilterDatabase()

    criterion_1 = Criterion('alert.messageid', '=', 'fakemessageid1')
    criteria_1 = {'alert': criterion_1}
    filter_obj_1 = Filter(None, 'Test filter 1', 'Filter category',
                          'Filter description', criteria_1)
    database.upsert_filter(env.request.user, filter_obj_1)

    criterion_2 = Criterion('heartbeat.messageid', '=', 'fakemessageid1')
    criteria_2 = {'heartbeat': criterion_2}
    filter_obj_2 = Filter(None, 'Test filter 2', 'Filter category',
                          'Filter description', criteria_2)
    database.upsert_filter(env.request.user, filter_obj_2)

    criterion_3 = Criterion(criterion_1, '||', criterion_2)
    criteria_3 = {'alert': criterion_3}
    filter_obj_3 = Filter(None, 'Test filter 3', 'Filter category',
                          'Filter description', criteria_3)
    database.upsert_filter(env.request.user, filter_obj_3)

    # complex criterion
    criterion_4 = Criterion(criterion_3, '||', criterion_2)
    criteria_4 = {'alert': criterion_4}
    filter_obj_4 = Filter(None, 'Test filter 4', 'Filter category',
                          'Filter description', criteria_4)
    database.upsert_filter(env.request.user, filter_obj_4)

    def tear_down():
        """
        TearDown
        """
        env.db.query('DELETE FROM Prewikka_Filter')

    request.addfinalizer(tear_down)

    return {
        'view': view,
        'database': database,
        'filter_obj_1': filter_obj_1,
        'filter_obj_2': filter_obj_2,
        'filter_obj_3': filter_obj_3,
        'filter_obj_4': filter_obj_4,
        'last_insert_id': env.db.get_last_insert_ident(),
        'criterion_list': [criterion_1, criterion_2, criterion_3, criterion_4]
    }
Ejemplo n.º 6
0
def baseview_fixtures(request):
    """
    Fixtures for tests of `prewikka.baseview`.
    """
    # view
    load_view_for_fixtures('BaseView.render')

    # dataset
    backup_dataset = copy(env.request.dataset)
    dataset = {'document': AttrObj()}
    env.request.dataset = dataset

    def tear_down():
        """
        TearDown
        """
        env.request.dataset = backup_dataset

    request.addfinalizer(tear_down)
Ejemplo n.º 7
0
def mainmenu_fixtures(request):
    """
    Fixture for `prewikka.mainmenu` test.
    """
    backup_parameters = env.request.parameters

    view = load_view_for_fixtures('BaseView.render')

    env.request.parameters['orderby'] = None
    env.request.parameters['timeline_mode'] = 'relative'
    env.request.parameters['timeline_value'] = 12
    env.request.parameters['timeline_unit'] = 'day'
    env.request.parameters['auto_apply_value'] = None

    def tear_down():
        """
        TearDown.
        """
        env.request.parameters = backup_parameters

    request.addfinalizer(tear_down)

    return {'view': view}
Ejemplo n.º 8
0
def test_my_account():
    """
    Test `prewikka.views.usermanagement.my_account` view.
    """
    view = load_view_for_fixtures("usersettings.my_account")
    view.render()