예제 #1
0
    def test_all_returns_correct_output_metric_names(self, mock_projects,
                                                     mock_jobs):
        from foundations_core_rest_api_components.lazy_result import LazyResult

        mock_jobs.return_value = LazyResult(lambda: [
            self.MockJob(
                job_id="123",
                job_parameters=[],
                output_metrics=[{
                    "name": "metric_1",
                    "type": "list"
                }],
            )
        ])

        mock_projects.list_projects.return_value = [{"name": "project1"}]

        project = Project.all().evaluate()[0]
        expected_project = Project(name="project1",
                                   created_at=None,
                                   owner=None,
                                   jobs=[
                                       self.MockJob(job_id="123",
                                                    job_parameters=[],
                                                    output_metrics=[])
                                   ],
                                   output_metric_names=[{
                                       "name": "metric_1",
                                       "type": "list"
                                   }],
                                   parameters=[])
        self.assertCountEqual(expected_project.output_metric_names,
                              project.output_metric_names)
예제 #2
0
    def test_all_returns_all_projects_multiple_projects(
            self, mock_projects, mock_jobs):
        from foundations_core_rest_api_components.lazy_result import LazyResult

        mock_jobs.return_value = LazyResult(
            lambda:
            [self.MockJob(job_id="123", job_parameters=[], output_metrics=[])])

        mock_projects.list_projects.return_value = [
            {
                "name": "project1"
            },
            {
                "name": "project2"
            },
        ]

        projects = [project for project in Project.all().evaluate()]

        expected_project = Project(name="project1",
                                   created_at=None,
                                   owner=None,
                                   jobs=[
                                       self.MockJob(job_id="123",
                                                    job_parameters=[],
                                                    output_metrics=[])
                                   ],
                                   output_metric_names=[],
                                   parameters=[])
        expected_project_two = Project(name="project2",
                                       created_at=None,
                                       owner=None,
                                       jobs=[
                                           self.MockJob(job_id="123",
                                                        job_parameters=[],
                                                        output_metrics=[])
                                       ],
                                       output_metric_names=[],
                                       parameters=[])
        self.assertEqual([expected_project, expected_project_two], projects)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
 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)
예제 #6
0
 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")
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 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))
예제 #10
0
    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))
예제 #11
0
 def test_new_project_has_name(self):
     lazy_result = Project.new(name="my first project")
     self.assertEqual("my first project", lazy_result.evaluate().name)
예제 #12
0
 def test_all_returns_all_projects_using_correct_redis(
         self, mock_projects, mock_redis):
     Project.all().evaluate()
     mock_projects.list_projects.assert_called_with(mock_redis)