Skip to content

Commit

Permalink
Merge pull request #10 from Aratz/DEVELOP-644_include_service_version
Browse files Browse the repository at this point in the history
Include service version in response
  • Loading branch information
Aratz authored Mar 13, 2024
2 parents 253bf19 + 92335a2 commit 50fff79
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
17 changes: 12 additions & 5 deletions sequencing_report_service/handlers/job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from sequencing_report_service.handlers import ACCEPTED, NOT_FOUND, FORBIDDEN
from sequencing_report_service.exceptions import UnableToStopJob, RunfolderNotFound
from sequencing_report_service import __version__ as version


class OneJobHandler(BaseRestHandler):
Expand Down Expand Up @@ -43,6 +44,7 @@ def get(self, job_id):
job = self.runner_service.get_job(job_id)
if job:
job_as_dicts = job.to_dict()
job_as_dicts["version"] = version
self.write_object(job_as_dicts)
else:
raise HTTPError(NOT_FOUND)
Expand Down Expand Up @@ -91,7 +93,7 @@ def get(self):
"""
jobs = self.runner_service.get_jobs()
jobs_as_dicts = list(map(lambda job: job.to_dict(), jobs))
self.write_object({"jobs": jobs_as_dicts})
self.write_object({"jobs": jobs_as_dicts, "version": version})


class JobStartHandler(BaseRestHandler):
Expand Down Expand Up @@ -135,7 +137,8 @@ def post(self, pipeline, runfolder):
"link":
f"{self.request.protocol}://"
f"{self.request.host}"
f"{self.reverse_url('one_job', job_id)}"
f"{self.reverse_url('one_job', job_id)}",
'version': version,
}
)
except (RunfolderNotFound, FileNotFoundError) as exc:
Expand Down Expand Up @@ -177,6 +180,10 @@ def post(self, job_id):
except UnableToStopJob:
self.set_status(status_code=FORBIDDEN)

self.write_object({'link': '{}://{}{}'.format(self.request.protocol,
self.request.host,
self.reverse_url('one_job', job_id))})
self.write_object({
"link":
f"{self.request.protocol}://"
f"{self.request.host}"
f"{self.reverse_url('one_job', job_id)}",
'version': version,
})
36 changes: 26 additions & 10 deletions tests/unit/handlers/test_job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sequencing_report_service.services.local_runner_service import LocalRunnerService
from sequencing_report_service.repositiories.runfolder_repo import RunfolderRepository
from sequencing_report_service.models.db_models import Job, State
from sequencing_report_service import __version__ as version


class TestJobHandler(AsyncHTTPTestCase):
Expand All @@ -24,7 +25,6 @@ def get_app(self):
mock_runner_service.start = mock.MagicMock(return_value=job.job_id)
mock_runner_service.stop = mock.MagicMock(return_value=job)

mock_path = Path('/foo')
mock_runfolder_repo = mock.create_autospec(RunfolderRepository)
mock_runfolder_repo.get_runfolder = mock.MagicMock(return_value=mock)

Expand All @@ -34,10 +34,14 @@ def get_app(self):
def test_get_jobs(self):
response = self.fetch('/api/1.0/jobs/')
self.assertEqual(response.code, 200)
resp_dict = json.loads(response.body)['jobs'][0]
self.assertEqual(resp_dict['command'], ['foo'])
self.assertEqual(resp_dict['job_id'], 1)
self.assertEqual(resp_dict['state'], 'pending')
resp_dict = json.loads(response.body)

self.assertEqual(resp_dict['version'], version)

jobs_dict = resp_dict['jobs'][0]
self.assertEqual(jobs_dict['command'], ['foo'])
self.assertEqual(jobs_dict['job_id'], 1)
self.assertEqual(jobs_dict['state'], 'pending')

def test_get_job(self):
response = self.fetch('/api/1.0/jobs/1')
Expand All @@ -46,16 +50,28 @@ def test_get_job(self):
self.assertEqual(resp_dict['command'], ['foo'])
self.assertEqual(resp_dict['job_id'], 1)
self.assertEqual(resp_dict['state'], 'pending')
self.assertEqual(resp_dict['version'], version)

def test_start_job(self):
response = self.fetch('/api/1.0/jobs/start/foo/bar', method='POST', body=json.dumps({}))
self.assertEqual(response.code, 202)
self.assertDictEqual(json.loads(response.body),
{'link':
'http://127.0.0.1:{}/api/1.0/jobs/{}'.format(self.get_http_port(), 1)})
self.assertDictEqual(
json.loads(response.body),
{
'link': 'http://127.0.0.1:{}/api/1.0/jobs/{}'.format(
self.get_http_port(), 1),
'version': version,
}
)

def test_stop_job(self):
response = self.fetch('/api/1.0/jobs/stop/1', method='POST', body=json.dumps({}))
self.assertEqual(response.code, 202)
self.assertDictEqual(json.loads(response.body),
{'link': 'http://127.0.0.1:{}/api/1.0/jobs/{}'.format(self.get_http_port(), 1)})
self.assertDictEqual(
json.loads(response.body),
{
'link': 'http://127.0.0.1:{}/api/1.0/jobs/{}'.format(
self.get_http_port(), 1),
'version': version,
}
)

0 comments on commit 50fff79

Please sign in to comment.