import unittest
from unittest import mock
from dataclasses import dataclass

from wqflask.marker_regression.rqtl_mapping import run_rqtl

@dataclass
class MockGroup:
    name: str
    genofile: str

@dataclass
class MockDataset:
    group: MockGroup

class TestRqtlMapping(unittest.TestCase):
    """Tests for functions in rqtl_mapping.py"""
    @mock.patch("wqflask.marker_regression.rqtl_mapping.requests.post")
    @mock.patch("wqflask.marker_regression.rqtl_mapping.locate")
    @mock.patch("wqflask.marker_regression.rqtl_mapping.write_phenotype_file")
    def test_run_rqtl_with_perm(self, mock_write_pheno_file, mock_locate, mock_post):
        """Test for run_rqtl with permutations > 0"""
        dataset_group = MockGroup("GP1", "file_geno")
        dataset = MockDataset(dataset_group)

        mock_write_pheno_file.return_value = "pheno_filename"
        mock_locate.return_value = "geno_filename"
        mock_post.return_value = {"output_file": "output_filename",
                                  "rqtl_cmd": "the_command"}

        results = run_rqtl(trait_name="the_trait", vals=[], samples=[],
        dataset=dataset, mapping_scale="cM", model="normal", method="hk",
        num_perm=5, perm_strata_list=[], do_control="false", control_marker="",
        manhattan_plot=True, cofactors="")

        mock_write_pheno_file.assert_called_once()
        mock_locate.assert_called_once()
        mock_post.assert_called_once()

        self.assertEqual(results, ([], 3, 4, []))

@@ -941,102 +941,299 @@
 e = 
-%7B%22output_file%22: %22output_filename%22,%0A                                  %22rqtl_cmd%22: %22the_command%22
+Mock(ok=True)%0A        mock_post.return_value.json.return_value = %7B%22perm_results%22: %5B%5D,%0A                                                    %22suggestive%22: 3,%0A                                                    %22significant%22: 4,%0A                                                    %22results%22 : %5B%5D
 %7D%0A%0A 

Change test_rqtl_mapping.py to account for full results being returned from the GN3 request