Skip to content

Commit

Permalink
Fixed sequence_run_manager endpoint unit test
Browse files Browse the repository at this point in the history
* Improved SRM unit testing regime, coverage report

Related #139
  • Loading branch information
victorskl committed Mar 22, 2024
1 parent 87b919e commit a0fec23
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ Brewfile.lock.json
*.xml

target/

.coverage
htmlcov/
5 changes: 5 additions & 0 deletions lib/workload/stateless/sequence_run_manager/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
omit = */tests/*,*tests*,sequence_run_manager/management/*,sequence_run_manager/migrations/*,sequence_run_manager/wsgi.py,migrate.py,manage.py

[report]
omit = */tests/*,*tests*,sequence_run_manager/management/*,sequence_run_manager/migrations/*,sequence_run_manager/wsgi.py,migrate.py,manage.py
23 changes: 23 additions & 0 deletions lib/workload/stateless/sequence_run_manager/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.EXPORT_ALL_VARIABLES:
DJANGO_SETTINGS_MODULE = sequence_run_manager.settings.local

.PHONY: test suite

install:
Expand All @@ -17,6 +20,26 @@ test: install up suite down
suite:
@python manage.py test

migrate:
@python manage.py migrate

start: migrate
@python manage.py runserver_plus

openapi:
@python manage.py generateschema > orcabus.srm.openapi.yaml

validate: openapi
@python -m openapi_spec_validator orcabus.srm.openapi.yaml

coverage: install up migrate
@echo $$DJANGO_SETTINGS_MODULE
@coverage run --source='.' manage.py test

report:
@coverage report -m
@coverage html

up:
@docker compose up --wait -d

Expand Down
8 changes: 8 additions & 0 deletions lib/workload/stateless/sequence_run_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ python manage.py generateschema > orcabus.srm.openapi.yaml

## Testing

### Coverage report

```
make coverage report
```

_The html report is in `htmlcov/index.html`._

### Run test suite

```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r requirements-test.txt
django_extensions==3.2.3
drf_yasg==1.21.7
openapi-spec-validator
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pytz==2024.1
mockito==1.5.0
# Intentionally leave out the boto3 version here. They bump like daily and latest is always fine.
boto3
coverage==7.4.4
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from django.utils.timezone import now

from sequence_run_manager.models.sequence import Sequence
from sequence_run_manager.urls.base import api_base

logger = logging.getLogger()
logger.setLevel(logging.INFO)


class SequenceViewSetTestCase(TestCase):
endpoint = f"/{api_base}sequence"

def setUp(self):
Sequence.objects.create(
instrument_run_id="190101_A01052_0001_BH5LY7ACGT",
Expand All @@ -29,22 +32,41 @@ def test_get_api(self):
"""
# Get sequence list
logger.info("Get sequence API")
response = self.client.get("/sequence/")
response = self.client.get(self.endpoint)
self.assertEqual(response.status_code, 200, "Ok status response is expected")

logger.info("Check if API return result")
result_response = response.data["results"]
self.assertGreater(len(result_response), 0, "A result is expected")

def test_get_by_uk_surrogate_key(self):
"""
python manage.py test sequence_run_manager.tests.test_viewsets.SequenceViewSetTestCase.test_get_by_uk_surrogate_key
"""
logger.info("Check if unique data has a single entry")
response = self.client.get("/sequence/?sequence_run_id=r.AAAAAA")
response = self.client.get(f"{self.endpoint}/?instrument_run_id=190101_A01052_0001_BH5LY7ACGT")
results_response = response.data["results"]
self.assertEqual(
len(results_response), 1, "Single result is expected for unique data"
)

def test_get_by_sequence_run_id(self):
"""
python manage.py test sequence_run_manager.tests.test_viewsets.SequenceViewSetTestCase.test_get_by_sequence_run_id
"""
logger.info("Check if unique data has a single entry")
response = self.client.get(f"{self.endpoint}/?sequence_run_id=r.AAAAAA")
results_response = response.data["results"]
self.assertEqual(
len(results_response), 1, "Single result is expected for unique data"
)

def test_get_by_invalid_parameter(self):
"""
python manage.py test sequence_run_manager.tests.test_viewsets.SequenceViewSetTestCase.test_get_by_invalid_parameter
"""
logger.info("Check if wrong parameter")
response = self.client.get("/sequence/?lib_id=LBR0001")
response = self.client.get(f"{self.endpoint}/?lib_id=LBR0001")
results_response = response.data["results"]
self.assertEqual(
len(results_response),
Expand Down

0 comments on commit a0fec23

Please sign in to comment.