Skip to content

Commit

Permalink
DATAOPS-489:Added DDS version as response in the dds service (#53)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nkongenelly and nkongenelly authored Jan 25, 2024
1 parent a5f6dcc commit 2b0200e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist/
.coverage
*.db
*.log
venv/*
5 changes: 4 additions & 1 deletion delivery/handlers/delivery_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions delivery/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion tests/integration_tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/test_integration_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 32 additions & 0 deletions tests/unit_tests/services/test_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
])



0 comments on commit 2b0200e

Please sign in to comment.