aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/unit/base
diff options
context:
space:
mode:
authorBonfaceKilz2021-05-04 23:27:00 +0300
committerBonfaceKilz2021-05-05 12:26:04 +0300
commitb2b81942c6dda717ec8e7beeac61477f0e67a387 (patch)
treebb3e2a30f673adacfdf78dc3d71af3a4b549698e /wqflask/tests/unit/base
parent31d447d5d70cf18a41c6e139a152fe4cfb864bb4 (diff)
downloadgenenetwork2-b2b81942c6dda717ec8e7beeac61477f0e67a387.tar.gz
templates: test_species: Add tests for instantiating Chromosomes
Diffstat (limited to 'wqflask/tests/unit/base')
-rw-r--r--wqflask/tests/unit/base/test_species.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/wqflask/tests/unit/base/test_species.py b/wqflask/tests/unit/base/test_species.py
index 42aa9092..487bbd7f 100644
--- a/wqflask/tests/unit/base/test_species.py
+++ b/wqflask/tests/unit/base/test_species.py
@@ -4,6 +4,27 @@ import unittest
from unittest import mock
from base.species import TheSpecies
from base.species import IndChromosome
+from base.species import Chromosomes
+from collections import OrderedDict
+from wqflask import app
+from dataclasses import dataclass
+
+
+@dataclass
+class MockChromosome:
+ OrderId: int
+ Name: str
+ Length: int
+
+
+@dataclass
+class MockGroup:
+ name: str
+
+
+@dataclass
+class MockDataset:
+ group: MockGroup
class TestTheSpecies(unittest.TestCase):
@@ -37,3 +58,59 @@ class TestIndChromosome(unittest.TestCase):
self.assertEqual(test_ind_chromosome.name, "Test")
self.assertEqual(test_ind_chromosome.length, 10000000)
self.assertEqual(test_ind_chromosome.mb_length, 10)
+
+
+class TestChromosomes(unittest.TestCase):
+ """Tests for Chromosomes class"""
+ maxDiff = None
+
+ def setUp(self):
+ self.app_context = app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ self.app_context.pop()
+
+ @mock.patch("base.species.g")
+ def test_create_chromosomes_with_no_species(self, mock_db):
+ """Test instantiating a chromosome without a species"""
+ mock_db.db.execute.return_value.fetchall.return_value = [
+ MockChromosome(1, "X", 100),
+ MockChromosome(2, "Y", 1000),
+ MockChromosome(3, "Z", 10000),
+ ]
+ mock_dataset = MockDataset(MockGroup("Random"))
+ test_chromosomes = Chromosomes(dataset=mock_dataset)
+ mock_db.db.execute.assert_called_with(
+ "SELECT Chr_Length.Name, Chr_Length.OrderId, Length "
+ "FROM Chr_Length, InbredSet WHERE "
+ "Chr_Length.SpeciesId = InbredSet.SpeciesId AND "
+ "InbredSet.Name = 'Random' ORDER BY OrderId"
+ )
+ self.assertEqual(
+ list(test_chromosomes.chromosomes.keys()),
+ [1, 2, 3]
+ )
+ self.assertEqual(test_chromosomes.dataset, mock_dataset)
+
+ @mock.patch("base.species.g")
+ def test_create_chromosomes_with_species(self, mock_db):
+ """Test instantiating a chromosome with a species"""
+ mock_db.db.execute.return_value.fetchall.return_value = [
+ MockChromosome(1, "X", 100),
+ MockChromosome(2, "Y", 1000),
+ MockChromosome(3, "Z", 10000),
+ ]
+ mock_dataset = MockDataset(MockGroup("Random"))
+ test_chromosomes = Chromosomes(dataset=mock_dataset,
+ species="testSpecies")
+ mock_db.db.execute.assert_called_with(
+ "SELECT Chr_Length.Name, Chr_Length.OrderId, Length "
+ "FROM Chr_Length, Species WHERE "
+ "Chr_Length.SpeciesId = Species.SpeciesId AND "
+ "Species.Name = 'Testspecies' ORDER BY OrderId"
+ )
+ self.assertEqual(
+ list(test_chromosomes.chromosomes.keys()),
+ [1, 2, 3]
+ )