diff --git a/ippisite/ippidb/tests.py b/ippisite/ippidb/tests.py index ed1a17904e24745f18af1a925a7b71991ffd8fa4..ea26a69d260f2bf50664f5eb1efe1a5ad42ad574 100644 --- a/ippisite/ippidb/tests.py +++ b/ippisite/ippidb/tests.py @@ -13,8 +13,13 @@ from openbabel import vectorUnsignedInt, OBFingerprint from ippidb import ws, models from ippidb.ws import get_uniprot_info -from .models import Compound, CompoundTanimoto, create_tanimoto, \ - update_compound_cached_properties, Symmetry +from .models import ( + Compound, + CompoundTanimoto, + create_tanimoto, + update_compound_cached_properties, + Symmetry, +) from .models import DrugBankCompound from .utils import FingerPrinter, mol2smi, smi2mol, smi2inchi, smi2inchikey @@ -28,9 +33,11 @@ class MolSmiTestCase(TestCase): self.smiles = "C" # the MOL version is also a valid regexp to validate arbitrary name in # the openbabel-generated version - self.mol = "\n OpenBabel[0-9]{11}D\n\n 1 0 0 0 0 0 0 0 " \ - " 0 0999 V2000\n 1.0000 0.0000 0.0000 C 0 0 0 0 " \ + self.mol = ( + "\n OpenBabel[0-9]{11}D\n\n 1 0 0 0 0 0 0 0 " + " 0 0999 V2000\n 1.0000 0.0000 0.0000 C 0 0 0 0 " " 0 0 0 0 0 0 0 0\nM END\n" + ) def test_mol2smi(self): self.assertEqual(mol2smi(self.mol), self.smiles) @@ -45,11 +52,14 @@ class SmiInchi(TestCase): """ def setUp(self): - self.smiles_str = "CC(C)C(=O)C1=C(C(=C(C(=C1)C(=O)C2=CC=C(C=C2)" \ - "OC3=CC=CC=C3)O)O)O" - self.inchi_str = "InChI=1S/C23H20O6/c1-13(2)19(24)17-12-18(22" \ - "(27)23(28)21(17)26)20(25)14-8-10-16(11-9-14)29-15-6-4-3-" \ + self.smiles_str = ( + "CC(C)C(=O)C1=C(C(=C(C(=C1)C(=O)C2=CC=C(C=C2)" "OC3=CC=CC=C3)O)O)O" + ) + self.inchi_str = ( + "InChI=1S/C23H20O6/c1-13(2)19(24)17-12-18(22" + "(27)23(28)21(17)26)20(25)14-8-10-16(11-9-14)29-15-6-4-3-" "5-7-15/h3-13,26-28H,1-2H3" + ) self.inchikey_str = "CVVQMBDTMYUWTR-UHFFFAOYSA-N" def test_smi2inchi(self): @@ -67,21 +77,19 @@ class FingerPrinterTestCase(TestCase): def setUp(self): self.fingerprinter = FingerPrinter("FP4") self.smiles = "CC" - self.fp = vectorUnsignedInt([ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + self.fp = vectorUnsignedInt([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) self.smiles_dict = {1: "CC", 2: "CCC"} self.fp_dict = { - 1: vectorUnsignedInt([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0]), - 2: vectorUnsignedInt([3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0])} + 1: vectorUnsignedInt([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + 2: vectorUnsignedInt([3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + } self.tanimoto_dict = {1: 1.0, 2: 0.5} def test_fingerprints_available(self): # test that all necessary fingerprints are available - self.assertIsNotNone(OBFingerprint.FindFingerprint('FP2')) - self.assertIsNotNone(OBFingerprint.FindFingerprint('FP4')) - self.assertIsNotNone(OBFingerprint.FindFingerprint('ECFP4')) + self.assertIsNotNone(OBFingerprint.FindFingerprint("FP2")) + self.assertIsNotNone(OBFingerprint.FindFingerprint("FP4")) + self.assertIsNotNone(OBFingerprint.FindFingerprint("ECFP4")) def assertEqualVUI(self, vui_one, vui_two): return self.assertEqual(list(vui_one), list(vui_two)) @@ -95,33 +103,35 @@ class FingerPrinterTestCase(TestCase): self.assertEqualVUI(self.fingerprinter.fp(self.smiles), self.fp) def test_fp_dict(self): - self.assertEqualVUIdict(self.fingerprinter.fp_dict(self.smiles_dict), - self.fp_dict) + self.assertEqualVUIdict( + self.fingerprinter.fp_dict(self.smiles_dict), self.fp_dict + ) def test_tanimoto_fps(self): - self.assertEqual(self.fingerprinter.tanimoto_fps(self.smiles, - self.fp_dict), - self.tanimoto_dict) + self.assertEqual( + self.fingerprinter.tanimoto_fps(self.smiles, self.fp_dict), + self.tanimoto_dict, + ) def test_tanimoto_smiles(self): - self.assertEqual(self.fingerprinter.tanimoto_smiles(self.smiles, - self.smiles_dict), - self.tanimoto_dict) + self.assertEqual( + self.fingerprinter.tanimoto_smiles(self.smiles, self.smiles_dict), + self.tanimoto_dict, + ) class FingerPrinterTestCaseCompound1ECFP4(TestCase): - def setUp(self): self.fingerprinter = FingerPrinter("ECFP4") self.smiles = "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O" - self.smiles_dict = {1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)" - "c(O)c1O"} + self.smiles_dict = {1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)" "c(O)c1O"} self.tanimoto_dict = {1: 1.0} def test_tanimoto_smiles(self): - self.assertEqual(self.fingerprinter.tanimoto_smiles(self.smiles, - self.smiles_dict), - self.tanimoto_dict) + self.assertEqual( + self.fingerprinter.tanimoto_smiles(self.smiles, self.smiles_dict), + self.tanimoto_dict, + ) def create_dummy_compound(id_, smiles): @@ -179,13 +189,12 @@ def create_dummy_compound(id_, smiles): def create_dummy_drugbank_compound(id_, smiles): dbc = DrugBankCompound() dbc.id = id_ - dbc.common_name = 'DrugBankCompound' + str(id_) + dbc.common_name = "DrugBankCompound" + str(id_) dbc.canonical_smiles = smiles dbc.save() class CompoundTanimotoTestCase(TestCase): - def setUp(self): self.smiles_dict = {1: "CC", 2: "CCC"} self.query = "CC" @@ -201,12 +210,12 @@ class CompoundTanimotoTestCase(TestCase): class CompoundTanimotoTestCaseCompound1ECFP4(TestCase): - def setUp(self): self.smiles_dict = { 1: "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O", 2: "NC(=N)N[C@H](C1CCCCC1)C(=O)NCC(=O)N1CCC(CC1)c1cc(n[nH]1)" - "-c1ccc(Cl)cc1Cl"} + "-c1ccc(Cl)cc1Cl", + } self.query = "CC(C)C(=O)c1cc(C(=O)c2ccc(Oc3ccccc3)cc2)c(O)c(O)c1O" for id_, smiles in self.smiles_dict.items(): create_dummy_compound(id_, smiles) @@ -220,7 +229,6 @@ class CompoundTanimotoTestCaseCompound1ECFP4(TestCase): class CompoundAnnotationsTestCase(TestCase): - def test_lipinsky_ok(self): # c is ok for Lipinsky c = create_dummy_compound(1, "CC") @@ -327,20 +335,19 @@ class CompoundAnnotationsTestCase(TestCase): class QueryCompoundViewsTestCase(TestCase): - @classmethod def setUpTestData(cls): c = create_dummy_compound(1, "CC") c = create_dummy_compound(2, "CCC") - call_command('lle_le') - call_command('pca') + call_command("lle_le") + call_command("pca") def test_existing_compound(self): """ The detail view of an existing compound returns a 200 """ - url = reverse('compound_card', kwargs={'pk': 1}) + url = reverse("compound_card", kwargs={"pk": 1}) response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -349,7 +356,7 @@ class QueryCompoundViewsTestCase(TestCase): The detail view of a non-existing compound returns a 404 not found. """ - url = reverse('compound_card', kwargs={'pk': 9}) + url = reverse("compound_card", kwargs={"pk": 9}) response = self.client.get(url) self.assertEqual(response.status_code, 404) @@ -358,7 +365,7 @@ class QueryCompoundViewsTestCase(TestCase): The compounds list view returns a 200 """ - url = reverse('compound_list') + url = reverse("compound_list") response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -369,50 +376,60 @@ class TestGetDoiInfo(TestCase): """ def test_get_doi_info(self): - resp = ws.get_doi_info('10.1073/pnas.0805139105') - self.assertEqual(resp['title'], 'A quantitative atlas of mitotic' - ' phosphorylation') - self.assertEqual(resp['journal_name'], 'Proceedings of the National' - ' Academy of Sciences') - self.assertEqual(resp['biblio_year'], 2008) - self.assertEqual(resp['authors_list'], - 'Dephoure N., Zhou C., Villen J., Beausoleil S. A., ' - 'Bakalarski C. E., Elledge S. J., Gygi S. P.') + resp = ws.get_doi_info("10.1073/pnas.0805139105") + self.assertEqual( + resp["title"], "A quantitative atlas of mitotic" " phosphorylation" + ) + self.assertEqual( + resp["journal_name"], "Proceedings of the National" " Academy of Sciences" + ) + self.assertEqual(resp["biblio_year"], 2008) + self.assertEqual( + resp["authors_list"], + "Dephoure N., Zhou C., Villen J., Beausoleil S. A., " + "Bakalarski C. E., Elledge S. J., Gygi S. P.", + ) class TestGetPfamInfo(TestCase): def test_create_protein(self): - target = {'id': 'bZIP_1', 'description': 'bZIP transcription factor'} - resp = ws.get_pfam_info('PF00170') + target = {"id": "bZIP_1", "description": "bZIP transcription factor"} + resp = ws.get_pfam_info("PF00170") self.assertEqual(resp, target) class TestGetGooglePatentInfo(TestCase): def test_it(self): - target = {'title': 'Secure virtual machine bootstrap in untrusted' - ' cloud infrastructures', - 'journal_name': None, - 'biblio_year': '2010', - 'authors_list': 'Fabio R. Maino, Pere Monclus, David A.' - ' McGrew, Robert T. Bell, ' - 'Steven Joseph Rich, Cisco Technology Inc'} - resp = ws.get_google_patent_info('US8856504') + target = { + "title": "Secure virtual machine bootstrap in untrusted" + " cloud infrastructures", + "journal_name": None, + "biblio_year": "2010", + "authors_list": "Fabio R. Maino, Pere Monclus, David A." + " McGrew, Robert T. Bell, " + "Steven Joseph Rich, Cisco Technology Inc", + } + resp = ws.get_google_patent_info("US8856504") self.assertEqual(resp, target) def test_entry_not_found(self): - self.assertRaises(ws.PatentNotFound, ws.get_google_patent_info, - 'US8856504US8856504US885US8856504US8856504') + self.assertRaises( + ws.PatentNotFound, + ws.get_google_patent_info, + "US8856504US8856504US885US8856504US8856504", + ) class TestGetPubMEDIdInfo(TestCase): def test_create_protein(self): - target = {'title': 'Gene List significance at-a-glance with' - ' GeneValorization.', - 'journal_name': 'Bioinformatics (Oxford, England)', - 'biblio_year': '2011', - 'authors_list': 'Brancotte B, Biton A, Bernard-Pierrot I, ' - 'Radvanyi F, Reyal F, Cohen-Boulakia S'} - resp = ws.get_pubmed_info('21349868') + target = { + "title": "Gene List significance at-a-glance with" " GeneValorization.", + "journal_name": "Bioinformatics (Oxford, England)", + "biblio_year": "2011", + "authors_list": "Brancotte B, Biton A, Bernard-Pierrot I, " + "Radvanyi F, Reyal F, Cohen-Boulakia S", + } + resp = ws.get_pubmed_info("21349868") self.assertEqual(resp, target) @@ -422,66 +439,99 @@ class TestGetUniprotInfo(TestCase): """ def test_get_uniprot_info(self): - resp = get_uniprot_info('Q15286') - self.assertEqual(resp['recommended_name'], - 'Ras-related protein Rab-35') - self.assertEqual(resp['organism'], 9606) - self.assertEqual(resp['gene_id'], 11021) - exp_gene_names = [{'name': 'RAB35', 'type': 'primary'}, - {'name': 'RAB1C', 'type': 'synonym'}, - {'name': 'RAY', 'type': 'synonym'}] - self.assertEqual(sorted(resp['gene_names'], key=lambda k: k['name']), - sorted(exp_gene_names, key=lambda k: k['name'])) - self.assertEqual(resp['entry_name'], 'RAB35_HUMAN') - self.assertEqual(resp['short_name'], 'RAB35') - exp_molecular_functions = ['GO_0003924', 'GO_0005525', 'GO_0005546', - 'GO_0019003'] - self.assertEqual(sorted(resp['molecular_functions']), - sorted(exp_molecular_functions)) - exp_cellular_localisations = ['GO_0000139', 'GO_0005829', 'GO_0005886', - 'GO_0005905', 'GO_0010008', 'GO_0030665', - 'GO_0031253', 'GO_0042470', 'GO_0045171', - 'GO_0045334', 'GO_0055038', 'GO_0070062', - 'GO_0098993'] - self.assertEqual(sorted(resp['cellular_localisations']), - sorted(exp_cellular_localisations)) - exp_biological_processes = ['GO_0000281', 'GO_0006886', 'GO_0008104', - 'GO_0016197', 'GO_0019882', 'GO_0031175', - 'GO_0032456', 'GO_0032482', 'GO_0036010', - 'GO_0048227', 'GO_1990090'] - self.assertEqual(sorted(resp['biological_processes']), - sorted(exp_biological_processes)) - exp_accessions = ['Q15286', 'B2R6E0', 'B4E390'] - self.assertEqual(sorted(resp['accessions']), - sorted(exp_accessions)) + resp = get_uniprot_info("Q15286") + self.assertEqual(resp["recommended_name"], "Ras-related protein Rab-35") + self.assertEqual(resp["organism"], 9606) + self.assertEqual(resp["gene_id"], 11021) + exp_gene_names = [ + {"name": "RAB35", "type": "primary"}, + {"name": "RAB1C", "type": "synonym"}, + {"name": "RAY", "type": "synonym"}, + ] + self.assertEqual( + sorted(resp["gene_names"], key=lambda k: k["name"]), + sorted(exp_gene_names, key=lambda k: k["name"]), + ) + self.assertEqual(resp["entry_name"], "RAB35_HUMAN") + self.assertEqual(resp["short_name"], "RAB35") + exp_molecular_functions = [ + "GO_0003924", + "GO_0005525", + "GO_0005546", + "GO_0019003", + ] + self.assertEqual( + sorted(resp["molecular_functions"]), sorted(exp_molecular_functions) + ) + exp_cellular_localisations = [ + "GO_0000139", + "GO_0005829", + "GO_0005886", + "GO_0005905", + "GO_0010008", + "GO_0030665", + "GO_0031253", + "GO_0042470", + "GO_0045171", + "GO_0045334", + "GO_0055038", + "GO_0070062", + "GO_0098993", + ] + self.assertEqual( + sorted(resp["cellular_localisations"]), sorted(exp_cellular_localisations) + ) + exp_biological_processes = [ + "GO_0000281", + "GO_0006886", + "GO_0008104", + "GO_0016197", + "GO_0019882", + "GO_0031175", + "GO_0032456", + "GO_0032482", + "GO_0036010", + "GO_0048227", + "GO_1990090", + ] + self.assertEqual( + sorted(resp["biological_processes"]), sorted(exp_biological_processes) + ) + exp_accessions = ["Q15286", "B2R6E0", "B4E390"] + self.assertEqual(sorted(resp["accessions"]), sorted(exp_accessions)) exp_citations = [ - {'doi': '10.1006/bbrc.1994.2889', 'pmid': '7811277'}, - {'doi': '10.1038/ng1285', 'pmid': '14702039'}, - {'doi': '10.1038/nature04569', 'pmid': '16541075'}, - {'doi': '10.1101/gr.2596504', 'pmid': '15489334'}, - {'doi': '10.1016/j.cub.2006.07.020', 'pmid': '16950109'}, - {'doi': '10.1021/pr060363j', 'pmid': '17081065'}, - {'doi': '10.1074/jbc.M109.050930', 'pmid': '20154091'}, - {'doi': '10.1186/1752-0509-5-17', 'pmid': '21269460'}, - {'doi': '10.1038/nature10335', 'pmid': '21822290'}, - {'doi': '10.1038/emboj.2012.16', 'pmid': '22307087'}, - {'doi': '10.1111/j.1600-0854.2011.01294.x', 'pmid': '21951725'}, - {'doi': '10.1021/pr300630k', 'pmid': '23186163'}, - {'doi': '10.1002/pmic.201400617', 'pmid': '25944712'}, - {'doi': '10.1073/pnas.1110415108', 'pmid': '22065758'} + {"doi": "10.1006/bbrc.1994.2889", "pmid": "7811277"}, + {"doi": "10.1038/ng1285", "pmid": "14702039"}, + {"doi": "10.1038/nature04569", "pmid": "16541075"}, + {"doi": "10.1101/gr.2596504", "pmid": "15489334"}, + {"doi": "10.1016/j.cub.2006.07.020", "pmid": "16950109"}, + {"doi": "10.1021/pr060363j", "pmid": "17081065"}, + {"doi": "10.1074/jbc.M109.050930", "pmid": "20154091"}, + {"doi": "10.1186/1752-0509-5-17", "pmid": "21269460"}, + {"doi": "10.1038/nature10335", "pmid": "21822290"}, + {"doi": "10.1038/emboj.2012.16", "pmid": "22307087"}, + {"doi": "10.1111/j.1600-0854.2011.01294.x", "pmid": "21951725"}, + {"doi": "10.1021/pr300630k", "pmid": "23186163"}, + {"doi": "10.1002/pmic.201400617", "pmid": "25944712"}, + {"doi": "10.1073/pnas.1110415108", "pmid": "22065758"}, + ] + self.assertEqual( + sorted(exp_citations, key=lambda k: k["pmid"]), + sorted(resp["citations"], key=lambda k: k["pmid"]), + ) + exp_alternative_names = [ + {"full": "GTP-binding protein RAY"}, + {"full": "Ras-related protein Rab-1C"}, ] - self.assertEqual(sorted(exp_citations, key=lambda k: k['pmid']), - sorted(resp['citations'], key=lambda k: k['pmid'])) - exp_alternative_names = [{'full': 'GTP-binding protein RAY'}, - {'full': 'Ras-related protein Rab-1C'}] self.assertEqual( - sorted(exp_alternative_names, key=lambda k: k['full']), - sorted(resp['alternative_names'], key=lambda k: k['full'])) + sorted(exp_alternative_names, key=lambda k: k["full"]), + sorted(resp["alternative_names"], key=lambda k: k["full"]), + ) def test_get_uniprot_info_domains(self): - resp = get_uniprot_info('O00255') - exp_domains = ['PF05053'] - self.assertEqual(sorted(resp['domains']), sorted(exp_domains)) + resp = get_uniprot_info("O00255") + exp_domains = ["PF05053"] + self.assertEqual(sorted(resp["domains"]), sorted(exp_domains)) class TestGetPDBUniProtMapping(TestCase): @@ -490,15 +540,14 @@ class TestGetPDBUniProtMapping(TestCase): """ def test_find_info(self): - target = sorted(['Q03164', 'O00255']) - resp = ws.get_pdb_uniprot_mapping('3u85') + target = sorted(["Q03164", "O00255"]) + resp = ws.get_pdb_uniprot_mapping("3u85") resp = sorted(resp) self.assertEqual(resp, target) self.assertEqual(len(resp), len(set(resp))) def test_entry_not_found(self): - self.assertRaises(ws.EntryNotFoundError, ws.get_pdb_uniprot_mapping, - 'Xu85') + self.assertRaises(ws.EntryNotFoundError, ws.get_pdb_uniprot_mapping, "Xu85") class TestConvertIUPACToSMILESAndMore(TestCase): @@ -509,54 +558,53 @@ class TestConvertIUPACToSMILESAndMore(TestCase): def test_valid(self): pairs = [ ( - '2,4,6-trinitrotoluene', + "2,4,6-trinitrotoluene", { "inchi": "InChI=1/C7H5N3O6/c1-4-6(9(13)14)2-5(8(11)12)" - "3-7(4)10(15)16/h2-3H,1H3", + "3-7(4)10(15)16/h2-3H,1H3", "stdinchi": "InChI=1S/C7H5N3O6/c1-4-6(9(13)14)2-5(8(11)" - "12)3-7(4)10(15)16/h2-3H,1H3", + "12)3-7(4)10(15)16/h2-3H,1H3", "stdinchikey": "SPSSULHKWOKEEL-UHFFFAOYSA-N", "smiles": "[N+](=O)([O-])C1=C(C)C(=CC(=C1)[N+](=O)[O-])" - "[N+](=O)[O-]", - } + "[N+](=O)[O-]", + }, ), ( - '3-{1-oxo-6-[4-(piperidin-4-yl)butanamido]-2,3-dihydro-1H-' - 'isoindol-2-yl}propanoic acid', + "3-{1-oxo-6-[4-(piperidin-4-yl)butanamido]-2,3-dihydro-1H-" + "isoindol-2-yl}propanoic acid", { "inchi": "InChI=1/C20H27N3O4/c24-18(3-1-2-14-6-9-21-10-" - "7-14)22-16-5-4-15-13-23(11-8-19(25)26)20(27)17" - "(15)12-16/h4-5,12,14,21H,1-3,6-11,13H2,(H,22," - "24)(H,25,26)/f/h22,25H", + "7-14)22-16-5-4-15-13-23(11-8-19(25)26)20(27)17" + "(15)12-16/h4-5,12,14,21H,1-3,6-11,13H2,(H,22," + "24)(H,25,26)/f/h22,25H", "stdinchi": "InChI=1S/C20H27N3O4/c24-18(3-1-2-14-6-9-21" - "-10-7-14)22-16-5-4-15-13-23(11-8-19(25)26)" - "20(27)17(15)12-16/h4-5,12,14,21H,1-3,6-11," - "13H2,(H,22,24)(H,25,26)", + "-10-7-14)22-16-5-4-15-13-23(11-8-19(25)26)" + "20(27)17(15)12-16/h4-5,12,14,21H,1-3,6-11," + "13H2,(H,22,24)(H,25,26)", "stdinchikey": "HWRXVANHVCXVHA-UHFFFAOYSA-N", - "smiles": "O=C1N(CC2=CC=C(C=C12)NC(CCCC1CCNCC1)=O)CCC(=O)O" - } - - ) + "smiles": "O=C1N(CC2=CC=C(C=C12)NC(CCCC1CCNCC1)=O)CCC(=O)O", + }, + ), ] for iupac, dict_expected in pairs: dict_returned = ws.convert_iupac_to_smiles_and_inchi(iupac) self.assertEqual(dict_expected["smiles"], dict_returned["smiles"]) self.assertEqual(dict_expected["inchi"], dict_returned["inchi"]) - self.assertEqual(dict_expected["stdinchi"], - dict_returned["stdinchi"]) - self.assertEqual(dict_expected["stdinchikey"], - dict_returned["stdinchikey"]) + self.assertEqual(dict_expected["stdinchi"], dict_returned["stdinchi"]) + self.assertEqual(dict_expected["stdinchikey"], dict_returned["stdinchikey"]) def test_invalid_entry(self): - self.assertRaises(ws.EntryNotFoundError, - ws.convert_iupac_to_smiles_and_inchi, - '3-{1-oxo-6-[4-(piperid') - self.assertRaises(ws.EntryNotFoundError, - ws.convert_iupac_to_smiles_and_inchi, None) + self.assertRaises( + ws.EntryNotFoundError, + ws.convert_iupac_to_smiles_and_inchi, + "3-{1-oxo-6-[4-(piperid", + ) + self.assertRaises( + ws.EntryNotFoundError, ws.convert_iupac_to_smiles_and_inchi, None + ) class DuplicateGeneNameTestCase(TestCase): - def test_works(self): - models.Protein.objects.get_or_create(uniprot_id='P12497') - models.Protein.objects.get_or_create(uniprot_id='P0C6F2') + models.Protein.objects.get_or_create(uniprot_id="P12497") + models.Protein.objects.get_or_create(uniprot_id="P0C6F2") diff --git a/ippisite/ippidb/tests_contribute.py b/ippisite/ippidb/tests_contribute.py index 8a2bc3529db134cef0dc5b37b80a81ac4337816b..cab5e273c6fb3cfcc2750e6f03ca61fbcccecac8 100644 --- a/ippisite/ippidb/tests_contribute.py +++ b/ippisite/ippidb/tests_contribute.py @@ -20,21 +20,21 @@ class ContributionViewsTestCase(TestCase): """ def setUp(self): - login = 'contributor' - password = '12345' + login = "contributor" + password = "12345" User = get_user_model() User.objects.create_user(username=login, password=password) self.client.login(username=login, password=password) symmetry = models.Symmetry() - symmetry.code = 'AS' - symmetry.description = 'asymmetric' + symmetry.code = "AS" + symmetry.description = "asymmetric" symmetry.save() @staticmethod def get_step_url(step_id): - step_url = reverse('admin-session-add') + step_url = reverse("admin-session-add") if step_id is not None: - step_url += step_id+'/' + step_url += step_id + "/" return step_url def _process_contribution_wizard(self, wizard_data): @@ -43,162 +43,164 @@ class ContributionViewsTestCase(TestCase): returns a 200 """ for step in wizard_data: - step_url = self.get_step_url(step.get('step-id')) + step_url = self.get_step_url(step.get("step-id")) response = self.client.get(step_url) # post form data - if step.get('form-data') is not None: - err_msg = f"Response code not ok when getting form " \ + if step.get("form-data") is not None: + err_msg = ( + f"Response code not ok when getting form " f"for {step.get('step-id')} at {step_url}" + ) self.assertEqual(response.status_code, 200, err_msg) form_data = { - step['step-id'] + '-' + param_name: value - for param_name, value in step.get('form-data').items() - } - form_data['ippi_wizard-current_step'] = step['step-id'] + step["step-id"] + "-" + param_name: value + for param_name, value in step.get("form-data").items() + } + form_data["ippi_wizard-current_step"] = step["step-id"] response = self.client.post(step_url, form_data) if response.status_code != 302: file_path = self.write_in_tmp_file(response) - err_msg = f"Response code not ok when getting form for " \ - f"{step.get('step-id')} at {step_url}. Server" \ - f" response is stored in {file_path}" + err_msg = ( + f"Response code not ok when getting form for " + f"{step.get('step-id')} at {step_url}. Server" + f" response is stored in {file_path}" + ) self.assertEqual(response.status_code, 302, err_msg) # check redirect to next step (if there is one) - if step.get('next') is not None: - redirect_url = self.get_step_url(step.get('next')) + if step.get("next") is not None: + redirect_url = self.get_step_url(step.get("next")) self.assertEqual(response.url, redirect_url, step) def _generate_wizard_data(self, entry_data): """ Generate the wizard form data dynamically based on iPPI-DB entry data """ + def get_id_form(): return { - 'source': entry_data['source'], - 'id_source': entry_data['id_source'] + "source": entry_data["source"], + "id_source": entry_data["id_source"], } def get_bibliography_form(): return { - 'source': entry_data['source'], - 'id_source': entry_data['id_source'], - 'title': - 'Opportunistic+amoebae:+challenges' - '+in+prophylaxis+and+treatment.', - 'journal_name': 'Drug+resistance+updates+:+reviews+and+' - 'commentaries+in+antimicrobial+and+anticancer' - '+chemotherapy', - 'authors_list': 'Schuster+FL,+Visvesvara+GS', - 'biblio_year': '2004', - 'in_silico': 'on' + "source": entry_data["source"], + "id_source": entry_data["id_source"], + "title": "Opportunistic+amoebae:+challenges" + "+in+prophylaxis+and+treatment.", + "journal_name": "Drug+resistance+updates+:+reviews+and+" + "commentaries+in+antimicrobial+and+anticancer" + "+chemotherapy", + "authors_list": "Schuster+FL,+Visvesvara+GS", + "biblio_year": "2004", + "in_silico": "on", } def get_pdb_form(): - return { - 'pdb_id': entry_data['pdb_id'] - } + return {"pdb_id": entry_data["pdb_id"]} def get_complex_type_form(): - return { - 'complexType': 'Hetero2MerAB', - 'complexChoice': 'inhibited' - } + return {"complexType": "Hetero2MerAB", "complexChoice": "inhibited"} def get_complex_form(): data = { - 'TOTAL_FORMS': len(entry_data['complex']), - 'INITIAL_FORMS': len(entry_data['complex']), - 'MIN_NUM_FORMS': 0, - 'MAX_NUM_FORMS': 1000, + "TOTAL_FORMS": len(entry_data["complex"]), + "INITIAL_FORMS": len(entry_data["complex"]), + "MIN_NUM_FORMS": 0, + "MAX_NUM_FORMS": 1000, } - for idx, entry_complex in enumerate(entry_data['complex']): - data['{}-protein'.format(idx)] = models.Protein.objects.get( - uniprot_id=entry_complex['uniprot_id']).id - data['{}-complex_type'.format(idx)] = \ - entry_complex['complex_type'] - if entry_complex['domain_pfam_acc'] is not None: + for idx, entry_complex in enumerate(entry_data["complex"]): + data["{}-protein".format(idx)] = models.Protein.objects.get( + uniprot_id=entry_complex["uniprot_id"] + ).id + data["{}-complex_type".format(idx)] = entry_complex["complex_type"] + if entry_complex["domain_pfam_acc"] is not None: try: - data['{}-domain'.format(idx)] = \ - models.Domain.objects.get( - pfam_acc=entry_complex['domain_pfam_acc']).id + data["{}-domain".format(idx)] = models.Domain.objects.get( + pfam_acc=entry_complex["domain_pfam_acc"] + ).id except models.Domain.DoesNotExist as dne: - print('No domain in DB for PFAM ACC {}'.format( - entry_complex['domain_pfam_acc'])) + print( + "No domain in DB for PFAM ACC {}".format( + entry_complex["domain_pfam_acc"] + ) + ) raise dne else: - data['{}-domain'.format(idx)] = '' - data['{}-ppc_copy_nb'.format(idx)] = \ - entry_complex['ppc_copy_nb'] - data['{}-cc_nb'.format(idx)] = entry_complex['cc_nb'] - data['{}-ppp_copy_nb_per_p'.format(idx)] = \ - entry_complex['ppp_copy_nb_per_p'] + data["{}-domain".format(idx)] = "" + data["{}-ppc_copy_nb".format(idx)] = entry_complex["ppc_copy_nb"] + data["{}-cc_nb".format(idx)] = entry_complex["cc_nb"] + data["{}-ppp_copy_nb_per_p".format(idx)] = entry_complex[ + "ppp_copy_nb_per_p" + ] return data def get_ppi_form(): return { - 'family': '', - 'pdb_id': entry_data['pdb_id'], - 'family_name': entry_data['family_name'], - 'symmetry': 1, # FIXME - 'pockets_nb': 1, # FIXME - 'other_diseases': 'test', # FIXME + "family": "", + "pdb_id": entry_data["pdb_id"], + "family_name": entry_data["family_name"], + "symmetry": 1, # FIXME + "pockets_nb": 1, # FIXME + "other_diseases": "test", # FIXME } def get_compound_form(): return { - 'TOTAL_FORMS': 1, + "TOTAL_FORMS": 1, # FIXME there should be a way to list more than one compound - 'INITIAL_FORMS': 0, - 'MIN_NUM_FORMS': 1, - 'MAX_NUM_FORMS': 1000, - '0-common_name': entry_data['common_name'], - '0-compound_name': entry_data['compound_name'], - '0-molecule_smiles': entry_data['molecule_smiles'], + "INITIAL_FORMS": 0, + "MIN_NUM_FORMS": 1, + "MAX_NUM_FORMS": 1000, + "0-common_name": entry_data["common_name"], + "0-compound_name": entry_data["compound_name"], + "0-molecule_smiles": entry_data["molecule_smiles"], } def get_activity_description_form(): return { - 'TOTAL_FORMS': 0, - 'INITIAL_FORMS': 0, - 'MIN_NUM_FORMS': 0, - 'MAX_NUM_FORMS': 1000, + "TOTAL_FORMS": 0, + "INITIAL_FORMS": 0, + "MIN_NUM_FORMS": 0, + "MAX_NUM_FORMS": 1000, } def get_cytotox_description_form(): return { - 'TOTAL_FORMS': 0, - 'INITIAL_FORMS': 0, - 'MIN_NUM_FORMS': 0, - 'MAX_NUM_FORMS': 1000, + "TOTAL_FORMS": 0, + "INITIAL_FORMS": 0, + "MIN_NUM_FORMS": 0, + "MAX_NUM_FORMS": 1000, } def get_pk_description_form(): return { - 'TOTAL_FORMS': 0, - 'INITIAL_FORMS': 0, - 'MIN_NUM_FORMS': 0, - 'MAX_NUM_FORMS': 1000, + "TOTAL_FORMS": 0, + "INITIAL_FORMS": 0, + "MIN_NUM_FORMS": 0, + "MAX_NUM_FORMS": 1000, } form_callable = { None: lambda: None, - 'IdForm': get_id_form, - 'BibliographyForm': get_bibliography_form, - 'PDBForm': get_pdb_form, - 'ProteinDomainComplexTypeForm': get_complex_type_form, - 'ProteinDomainComplexForm': get_complex_form, - 'PpiForm': get_ppi_form, - 'CompoundForm': get_compound_form, - 'TestActivityDescriptionFormSet': get_activity_description_form, - 'TestCytotoxDescriptionFormSet': get_cytotox_description_form, - 'TestPKDescriptionFormSet': get_pk_description_form + "IdForm": get_id_form, + "BibliographyForm": get_bibliography_form, + "PDBForm": get_pdb_form, + "ProteinDomainComplexTypeForm": get_complex_type_form, + "ProteinDomainComplexForm": get_complex_form, + "PpiForm": get_ppi_form, + "CompoundForm": get_compound_form, + "TestActivityDescriptionFormSet": get_activity_description_form, + "TestCytotoxDescriptionFormSet": get_cytotox_description_form, + "TestPKDescriptionFormSet": get_pk_description_form, } form_ids = iter(list(form_callable.keys())[1:]) for step in form_callable.keys(): item = { - 'step-id': step, - 'form-data': form_callable[step](), - 'next': next(form_ids, None) - } + "step-id": step, + "form-data": form_callable[step](), + "next": next(form_ids, None), + } yield item def test_basic_entry(self): @@ -206,34 +208,34 @@ class ContributionViewsTestCase(TestCase): Basic entry test """ entry_data = { - 'source': 'PM', - 'id_source': '15072770', - 'in_silico': 'on', - 'pdb_id': '3u85', - 'complexChoice': 'inhibited', - 'complexType': 'Hetero2MerAB', - 'complex': [ + "source": "PM", + "id_source": "15072770", + "in_silico": "on", + "pdb_id": "3u85", + "complexChoice": "inhibited", + "complexType": "Hetero2MerAB", + "complex": [ { - 'uniprot_id': 'O00255', - 'complex_type': 'Partner', - 'domain_pfam_acc': 'PF05053', - 'ppc_copy_nb': 1, - 'cc_nb': 1, - 'ppp_copy_nb_per_p': '', + "uniprot_id": "O00255", + "complex_type": "Partner", + "domain_pfam_acc": "PF05053", + "ppc_copy_nb": 1, + "cc_nb": 1, + "ppp_copy_nb_per_p": "", }, { - 'uniprot_id': 'Q03164', - 'complex_type': 'Bound', - 'domain_pfam_acc': 'PF05965', - 'ppc_copy_nb': 1, - 'cc_nb': 1, - 'ppp_copy_nb_per_p': 1, + "uniprot_id": "Q03164", + "complex_type": "Bound", + "domain_pfam_acc": "PF05965", + "ppc_copy_nb": 1, + "cc_nb": 1, + "ppp_copy_nb_per_p": 1, }, ], - 'family_name': 'BCL2-Like+/+BAX', - 'molecule_smiles': 'CCC', - 'compound_name': 'toto', - 'common_name': 'super' + "family_name": "BCL2-Like+/+BAX", + "molecule_smiles": "CCC", + "compound_name": "toto", + "common_name": "super", } wizard_data = self._generate_wizard_data(entry_data) self._process_contribution_wizard(wizard_data) @@ -245,34 +247,34 @@ class ContributionViewsTestCase(TestCase): (see #77) """ entry_data = { - 'source': 'PM', - 'id_source': '26958703', - 'in_silico': 'on', - 'pdb_id': '3emh', - 'complexChoice': 'inhibited', - 'complexType': 'Hetero2MerAB', - 'complex': [ + "source": "PM", + "id_source": "26958703", + "in_silico": "on", + "pdb_id": "3emh", + "complexChoice": "inhibited", + "complexType": "Hetero2MerAB", + "complex": [ { - 'uniprot_id': 'P61964', - 'complex_type': 'Bound', - 'domain_pfam_acc': 'PF00400', - 'ppc_copy_nb': 1, - 'cc_nb': 1, - 'ppp_copy_nb_per_p': 1, + "uniprot_id": "P61964", + "complex_type": "Bound", + "domain_pfam_acc": "PF00400", + "ppc_copy_nb": 1, + "cc_nb": 1, + "ppp_copy_nb_per_p": 1, }, { - 'uniprot_id': 'Q03164', - 'complex_type': 'Partner', - 'domain_pfam_acc': None, - 'ppc_copy_nb': 1, - 'cc_nb': 1, - 'ppp_copy_nb_per_p': '', + "uniprot_id": "Q03164", + "complex_type": "Partner", + "domain_pfam_acc": None, + "ppc_copy_nb": 1, + "cc_nb": 1, + "ppp_copy_nb_per_p": "", }, ], - 'family_name': 'family', - 'molecule_smiles': 'C', - 'compound_name': 'toto', - 'common_name': 'super' + "family_name": "family", + "molecule_smiles": "C", + "compound_name": "toto", + "common_name": "super", } wizard_data = self._generate_wizard_data(entry_data) self._process_contribution_wizard(wizard_data)