def test_list(self): url = reverse("clinvar_export:ajax-organisation-list", kwargs={"project": self.project.sodar_uuid}) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 2) expected0 = jsonmatch.compile({ "sodar_uuid": RE_UUID4, "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "clinvar_id": 505735, "name": ("Institute for Medical Genetics and Human Genetics (Charité - Universitätsmedizin " "Berlin), Charité - Universitätsmedizin"), }) expected0.assert_matches(res_json[0]) expected1 = jsonmatch.compile({ "sodar_uuid": RE_UUID4, "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "clinvar_id": 507461, "name": "CUBI - Core Unit Bioinformatics (Berlin Institute of Health)", }) expected1.assert_matches(res_json[1])
def setUp(self): self.length_lambda = lambda x: len(x) == 3 self.crazy_regexp = re.compile(r'[a-z][A-Z]{3}') self.spec = { 'foo': 1, 'b': str, 'c': { 'd': [1], 'e': list, 'f': self.crazy_regexp, 'g': self.length_lambda, }, } self.matchingd = { 'foo': 1, 'b': 'abcd', 'c': { 'd': [1], 'e': [1, 2, 3], 'f': "aBBB", 'g': '123', }, } self.shuffled = copy.deepcopy(self.matchingd) self.shuffled['c']['e'] = [3, 1, 2] self.matcher = jsonmatch.compile(self.spec) self.ordermatcher = jsonmatch.compile(self.matchingd)
def setUp(self): self.length_lambda = lambda x: len(x) == 3 self.crazy_regexp = re.compile(r'[a-z][A-Z]{3}') self.spec = { 'foo': 1, 'b': str, 'c': { 'd': [1], 'e': list, 'f': self.crazy_regexp, 'g': self.length_lambda, } } self.matchingd = { 'foo': 1, 'b': 'abcd', 'c': { 'd': [1], 'e': [1, 2, 3], 'f': "aBBB", 'g': '123', } } self.matcher = jsonmatch.compile(self.spec)
def test_list(self): submittingorg = SubmittingOrgFactory(organisation=self.organisation, submission_set=self.submissionset) url = reverse( "clinvar_export:ajax-submittingorg-list-create", kwargs={"project": self.submissionset.project.sodar_uuid}, ) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) expected = jsonmatch.compile({ "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "organisation": str(self.organisation.sodar_uuid), "sodar_uuid": str(submittingorg.sodar_uuid), "sort_order": submittingorg.sort_order, "submission_set": str(self.submissionset.sodar_uuid), }) expected.assert_matches(res_json[0])
def test_update(self): url = reverse( "clinvar_export:ajax-submissionset-retrieve-update-destroy", kwargs={ "project": self.project.sodar_uuid, "submissionset": self.submissionset.sodar_uuid, }, ) data = { "title": "Brand New Title", "state": "submitted", } with self.login(self.contributor_as.user): response = self.client.patch(url, data) self.assertEqual(response.status_code, 200) res_json = response.json() expected = jsonmatch.compile({ "sodar_uuid": str(self.submissionset.sodar_uuid), "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "project": str(self.project.sodar_uuid), "title": data["title"], "submitting_orgs": [str(self.submittingorg.sodar_uuid)], "submissions": [str(self.submission.sodar_uuid)], "state": data["state"], "submitter": str(self.submissionset.submitter.sodar_uuid), }) expected.assert_matches(res_json)
def test_query(self): hpo_record = HpoFactory() url = (reverse( "clinvar_export:query-omim-term", kwargs={ "project": self.project.sodar_uuid, }, ) + "?query=" + hpo_record.database_id) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() lst = [x.strip() for x in hpo_record.name.split(";") if x.strip()] expected = jsonmatch.compile({ "query": hpo_record.database_id, "result": [ { "term_id": hpo_record.database_id, "term_name": lst[2] }, { "term_id": hpo_record.database_id, "term_name": lst[0] }, { "term_id": hpo_record.database_id, "term_name": lst[1] }, ], }) expected.assert_matches(res_json)
def test_list(self): url = reverse( "clinvar_export:ajax-submissionset-list-create", kwargs={"project": self.project.sodar_uuid}, ) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) expected = jsonmatch.compile({ "sodar_uuid": RE_UUID4, "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "project": str(self.project.sodar_uuid), "title": re.compile(r"^Submission #\d+$"), "submitting_orgs": [str(self.submittingorg.sodar_uuid)], "submissions": [str(self.submission.sodar_uuid)], "state": self.submissionset.state, "submitter": str(self.submissionset.submitter.sodar_uuid), }) expected.assert_matches(res_json[0])
def test_list(self): self.assertEqual(Family.objects.count(), 0) self.assertEqual(Individual.objects.count(), 0) url = reverse("clinvar_export:ajax-individual-list", kwargs={"project": self.project.sodar_uuid}) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) re_name = re.compile(r"^index_\d\d\d-N1-DNA1-WES1$") expected = jsonmatch.compile({ "affected": "yes", "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "family": RE_UUID4, "name": re_name, "project": RE_UUID4, "phenotype_terms": None, "sex": "male", "sodar_uuid": RE_UUID4, "taxonomy_id": 9606, }) expected.assert_matches(res_json[0]) self.assertEqual(Family.objects.count(), 1) self.assertEqual(Individual.objects.count(), 1)
def test_retrieve(self): url = reverse( "clinvar_export:ajax-submittingorg-retrieve-update-destroy", kwargs={ "project": self.project.sodar_uuid, "submittingorg": self.submittingorg.sodar_uuid, }, ) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() expected = jsonmatch.compile({ "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "organisation": str(self.organisation.sodar_uuid), "sodar_uuid": str(self.submittingorg.sodar_uuid), "sort_order": self.submittingorg.sort_order, "submission_set": str(self.submissionset.sodar_uuid), }) expected.assert_matches(res_json)
def test_py2_str_should_match_unicode(self): assert PY2_STR is not None # this is to ensure all previously written spec with py2 `str` # should continue to work for py2 `unicode` and py2 `str` matcher = jsonmatch.compile({'key': PY2_STR}) self.assertTrue(matcher.matches({'key': b'abc'})) self.assertTrue(matcher.matches({'key': '\U0001f600'}))
def test_update(self): url = reverse( "clinvar_export:ajax-submissionindividual-retrieve-update-destroy", kwargs={ "project": self.project.sodar_uuid, "submissionindividual": self.submissionindividual.sodar_uuid, }, ) data = { "phenotypes": json.dumps([{ "term_id": "HP:XXX", "term_name": "Updated Term" }]), "sort_order": 42, "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "individual": RE_UUID4, "project": RE_UUID4, "sodar_uuid": RE_UUID4, "submission": RE_UUID4, "citations": [], "source": "clinical testing", "tissue": "saliva", "variant_allele_count": 1, "variant_origin": "germline", "variant_zygosity": "Homozygote", } with self.login(self.contributor_as.user): response = self.client.patch(url, data) self.assertEqual(response.status_code, 200) res_json = response.json() expected = jsonmatch.compile({ **data, "phenotypes": json.loads(data["phenotypes"]) }) expected.assert_matches(res_json)
def test_list(self): url = reverse("clinvar_export:ajax-submitter-list", kwargs={"project": self.project.sodar_uuid}) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) expected = jsonmatch.compile({ "sodar_uuid": RE_UUID4, "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "clinvar_id": 9131, "name": "Manuel Holtgrewe", }) expected.assert_matches(res_json[0])
def test_list(self): url = reverse("clinvar_export:ajax-assertionmethod-list", kwargs={"project": self.project.sodar_uuid}) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) expected = jsonmatch.compile({ "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "sodar_uuid": RE_UUID4, "is_builtin": True, "title": "ACMG Guidelines, 2015", "reference": "PMID:25741868", }) expected.assert_matches(res_json[0])
def test_list(self): submissionindividual = SubmissionIndividualFactory( submission=self.submission, individual=self.individual) url = reverse( "clinvar_export:ajax-submissionindividual-list-create", kwargs={ "project": self.submission.submission_set.project.sodar_uuid }, ) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) expected = jsonmatch.compile({ "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "individual": str(self.individual.sodar_uuid), "phenotypes": submissionindividual.phenotypes, "project": str(self.project.sodar_uuid), "sodar_uuid": str(submissionindividual.sodar_uuid), "sort_order": submissionindividual.sort_order, "submission": str(self.submission.sodar_uuid), "citations": [], "source": re.compile(r"(clinical testing|research|not provided)$"), "tissue": re.compile(r"^(blood|saliva)$"), "variant_allele_count": 1, "variant_origin": "germline", "variant_zygosity": "Homozygote", }) expected.assert_matches(res_json[0])
def test_query(self): hpo_name_record = HpoNameFactory() url = (reverse( "clinvar_export:query-hpo-term", kwargs={ "project": self.project.sodar_uuid, }, ) + "?query=" + hpo_name_record.hpo_id) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() expected = jsonmatch.compile({ "query": hpo_name_record.hpo_id, "result": [{ "term_id": hpo_name_record.hpo_id, "term_name": hpo_name_record.name }], }) expected.assert_matches(res_json)
def test_retrieve(self): url = reverse( "clinvar_export:ajax-submission-retrieve-update-destroy", kwargs={ "project": self.project.sodar_uuid, "submission": self.submission.sodar_uuid, }, ) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() expected = jsonmatch.compile({ "age_of_onset": "Antenatal", "inheritance": "Other", "variant_type": "Variation", "assertion_method": str(self.submission.assertion_method.sodar_uuid), "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "diseases": self.submission.diseases, "project": str(self.project.sodar_uuid), "record_status": self.submission.record_status, "release_status": self.submission.release_status, "significance_description": self.submission.significance_description, "significance_last_evaluation": self.submission.significance_last_evaluation.strftime("%Y-%m-%d"), "significance_status": self.submission.significance_status, "sodar_uuid": str(self.submission.sodar_uuid), "sort_order": self.submission.sort_order, "submission_individuals": [], # TODO: fill me! "submission_set": str(self.submission.submission_set.sodar_uuid), "variant_alternative": self.submission.variant_alternative, "variant_assembly": self.submission.variant_assembly, "variant_chromosome": self.submission.variant_chromosome, "variant_gene": self.submission.variant_gene, "variant_hgvs": self.submission.variant_hgvs, "variant_reference": self.submission.variant_reference, "variant_start": self.submission.variant_start, "variant_stop": self.submission.variant_stop, }) expected.assert_matches(res_json)
def test_py3_str_should_not_match_byte(self): matcher = jsonmatch.compile({'key': str}) self.assertFalse(matcher.matches({'key': b'abc'})) self.assertTrue(matcher.matches({'key': 'abc'}))
def test_list(self): url = reverse( "clinvar_export:ajax-submission-list-create", kwargs={"project": self.project.sodar_uuid}, ) with self.login(self.contributor_as.user): response = self.client.get(url) self.assertEqual(response.status_code, 200) res_json = response.json() self.assertEqual(len(res_json), 1) expected = jsonmatch.compile({ "age_of_onset": "Antenatal", "inheritance": "Other", "variant_type": "Variation", "assertion_method": str(self.submission.assertion_method.sodar_uuid), "date_created": RE_DATETIME, "date_modified": RE_DATETIME, "diseases": [{ "term_id": re.compile(r"OMIM:\d+"), "term_name": re.compile(r"Disease \d+") }], "project": str(self.project.sodar_uuid), "record_status": self.submission.record_status, "release_status": self.submission.release_status, "significance_description": self.submission.significance_description, "significance_last_evaluation": self.submission.significance_last_evaluation.strftime("%Y-%m-%d"), "significance_status": self.submission.significance_status, "sodar_uuid": str(self.submission.sodar_uuid), "sort_order": self.submission.sort_order, "submission_individuals": [str(self.submission_individual.sodar_uuid)], "submission_set": str(self.submissionset.sodar_uuid), "variant_assembly": "GRCh37", "variant_chromosome": self.submission.variant_chromosome, "variant_gene": self.submission.variant_gene, "variant_hgvs": self.submission.variant_hgvs, "variant_start": self.submission.variant_start, "variant_stop": self.submission.variant_stop, "variant_reference": re.compile(r"[ACGT]+$"), "variant_alternative": re.compile(r"[ACGT]+$"), }) expected.assert_matches(res_json[0])
"variant_hgvs": ["p.W23T"], "diseases": json.dumps([{ "term_id": "OMIM:1234567", "term_name": "Disease 1234567" }]), "submission_individuals": [], "submission_set": str(self.submission.submission_set.sodar_uuid), } with self.login(self.contributor_as.user): response = self.client.patch(url, data) self.assertEqual(response.status_code, 200) res_json = response.json() expected = jsonmatch.compile({ **data, "diseases": json.loads(data["diseases"]) }) expected.assert_matches(res_json) def test_destroy(self): url = reverse( "clinvar_export:ajax-submission-retrieve-update-destroy", kwargs={ "project": self.project.sodar_uuid, "submission": self.submission.sodar_uuid, }, ) with self.login(self.contributor_as.user): response = self.client.delete(url) self.assertEqual(response.status_code, 204) self.assertEqual(Submission.objects.count(), 0)