From 837be6ab86ffae662f01864485184e5b79a8df53 Mon Sep 17 00:00:00 2001 From: Akim Ruslanov Date: Fri, 3 May 2024 14:01:04 -0700 Subject: [PATCH] Raise error if searching with incorrect parameter (#1165) --- pycue/opencue/search.py | 4 ++++ pycue/tests/api_test.py | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pycue/opencue/search.py b/pycue/opencue/search.py index 1a42f696a..80ad0fa5e 100644 --- a/pycue/opencue/search.py +++ b/pycue/opencue/search.py @@ -381,4 +381,8 @@ def _setOptions(criteria, options): criteria.first_result = int(v) elif k == "include_finished": criteria.include_finished = v + elif len(k) == 0: + return criteria + else: + raise Exception("Criteria for search does not exist") return criteria diff --git a/pycue/tests/api_test.py b/pycue/tests/api_test.py index 759c09da1..b75fcec3f 100644 --- a/pycue/tests/api_test.py +++ b/pycue/tests/api_test.py @@ -189,7 +189,7 @@ def testGetJobs(self, getStubMock): jobs=job_pb2.JobSeq(jobs=[job_pb2.Job(name=TEST_JOB_NAME)])) getStubMock.return_value = stubMock - jobsByShow = opencue.api.getJobs(show=[TEST_SHOW_NAME], all=True) + jobsByShow = opencue.api.getJobs(show=[TEST_SHOW_NAME]) stubMock.GetJobs.assert_called_with( job_pb2.JobGetJobsRequest( @@ -206,6 +206,25 @@ def testGetJobs(self, getStubMock): self.assertEqual(1, len(jobsByName)) self.assertEqual(TEST_JOB_NAME, jobsByName[0].name()) + @mock.patch('opencue.cuebot.Cuebot.getStub') + def testGetAllJobs(self, getStubMock): + stubMock = mock.Mock() + stubMock.GetJobs.return_value = job_pb2.JobGetJobsResponse( + jobs=job_pb2.JobSeq(jobs=[job_pb2.Job(name=TEST_JOB_NAME)])) + getStubMock.return_value = stubMock + + jobs = opencue.api.getJobs() + + stubMock.GetJobs.assert_called_with( + job_pb2.JobGetJobsRequest( + r=job_pb2.JobSearchCriteria()), timeout=mock.ANY) + self.assertEqual(1, len(jobs)) + self.assertEqual(TEST_JOB_NAME, jobs[0].name()) + + def testRaiseExceptionOnBadCriteriaSearch(self): + with self.assertRaises(Exception) as context: + opencue.api.getJobs(bad_criteria=["00000000-0000-0000-0000-012345678980"]) + @mock.patch('opencue.cuebot.Cuebot.getStub') def testGetJob(self, getStubMock): arbitraryId = '00000000-0000-0000-0000-012345678980'