def get(self): """ Get featured projects --- tags: - projects produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token required: false type: string default: Token sessionTokenHere== responses: 200: description: Featured projects 500: description: Internal Server Error """ try: preferred_locale = request.environ.get("HTTP_ACCEPT_LANGUAGE") projects_dto = ProjectService.get_featured_projects(preferred_locale) return projects_dto.to_primitive(), 200 except Exception as e: error_msg = f"FeaturedProjects GET - unhandled error: {str(e)}" current_app.logger.critical(error_msg) return {"Error": error_msg}, 500
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)