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))
Esempio n. 2
0
 def get(self):
     """
     List and search for projects
     ---
     tags:
         - projects
     produces:
         - application/json
     parameters:
         - in: header
           name: Authorization
           description: Base64 encoded session token
           type: string
           default: Token sessionTokenHere==
         - in: header
           name: Accept-Language
           description: Language user is requesting
           type: string
           required: true
           default: en
         - in: query
           name: mapperLevel
           type: string
         - in: query
           name: orderBy
           type: string
           default: priority
           enum: [id,mapper_level,priority,status,last_updated,due_date]
         - in: query
           name: orderByType
           type: string
           default: ASC
           enum: [ASC, DESC]
         - in: query
           name: mappingTypes
           type: string
         - in: query
           name: mappingTypesExact
           type: boolean
           default: false
           description: if true, limits projects to match the exact mapping types requested
         - in: query
           name: organisationName
           description: Organisation name to search for
           type: string
         - in: query
           name: organisationId
           description: Organisation ID to search for
           type: integer
         - in: query
           name: campaign
           description: Campaign name to search for
           type: string
         - in: query
           name: page
           description: Page of results user requested
           type: integer
           default: 1
         - in: query
           name: textSearch
           description: Text to search
           type: string
         - in: query
           name: country
           description: Project country
           type: string
         - in: query
           name: action
           description: Filter projects by possible actions
           enum: [map, validate, any]
           type: string
         - in: query
           name: projectStatuses
           description: Authenticated PMs can search for archived or draft statuses
           type: string
         - in: query
           name: interests
           type: string
           description: Filter by interest on project
           default: null
         - in: query
           name: createdByMe
           description: Limit to projects created by the authenticated user
           type: boolean
           default: false
         - in: query
           name: mappedByMe
           description: Limit to projects mapped/validated by the authenticated user
           type: boolean
           default: false
         - in: query
           name: favoritedByMe
           description: Limit to projects favorited by the authenticated user
           type: boolean
           default: false
         - in: query
           name: managedByMe
           description:
             Limit to projects that can be managed by the authenticated user,
             excluding the ones created by them
           type: boolean
           default: false
         - in: query
           name: teamId
           type: string
           description: Filter by team on project
           default: null
           name: omitMapResults
           type: boolean
           description: If true, it will not return the project centroid's geometries.
           default: false
     responses:
         200:
             description: Projects found
         404:
             description: No projects found
         500:
             description: Internal Server Error
     """
     try:
         user = None
         user_id = token_auth.current_user()
         if user_id:
             user = UserService.get_user_by_id(user_id)
         search_dto = self.setup_search_dto()
         results_dto = ProjectSearchService.search_projects(search_dto, user)
         return results_dto.to_primitive(), 200
     except NotFound:
         return {"mapResults": {}, "results": []}, 200
     except Exception as e:
         error_msg = f"Project GET - unhandled error: {str(e)}"
         current_app.logger.critical(error_msg)
         return {"Error": "Unable to fetch projects"}, 500