Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adatps validation behaviour to marshmallow > 3.0. Adds tests
- Loading branch information
Måns Magnusson
committed
Jul 1, 2020
1 parent
4e0ed0e
commit 65baa9d
Showing
2 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
"""Tests for the config functionality""" | ||
import pytest | ||
|
||
from trailblazer.mip import config as tb_config | ||
from trailblazer.exc import ConfigError | ||
|
||
def test_validate_config(): | ||
"""Test to validate a correct config""" | ||
# GIVEN a correct config | ||
sample = dict( | ||
sample_id = "sample", | ||
analysis_type = 'wes', | ||
father = '0', | ||
mother = '0', | ||
phenotype = 'affected', | ||
sex = 'male', | ||
expected_coverage = 15, | ||
capture_kit = 'agilent_sureselect_cre.v1', | ||
) | ||
|
||
config = dict( | ||
case = "a_case", | ||
default_gene_panels = ["a_panel"], | ||
samples = [sample], | ||
) | ||
|
||
# WHEN validating the config | ||
errors = tb_config.ConfigHandler.validate_config(config) | ||
|
||
# THEN assert the errors is a dict | ||
assert isinstance(errors, dict) | ||
|
||
# THEN assert there where no errors | ||
assert errors == {} | ||
|
||
def test_validate_config_invalid_analysis_type(): | ||
"""Test to validate a invalid config with wrong analysis type""" | ||
# GIVEN a correct config | ||
sample = dict( | ||
sample_id = "sample", | ||
analysis_type = 'nonexisting', | ||
father = '0', | ||
mother = '0', | ||
phenotype = 'affected', | ||
sex = 'male', | ||
expected_coverage = 15, | ||
capture_kit = 'agilent_sureselect_cre.v1', | ||
) | ||
|
||
config = dict( | ||
case = "a_case", | ||
default_gene_panels = ["a_panel"], | ||
samples = [sample], | ||
) | ||
|
||
# WHEN validating the config | ||
with pytest.raises(ConfigError): | ||
# THEN assert a config error is raised | ||
tb_config.ConfigHandler.validate_config(config) | ||
|
||
def test_validate_config_unknown_field(): | ||
"""Test to validate a config with a unspecified field. | ||
This should work since we allow unspecified fields | ||
""" | ||
# GIVEN a correct config with a extra field | ||
sample = dict( | ||
sample_id = "sample", | ||
sample_display_name = "ASAMPLENAME", | ||
analysis_type = 'wes', | ||
father = '0', | ||
mother = '0', | ||
phenotype = 'affected', | ||
sex = 'male', | ||
expected_coverage = 15, | ||
capture_kit = 'agilent_sureselect_cre.v1', | ||
) | ||
|
||
config = dict( | ||
case = "a_case", | ||
default_gene_panels = ["a_panel"], | ||
samples = [sample], | ||
) | ||
|
||
# WHEN validating the config | ||
errors = tb_config.ConfigHandler.validate_config(config) | ||
|
||
# THEN assert the errors is a dict | ||
assert isinstance(errors, dict) | ||
|
||
# THEN assert there where one error that could pass | ||
assert len(errors) == 1 | ||
|
||
def test_validate_config_unknown_field_and_missing_sample_id(): | ||
"""Test to validate a config with a unspecified field and a missing mandatory field. | ||
This should raise exception since we do not allow missing mandatory fields | ||
""" | ||
# GIVEN a config with missing sample_id and an extra field | ||
sample = dict( | ||
sample_display_name = "ASAMPLENAME", | ||
analysis_type = 'wes', | ||
father = '0', | ||
mother = '0', | ||
phenotype = 'affected', | ||
sex = 'male', | ||
expected_coverage = 15, | ||
capture_kit = 'agilent_sureselect_cre.v1', | ||
) | ||
|
||
config = dict( | ||
case = "a_case", | ||
default_gene_panels = ["a_panel"], | ||
samples = [sample], | ||
) | ||
|
||
# WHEN validating the config | ||
with pytest.raises(ConfigError): | ||
# THEN assert a config error is raised | ||
tb_config.ConfigHandler.validate_config(config) | ||
|
||
def test_validate_config_unknown_field_and_invalid_analysis_type(): | ||
"""Test to validate a config with a unspecified field and a missing mandatory field. | ||
This should raise exception since we do not allow wrong analysis types | ||
""" | ||
# GIVEN a config with wrong analysis type and an extra field | ||
sample = dict( | ||
sample_id = "sample", | ||
sample_display_name = "ASAMPLENAME", | ||
analysis_type = 'nonexisting', | ||
father = '0', | ||
mother = '0', | ||
phenotype = 'affected', | ||
sex = 'male', | ||
expected_coverage = 15, | ||
capture_kit = 'agilent_sureselect_cre.v1', | ||
) | ||
|
||
config = dict( | ||
case = "a_case", | ||
default_gene_panels = ["a_panel"], | ||
samples = [sample], | ||
) | ||
|
||
# WHEN validating the config | ||
with pytest.raises(ConfigError): | ||
# THEN assert a config error is raised | ||
tb_config.ConfigHandler.validate_config(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters