Skip to content

Commit

Permalink
Raise error if searching with incorrect parameter (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
akim-ruslanov authored May 3, 2024
1 parent 3e2a932 commit b0dff61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pycue/opencue/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 20 additions & 1 deletion pycue/tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'
Expand Down

0 comments on commit b0dff61

Please sign in to comment.