def test_project_search(self):

        user = User(id=3488526)
        search_dto = ProjectSearchDTO()
        search_dto.preferred_locale = None
        search_dto.mapper_level = "BEGINNER"
        search_dto.mapping_types = None
        search_dto.project_statuses = ["PUBLISHED"]
        search_dto.organisation_name = None
        search_dto.organisation_id = 34
        search_dto.team_id = 1
        search_dto.campaign = "DengueFeverHonduras"
        search_dto.order_by = "priority"
        search_dto.order_by_type = "DESC"
        search_dto.country = "Honduras"
        search_dto.page = 1
        search_dto.text_search = "6158"
        search_dto.mapping_editors = ["ID"]
        search_dto.validation_editors = ["ID"]
        search_dto.teams = None
        search_dto.interests = None
        search_dto.created_by = 378610
        search_dto.mapped_by = None
        search_dto.favorited_by = None
        search_dto.managed_by = None
        search_dto.omit_map_results = False

        search_dto.validate()

        self.assertIsNotNone(
            ProjectSearchService.search_projects(search_dto, user))
Ejemplo n.º 2
0
    def setup_search_dto(self) -> ProjectSearchDTO:
        search_dto = ProjectSearchDTO()
        search_dto.preferred_locale = request.environ.get("HTTP_ACCEPT_LANGUAGE")
        search_dto.mapper_level = request.args.get("mapperLevel")
        search_dto.action = request.args.get("action")
        search_dto.organisation_name = request.args.get("organisationName")
        search_dto.organisation_id = request.args.get("organisationId")
        search_dto.team_id = request.args.get("teamId")
        search_dto.campaign = request.args.get("campaign")
        search_dto.order_by = request.args.get("orderBy", "priority")
        search_dto.country = request.args.get("country")
        search_dto.order_by_type = request.args.get("orderByType", "ASC")
        search_dto.page = (
            int(request.args.get("page")) if request.args.get("page") else 1
        )
        search_dto.text_search = request.args.get("textSearch")
        search_dto.omit_map_results = strtobool(
            request.args.get("omitMapResults", "false")
        )
        search_dto.last_updated_gte = request.args.get("lastUpdatedFrom")
        search_dto.last_updated_lte = request.args.get("lastUpdatedTo")
        search_dto.created_gte = request.args.get("createdFrom")
        search_dto.created_lte = request.args.get("createdTo")

        # See https://github.com/hotosm/tasking-manager/pull/922 for more info
        try:
            authenticated_user_id = token_auth.current_user()
            if request.args.get("createdByMe") == "true":
                search_dto.created_by = authenticated_user_id

            if request.args.get("mappedByMe") == "true":
                search_dto.mapped_by = authenticated_user_id

            if request.args.get("favoritedByMe") == "true":
                search_dto.favorited_by = authenticated_user_id

            if request.args.get("managedByMe") == "true":
                search_dto.managed_by = authenticated_user_id

        except Exception:
            pass

        mapping_types_str = request.args.get("mappingTypes")
        if mapping_types_str:
            search_dto.mapping_types = map(
                str, mapping_types_str.split(",")
            )  # Extract list from string
        search_dto.mapping_types_exact = strtobool(
            request.args.get("mappingTypesExact", "false")
        )
        project_statuses_str = request.args.get("projectStatuses")
        if project_statuses_str:
            search_dto.project_statuses = map(str, project_statuses_str.split(","))
        interests_str = request.args.get("interests")
        if interests_str:
            search_dto.interests = map(int, interests_str.split(","))
        search_dto.validate()

        return search_dto
Ejemplo n.º 3
0
    def setup_search_dto(self):
        search_dto = ProjectSearchDTO()
        search_dto.preferred_locale = request.environ.get(
            "HTTP_ACCEPT_LANGUAGE")
        search_dto.mapper_level = request.args.get("mapperLevel")
        search_dto.organisation_name = request.args.get("organisationName")
        search_dto.organisation_id = request.args.get("organisationId")
        search_dto.team_id = request.args.get("teamId")
        search_dto.campaign = request.args.get("campaign")
        search_dto.order_by = request.args.get("orderBy", "priority")
        search_dto.country = request.args.get("country")
        search_dto.order_by_type = request.args.get("orderByType", "ASC")
        search_dto.page = (int(request.args.get("page"))
                           if request.args.get("page") else 1)
        search_dto.text_search = request.args.get("textSearch")

        # See https://github.com/hotosm/tasking-manager/pull/922 for more info
        try:
            verify_token(
                request.environ.get("HTTP_AUTHORIZATION").split(None, 1)[1])

            if request.args.get("createdByMe") == "true":
                search_dto.created_by = tm.authenticated_user_id

            if request.args.get("mappedByMe") == "true":
                search_dto.mapped_by = tm.authenticated_user_id

            if request.args.get("favoritedByMe") == "true":
                search_dto.favorited_by = tm.authenticated_user_id

            if request.args.get("managedByMe") == "true":
                search_dto.managed_by = tm.authenticated_user_id

        except Exception:
            pass

        mapping_types_str = request.args.get("mappingTypes")
        if mapping_types_str:
            search_dto.mapping_types = map(
                str, mapping_types_str.split(","))  # Extract list from string
        project_statuses_str = request.args.get("projectStatuses")
        if project_statuses_str:
            search_dto.project_statuses = map(str,
                                              project_statuses_str.split(","))
        interests_str = request.args.get("interests")
        if interests_str:
            search_dto.interests = map(int, interests_str.split(","))
        search_dto.validate()

        return search_dto