def test_convert_other_sex(other_sex_case_output: str): """Test to validate a case when the is set to 'other'""" cases = json.loads(other_sex_case_output) case = cases[0] # GIVEN a case that has parent set to None assert case["individuals"][0]["sex"] == "other" # WHEN validating the output with model case_obj = ScoutExportCase(**case) # THEN assert that the sex has been converted to "0" assert case_obj.dict()["individuals"][0]["sex"] == "0"
def test_validate_empty_diagnosis_phenotypes(none_case_output: str): """Test to validate a case when the diagnosis phenotypes is a empty list""" cases = json.loads(none_case_output) case = cases[0] # GIVEN a case that has parent set to None assert case["diagnosis_phenotypes"] == [] # WHEN validating the output with model case_obj = ScoutExportCase(**case) # THEN assert diagnosis phenotypes is set to None assert case_obj.dict()["diagnosis_phenotypes"] == []
def test_validate_case_parents_none(none_case_output: str): """Test to validate a case when there are mandatory fields with the value None""" cases = json.loads(none_case_output) case = cases[0] # GIVEN a case that has parent set to None assert case["individuals"][0]["father"] is None assert case["individuals"][0]["mother"] is None # WHEN validating the output with model case_obj = ScoutExportCase(**case) # THEN assert father is set to None assert case_obj.dict()["individuals"][0]["father"] == "0" assert case_obj.dict()["individuals"][0]["mother"] == "0"
def test_validate_case_father_none(none_case_output: str): """Test to validate a case when there are mandatory fields with the value None""" cases = json.loads(none_case_output) case = cases[0] # GIVEN a case that has parent set to None assert case["individuals"][0]["father"] is None # WHEN validating the output with model case_obj = ScoutExportCase(**case) case_dict = case_obj.dict() # THEN assert father is set to None assert case_dict["individuals"][0]["father"] == "0" # THEN assert that '_id' has been changed to 'id' assert "_id" not in case_dict assert "id" in case_dict
def get_cases( self, case_id: Optional[str] = None, reruns: bool = False, finished: bool = False, status: Optional[str] = None, days_ago: int = None, ) -> List[ScoutExportCase]: """Interact with cases existing in the database.""" # These commands can be run with `scout export cases` get_cases_command = ["export", "cases", "--json"] if case_id: get_cases_command.extend(["--case-id", case_id]) elif status: get_cases_command.extend(["--status", status]) elif finished: get_cases_command.append("--finished") if reruns: LOG.info("Fetching cases that are reruns") get_cases_command.append("--reruns") if days_ago: get_cases_command.extend(["--within-days", str(days_ago)]) try: self.process.run_command(get_cases_command) if not self.process.stdout: return [] except CalledProcessError: LOG.info("Could not find cases") return [] cases = [] for case_export in json.loads(self.process.stdout): LOG.info("Validating case %s", case_export.get("_id")) case_obj = ScoutExportCase(**case_export) cases.append(case_obj) return cases
def fixture_scout_export_case_missing_bam( scout_export_case_data: dict) -> ScoutExportCase: """Returns a export case object where one individual is missing bam file""" scout_export_case_data["individuals"][1].pop("bam_file") return ScoutExportCase(**scout_export_case_data)
def fixture_scout_export_case(scout_export_case_data: dict) -> ScoutExportCase: """Returns a export case object""" return ScoutExportCase(**scout_export_case_data)
def fixture_scout_export_case_no_causatives( scout_export_case_data: dict) -> ScoutExportCase: """Returns a export case object without causatives""" scout_export_case_data.pop("causatives") return ScoutExportCase(**scout_export_case_data)