diff options
author | BonfaceKilz | 2021-02-24 14:06:27 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-02-24 14:20:29 +0300 |
commit | a0f1ee1f4cb4b7d3494b47335fc48e63e40d85d3 (patch) | |
tree | e4aa2eb40a7d830405b90ff46ab026bcea26b806 /tests/integration | |
parent | 6c434c9dc30dc0b4e2b806b0792bf6d384490c14 (diff) | |
download | genenetwork3-a0f1ee1f4cb4b7d3494b47335fc48e63e40d85d3.tar.gz |
Add tests for "/gemma/run" endpoint
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/test_gemma.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py index 676812d..d9ebeb1 100644 --- a/tests/integration/test_gemma.py +++ b/tests/integration/test_gemma.py @@ -1,10 +1,18 @@ """Integration tests for gemma API endpoints""" import unittest +from dataclasses import dataclass +from typing import Callable from unittest import mock from gn3.app import create_app +@dataclass +class MockRedis: + """Mock File object returned by request.files""" + redis: Callable + + class GemmaAPITest(unittest.TestCase): """Test cases for the Gemma API""" def setUp(self): @@ -18,3 +26,54 @@ class GemmaAPITest(unittest.TestCase): self.assertEqual(response.get_json(), {"status": 0, "output": "v1.9"}) self.assertEqual(response.status_code, 200) + + @mock.patch("gn3.api.gemma.redis.Redis") + @mock.patch("gn3.api.gemma.queue_cmd") + @mock.patch("gn3.api.gemma.generate_gemma_computation_cmd") + def test_run_gemma(self, mock_gemma_computation_cmd, + mock_queue_cmd, mock_redis): + """Test that gemma composes the command correctly""" + _redis_conn = MockRedis(redis=mock.MagicMock()) + mock_redis.return_value = _redis_conn + mock_gemma_computation_cmd.side_effect = [ + ("gemma-wrapper --json -- " + "-g genofile.txt -p " + "test.txt -a genofile_snps.txt " + "-gk > /tmp/gn2/" + "bxd_K_gUFhGu4rLG7k+CXLPk1OUg.txt"), + ("gemma-wrapper --json -- " + "-g genofile.txt -p " + "test.txt -a genofile_snps.txt " + "-gk > /tmp/gn2/" + "bxd_GWA_gUFhGu4rLG7k+CXLPk1OUg.txt") + ] + mock_queue_cmd.return_value = "my-unique-id" + response = self.app.post("/gemma/run", json={ + "trait_filename": "BXD.txt", + "geno_filename": "BXD_geno", + "values": ["X", "N/A", "X"], + "dataset_groupname": "BXD", + "trait_name": "Height", + "email": "me@me.com", + "dataset_name": "BXD" + }) + mock_queue_cmd.assert_has_calls( + [mock.call(conn=_redis_conn, + email="me@me.com", + cmd=("gemma-wrapper --json -- -g " + "genofile.txt -p test.txt " + "-a genofile_snps.txt -gk > " + "/tmp/gn2/bxd_K_gUFhGu4rLG7k+CXLPk1OUg.txt " + "&& gemma-wrapper --json -- -g " + "genofile.txt -p test.txt " + "-a genofile_snps.txt " + "-gk > " + "/tmp/gn2/" + "bxd_GWA_gUFhGu4rLG7k+CXLPk1OUg.txt"))] + ) + # mock_pheno_txt_file.return_value = "/tmp/gn2/BXD_6OBEPW." + self.assertEqual( + response.get_json(), + {"unique_id": 'my-unique-id', + "status": "queued", + "output_file": "BXD_GWA_9lo8zwOOXbfB73EcyXxAYQ.txt"}) |