def index(self): from foundations_rest_api.v2beta.models.project import Project from foundations_core_rest_api_components.response import Response from foundations_core_rest_api_components.lazy_result import LazyResult project_name = self.params.pop("project_name") jobs_data_future = Project.find_by(name=project_name).only( ["name", "jobs", "output_metric_names", "parameters"]) jobs_data_future = jobs_data_future.apply_filters(self.params, fields=["jobs"]) fallback = Response("Jobs", LazyResult(lambda: "This project was not found"), status=404) return Response("Jobs", jobs_data_future, fallback=fallback)
def index(self): from foundations_rest_api.v2beta.models.project import Project from foundations_core_rest_api_components.response import Response from foundations_core_rest_api_components.lazy_result import LazyResult project_name = self.params.pop('project_name') jobs_data_future = Project.find_by(name=project_name).only( ['name', 'jobs', 'output_metric_names']) jobs_data_future = jobs_data_future.apply_filters({}, fields=['jobs']) fallback = Response( 'Jobs', LazyResult(lambda: 'This project or sort detail was not found'), status=404) jobs_data_future = self.sort_jobs(jobs_data_future) return Response('Jobs', jobs_data_future, fallback=fallback)
def test_find_returns_none_when_project_does_not_exist(self): self._find_project.return_value = None project = Project.find_by(name="my least favourite project").evaluate() self.assertIsNone(project)
def test_find_looks_for_correct_project_different_project(self): Project.find_by(name="my least favourite project").evaluate() self._find_project.assert_called_with(self._redis, "my least favourite project")
def test_find_by_name_project_has_name_different_name(self): lazy_result = Project.find_by(name="my favourite project") self.assertEqual("my favourite project", lazy_result.evaluate().name)
def test_find_by_name_project_has_name(self): lazy_result = Project.find_by(name="my first project") self.assertEqual("my first project", lazy_result.evaluate().name)
def test_find_by_name_project_is_response_containing_project(self): lazy_result = Project.find_by(name="my first project") self.assertTrue(isinstance(lazy_result.evaluate(), Project))
def test_find_by_name_project_is_response(self): from foundations_core_rest_api_components.lazy_result import LazyResult lazy_result = Project.find_by(name="my first project") self.assertTrue(isinstance(lazy_result, LazyResult))