Ejemplo n.º 1
0
    def post(self, project_id):
        """
        Unset a project as featured
        ---
        tags:
            - projects
        produces:
            - application/json
        parameters:
            - in: header
              name: Authorization
              description: Base64 encoded session token
              required: true
              type: string
              default: Token sessionTokenHere==
            - name: project_id
              in: path
              description: Unique project ID
              required: true
              type: integer
              default: 1
        responses:
            200:
                description: Project Unfeatured
            400:
                description: Bad request
            403:
                description: Forbidden
            404:
                description: Project not found
            500:
                description: Internal Server Error
        """
        try:
            ProjectAdminService.is_user_action_permitted_on_project(
                token_auth.current_user(), project_id)
        except ValueError as e:
            error_msg = f"FeaturedProjects POST: {str(e)}"
            return {"Error": error_msg}, 403

        try:
            ProjectService.unset_project_as_featured(project_id)
            return {"Success": True}, 200
        except NotFound:
            return {"Error": "Project Not Found"}, 404
        except ValueError as e:
            error_msg = f"FeaturedProjects DELETE: {str(e)}"
            return {"Error": error_msg}, 400
        except Exception as e:
            error_msg = f"FeaturedProjects DELETE - unhandled error: {str(e)}"
            current_app.logger.critical(error_msg)
            return {"Error": error_msg}, 500
Ejemplo n.º 2
0
    def test_featured_projects_service(self):
        self.test_project, self.test_user = create_canned_project()

        # Featured a not created project.
        with self.assertRaises(NotFound):
            ProjectService.set_project_as_featured(project_id=100)

        # Feature an already created project.
        ProjectService.set_project_as_featured(project_id=self.test_project.id)

        # List all featured projects.
        featured_projects = ProjectService.get_featured_projects(None)
        self.assertEqual(len(featured_projects.results), 1)

        # Unfeature project.
        ProjectService.unset_project_as_featured(
            project_id=self.test_project.id)
        # List all featured projects.
        featured_projects = ProjectService.get_featured_projects(None)
        self.assertEqual(len(featured_projects.results), 0)