From 5a3eab3fd18afca73ef2b34e358baa7aadd73cbf Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Mon, 1 Feb 2021 22:20:20 -0500 Subject: [PATCH] Add tests for sequences and indexes endpoints --- test/integration/test_genomes.py | 40 +++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/test/integration/test_genomes.py b/test/integration/test_genomes.py index fbc66efca8e..50556ebee0b 100644 --- a/test/integration/test_genomes.py +++ b/test/integration/test_genomes.py @@ -1,8 +1,10 @@ import os +import tempfile +from unittest.mock import patch from galaxy.exceptions import ( - MissingDataError, ObjectNotFound, + ReferenceDataError, ) from galaxy_test.driver import integration_util @@ -65,13 +67,45 @@ class GenomesTestCase(integration_util.IntegrationTestCase): assert rval['id'] == key assert len(rval['chrom_info']) == len(LEN_DATA) - def test_show_valid_missing(self): + def test_show_valid_no_refdata(self): key = get_key(has_len_file=False) response = self._get(f'genomes/{key}') self._assert_status_code_is(response, 500) - assert response.json()['err_code'] == MissingDataError.err_code.code + assert response.json()['err_code'] == ReferenceDataError.err_code.code def test_show_invalid(self): response = self._get('genomes/invalid') self._assert_status_code_is(response, 404) assert response.json()['err_code'] == ObjectNotFound.err_code.code + + def test_sequences(self): + + class RefDataMock: + sequence = 'test-value' + + key = get_key() + with patch.object(self._app.genomes, 'has_reference_data', return_value=True), \ + patch.object(self._app.genomes, '_get_reference_data', return_value=RefDataMock()): + response = self._get(f'genomes/{key}/sequences') + self._assert_status_code_is(response, 200) + assert response.content == bytes(RefDataMock.sequence, 'utf-8') + + def test_sequences_no_data(self): + key = get_key() + with patch.object(self._app.genomes, 'has_reference_data', return_value=False): + response = self._get(f'genomes/{key}/sequences') + self._assert_status_code_is(response, 500) + assert response.json()['err_code'] == ReferenceDataError.err_code.code + + def test_indexes(self): + mock_key, mock_content, index_type, suffix = 'mykey', 'mydata', 'fasta_indexes', '.fai' + # write some data to a tempfile + with tempfile.NamedTemporaryFile(dir=self._tempdir, suffix=suffix, mode="w", delete=False) as tf: + tf.write(mock_content) + # make a mock containing the path to the tempfile + tmpfile_path = tf.name[:-len(suffix)] # chop off the extention + mock_data = [[mock_key, tmpfile_path]] + with patch.object(self._app.tool_data_tables.data_tables[index_type], 'data', new=mock_data): + response = self._get(f'genomes/{mock_key}/indexes?type={index_type}') + self._assert_status_code_is(response, 200) + assert response.content == bytes(mock_content, 'utf-8')