Ejemplo n.º 1
0
    def test_query_time_flags_project_and_groups(self) -> None:
        """
        Tests errors_replacer.set_project_needs_final() and
        errors_replacer.set_project_exclude_groups() work together as expected.

        ReplacementType's are arbitrary, just need to show up in
        getter appropriately once set.
        """
        redis_client.flushdb()
        project_ids = [7, 8, 9]

        errors_replacer.set_project_needs_final(7, ReplacerState.ERRORS,
                                                ReplacementType.EXCLUDE_GROUPS)
        errors_replacer.set_project_exclude_groups(7, [1, 2],
                                                   ReplacerState.ERRORS,
                                                   ReplacementType.START_MERGE)
        flags = ProjectsQueryFlags.load_from_redis(project_ids,
                                                   ReplacerState.ERRORS)
        assert (
            flags.needs_final,
            flags.group_ids_to_exclude,
            flags.replacement_types,
        ) == (
            True,
            {1, 2},
            # exclude_groups from project setter, start_merge from group setter
            {ReplacementType.EXCLUDE_GROUPS, ReplacementType.START_MERGE},
        )
Ejemplo n.º 2
0
def test_without_turbo_with_projects_needing_final(query: ClickhouseQuery) -> None:
    set_project_needs_final(2, ReplacerState.EVENTS)

    PostReplacementConsistencyEnforcer(
        "project_id", ReplacerState.EVENTS
    ).process_query(query, HTTPRequestSettings())

    assert query.get_condition_from_ast() == build_in("project_id", [2])
    assert query.get_from_clause().final
Ejemplo n.º 3
0
    def test_without_turbo_with_projects_needing_final(self):
        request_settings = HTTPRequestSettings()
        set_project_needs_final(2, ReplacerState.EVENTS)

        self.extension.get_processor().process_query(self.query,
                                                     self.valid_data,
                                                     request_settings)

        assert self.query.get_conditions() == [("project_id", "IN", [2])]
        assert self.query.get_condition_from_ast() == build_in(
            "project_id", [2])
        assert self.query.get_final()
Ejemplo n.º 4
0
def test_without_turbo_with_projects_needing_final(
        query: ClickhouseQuery) -> None:
    set_project_needs_final(
        2,
        ReplacerState.ERRORS,
        ReplacementType.
        EXCLUDE_GROUPS,  # Arbitrary replacement type, no impact on tests
    )

    PostReplacementConsistencyEnforcer("project_id",
                                       ReplacerState.ERRORS).process_query(
                                           query, HTTPQuerySettings())

    assert query.get_condition() == build_in("project_id", [2])
    assert query.get_from_clause().final
Ejemplo n.º 5
0
    def test_query_time_flags(self):
        project_ids = [1, 2]

        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.ERRORS
        ) == (False, [],)

        errors_replacer.set_project_needs_final(100, ReplacerState.ERRORS)
        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.ERRORS
        ) == (False, [],)

        errors_replacer.set_project_needs_final(1, ReplacerState.ERRORS)
        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.ERRORS
        ) == (True, [],)
        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.EVENTS
        ) == (False, [],)

        errors_replacer.set_project_needs_final(2, ReplacerState.ERRORS)
        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.ERRORS
        ) == (True, [],)

        errors_replacer.set_project_exclude_groups(1, [1, 2], ReplacerState.ERRORS)
        errors_replacer.set_project_exclude_groups(2, [3, 4], ReplacerState.ERRORS)
        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.ERRORS
        ) == (True, [1, 2, 3, 4],)
        assert errors_replacer.get_projects_query_flags(
            project_ids, ReplacerState.EVENTS
        ) == (False, [],)
Ejemplo n.º 6
0
    def test_query_time_flags_project(self) -> None:
        """
        Tests errors_replacer.set_project_needs_final()

        ReplacementType's are arbitrary, just need to show up in
        getter appropriately once set.
        """
        redis_client.flushdb()
        project_ids = [1, 2, 3]
        assert ProjectsQueryFlags.load_from_redis(
            project_ids, ReplacerState.ERRORS) == ProjectsQueryFlags(
                False, set(), set(), None)

        errors_replacer.set_project_needs_final(100, ReplacerState.ERRORS,
                                                ReplacementType.EXCLUDE_GROUPS)
        assert ProjectsQueryFlags.load_from_redis(
            project_ids, ReplacerState.ERRORS) == ProjectsQueryFlags(
                False, set(), set(), None)

        errors_replacer.set_project_needs_final(1, ReplacerState.ERRORS,
                                                ReplacementType.EXCLUDE_GROUPS)
        flags = ProjectsQueryFlags.load_from_redis(project_ids,
                                                   ReplacerState.ERRORS)
        assert (
            flags.needs_final,
            flags.group_ids_to_exclude,
            flags.replacement_types,
        ) == (
            True,
            set(),
            {ReplacementType.EXCLUDE_GROUPS},
        )

        errors_replacer.set_project_needs_final(2, ReplacerState.ERRORS,
                                                ReplacementType.EXCLUDE_GROUPS)
        flags = ProjectsQueryFlags.load_from_redis(project_ids,
                                                   ReplacerState.ERRORS)
        assert (
            flags.needs_final,
            flags.group_ids_to_exclude,
            flags.replacement_types,
        ) == (
            True,
            set(),
            {ReplacementType.EXCLUDE_GROUPS},
        )