From 2b0200e7d9e78bf81ab2fd5fa70e68fae75e91d2 Mon Sep 17 00:00:00 2001 From: nkongenelly Date: Thu, 25 Jan 2024 12:18:49 -0100 Subject: [PATCH] DATAOPS-489:Added DDS version as response in the dds service (#53) DATAOPS-489:refactored code to get dds version DATAOPS-489: Usinf _run() to run the dds --version command DATAOPS-489: correct unit tests Co-authored-by: nelnk861 --- .gitignore | 1 + delivery/handlers/delivery_handlers.py | 5 ++- delivery/models/project.py | 13 ++++++++ tests/integration_tests/base.py | 5 ++- .../integration_tests/test_integration_dds.py | 3 ++ tests/unit_tests/services/test_dds.py | 32 +++++++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1d7016e..4cbd9e4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dist/ .coverage *.db *.log +venv/* diff --git a/delivery/handlers/delivery_handlers.py b/delivery/handlers/delivery_handlers.py index b3a203d..2f4b3d1 100644 --- a/delivery/handlers/delivery_handlers.py +++ b/delivery/handlers/delivery_handlers.py @@ -64,8 +64,11 @@ def post(self, staging_id): self.reverse_url("delivery_status", delivery_id)) self.set_status(ACCEPTED) + + dds_version = dds_project.get_dds_version() self.write_json({'delivery_order_id': delivery_id, - 'delivery_order_link': status_end_point}) + 'delivery_order_link': status_end_point, + 'dds_version': dds_version}) class DeliveryStatusHandler(ArteriaDeliveryBaseHandler): diff --git a/delivery/models/project.py b/delivery/models/project.py index cb2ae09..40e1f41 100644 --- a/delivery/models/project.py +++ b/delivery/models/project.py @@ -165,6 +165,19 @@ def __del__(self): " Check token expiry date (`dds auth info`).") raise + @gen.coroutine + def get_dds_version(self): + """ + Get the DDS version been used + """ + + cmd = ['dds', '--version'] + result = yield self._run(cmd) # should return "Data Delivery System, version 2.6.1" + version_stdout = ''.join(result) + version = (version_stdout.split("version")[-1]).strip() + return version + + @classmethod @gen.coroutine def new( diff --git a/tests/integration_tests/base.py b/tests/integration_tests/base.py index afdccdc..7fcc6f1 100644 --- a/tests/integration_tests/base.py +++ b/tests/integration_tests/base.py @@ -4,7 +4,8 @@ import random import logging -from subprocess import PIPE + +from subprocess import PIPE, run as subprocess_run from tornado.testing import * from tornado.web import Application @@ -125,6 +126,8 @@ def mock_delivery(cmd): new_cmd += ['&&', 'test', '-e', auth_token] new_cmd = " ".join(new_cmd) shell = True + elif '--version' in cmd: + new_cmd += ['&&', 'echo', f"2.6.1"] else: new_cmd = cmd diff --git a/tests/integration_tests/test_integration_dds.py b/tests/integration_tests/test_integration_dds.py index 2473524..7234440 100644 --- a/tests/integration_tests/test_integration_dds.py +++ b/tests/integration_tests/test_integration_dds.py @@ -108,6 +108,9 @@ def test_can_stage_and_delivery_project_dir(self): status_response = yield self.http_client.fetch(delivery_link) self.assertEqual(json.loads(status_response.body)["status"], DeliveryStatus.delivery_skipped.name) + + dds_version = delivery_resp_as_json['dds_version'] + self.assertEqual(dds_version, '2.6.1') @gen_test def test_can_stage_and_deliver_clean_flowcells(self): diff --git a/tests/unit_tests/services/test_dds.py b/tests/unit_tests/services/test_dds.py index 8e58c62..0751fc5 100644 --- a/tests/unit_tests/services/test_dds.py +++ b/tests/unit_tests/services/test_dds.py @@ -410,3 +410,35 @@ def test_get_dds_project_title(self): ngi_project_name = yield dds_project.get_ngi_project_name() self.assertEqual(ngi_project_name, "AB-1234") + + @gen_test + def test_get_dds_version(self): + project_id = 'snpseq00001' + mocked_version = "2.6.1" + + with patch( + 'delivery.models.project.DDSProject._run', + new_callable=AsyncMock, + return_value=mocked_version, + ): + + dds_project = DDSProject( + dds_service=self.dds_service, + auth_token=self.token_file.name, + dds_project_id=project_id, + ) + + dds_version = yield dds_project.get_dds_version() + self.assertEqual(dds_version, mocked_version) + + + yield dds_project.get_dds_version() + self.mock_dds_runner.run.assert_has_calls([ + call([ + 'dds', + '--version', + ]) + ]) + + +