def test_interaction_id_id_must_be_int(self, mock_json_retriever): mock_json_retriever.return_value = [ self.interaction_json, self.interaction_json ] target = Target(self.target_json) with self.assertRaises(TypeError): target.get_interaction_by_id("1")
def test_can_get_interactions(self, mock_json_retriever): mock_json_retriever.return_value = [self.interaction_json, self.interaction_json] target = Target(self.target_json) interactions = target.interactions() self.assertIsInstance(interactions, list) self.assertEqual(len(interactions), 2) for interaction in interactions: self.assertIsInstance(interaction, Interaction)
def test_can_get_interaction_by_id(self, mock_json_retriever): mock_json_retriever.return_value = [ self.interaction_json, self.interaction_json ] target = Target(self.target_json) interaction = target.get_interaction_by_id( self.interaction_json["interactionId"]) self.assertIsInstance(interaction, Interaction)
def test_can_get_subunits(self, mock_json_retriever): mock_json_retriever.return_value = self.target_json target = Target(self.target_json) subunits = target.subunits() self.assertIsInstance(subunits, list) self.assertEqual(len(subunits), len(self.target_json["subunitIds"])) for subunit in subunits: self.assertIsInstance(subunit, Target)
def test_can_get_complexes(self, mock_json_retriever): mock_json_retriever.return_value = self.target_json target = Target(self.target_json) complexes = target.complexes() self.assertIsInstance(complexes, list) self.assertEqual(len(complexes), len(self.target_json["complexIds"])) for complex_ in complexes: self.assertIsInstance(complex_, Target)
def test_synonym_properties(self, mock_json_retriever): mock_json_retriever.return_value = [ {"name": "ADRBRL1", "refs": []}, {"name": "5-HT1A", "refs": []} ] target = Target(self.target_json) self.assertEqual(target.synonyms(), ["ADRBRL1", "5-HT1A"])
def test_can_get_uniprot_pdbs_when_no_results(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = [ {"accession": "10576", "database": "UniProtKB", "species": "Human", "url":"http"} ] mock_xml_retriever.return_value = None target = Target(self.target_json) pdbs = target.uniprot_pdbs() self.assertEqual(pdbs, [])
def test_species_gene_properties(self, mock_json_retriever): mock_json_retriever.return_value = self.gene_json target = Target(self.target_json) genes = target.genes(species="mouse") self.assertEqual(len(genes), 1) self.assertIsInstance(genes[0], Gene) self.assertEqual(genes[0].gene_symbol(), "Kcnma1") self.assertEqual(genes[0].species(), "Mouse")
def test_species_database_properties(self, mock_json_retriever): mock_json_retriever.return_value = self.database_json target = Target(self.target_json) links = target.database_links(species="mouse") self.assertEqual(len(links), 1) self.assertIsInstance(links[0], DatabaseLink) self.assertEqual(links[0].accession(), "11863") self.assertEqual(links[0].species(), "Mouse")
def test_can_get_uniprot_pdbs_by_species(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = [ {"accession": "10576", "database": "UniProtKB", "species": "Human", "url":"http"}, {"accession": "10576", "database": "UniProtKB", "species": "Rat", "url":"http"} ] mock_xml_retriever.side_effect = [["2XG3", "3A1I"], ["1xxx"]] target = Target(self.target_json) pdbs = target.uniprot_pdbs(species="rat") self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_can_get_ligands(self, mock_json_retriever): mock_json_retriever.side_effect = [[ self.interaction_json, self.interaction_json ], self.ligand_json, self.ligand_json] target = Target(self.target_json) ligands = target.ligands() self.assertIsInstance(ligands, list) self.assertEqual(len(ligands), 2) for ligand in ligands: self.assertIsInstance(ligand, Ligand)
def test_can_get_ligands(self, mock_json_retriever): mock_json_retriever.side_effect = [ [self.interaction_json, self.interaction_json], self.ligand_json, self.ligand_json ] target = Target(self.target_json) ligands = target.ligands() self.assertIsInstance(ligands, list) self.assertEqual(len(ligands), 2) for ligand in ligands: self.assertIsInstance(ligand, Ligand)
def test_basic_property_methods(self): target = Target(self.target_json) self.assertIs(target._target_id, target.target_id()) self.assertIs(target._name, target.name()) self.assertIs(target._abbreviation, target.abbreviation()) self.assertIs(target._systematic_name, target.systematic_name()) self.assertIs(target._target_type, target.target_type()) self.assertIs(target._family_ids, target.family_ids()) self.assertIs(target._subunit_ids, target.subunit_ids()) self.assertIs(target._complex_ids, target.complex_ids())
def test_can_get_interactions(self, mock_json_retriever): mock_json_retriever.return_value = [ self.interaction_json, self.interaction_json ] target = Target(self.target_json) interactions = target.interactions() self.assertIsInstance(interactions, list) self.assertEqual(len(interactions), 2) for interaction in interactions: self.assertIsInstance(interaction, Interaction)
def test_database_properties(self, mock_json_retriever): mock_json_retriever.return_value = self.database_json target = Target(self.target_json) self.assertEqual(len(target.database_links()), 2) self.assertIsInstance(target.database_links()[0], DatabaseLink) self.assertIsInstance(target.database_links()[1], DatabaseLink) self.assertEqual(target.database_links()[0].accession(), "10576") self.assertEqual(target.database_links()[1].accession(), "11863") self.assertEqual(target.database_links()[0].species(), "Rat") self.assertEqual(target.database_links()[1].species(), "Mouse")
def test_can_get_all_pdbs(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.side_effect = [ self.pdb_json, [{"accession": "10576", "database": "UniProtKB", "species": "Human", "url":"http"}] ] mock_xml_retriever.return_value = ["2XG3", "3A1I"] target = Target(self.target_json) pdbs = target.all_pdbs() self.assertEqual(len(pdbs), 4) for code in ["4IAQ", "4IAR", "2XG3", "3A1I"]: self.assertIn(code, pdbs)
def test_synonym_properties(self, mock_json_retriever): mock_json_retriever.return_value = [{ "name": "ADRBRL1", "refs": [] }, { "name": "5-HT1A", "refs": [] }] target = Target(self.target_json) self.assertEqual(target.synonyms(), ["ADRBRL1", "5-HT1A"])
def test_can_get_uniprot_pdbs_when_no_results(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = [{ "accession": "10576", "database": "UniProtKB", "species": "Human", "url": "http" }] mock_xml_retriever.return_value = None target = Target(self.target_json) pdbs = target.uniprot_pdbs() self.assertEqual(pdbs, [])
def test_can_get_families(self, mock_json_retriever): mock_json_retriever.return_value = { "familyId": 1, "name": "5-Hydroxytryptamine receptors", "targetIds": [1, 2, 5], "parentFamilyIds": [694], "subFamilyIds": [9] } target = Target(self.target_json) families = target.families() self.assertIsInstance(families, list) self.assertEqual(len(families), len(self.target_json["familyIds"])) for family in families: self.assertIsInstance(family, TargetFamily)
def test_can_get_all_pdbs(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.side_effect = [ self.pdb_json, [{ "accession": "10576", "database": "UniProtKB", "species": "Human", "url": "http" }] ] mock_xml_retriever.return_value = ["2XG3", "3A1I"] target = Target(self.target_json) pdbs = target.all_pdbs() self.assertEqual(len(pdbs), 4) for code in ["4IAQ", "4IAR", "2XG3", "3A1I"]: self.assertIn(code, pdbs)
def test_can_get_uniprot_pdbs_by_species(self, mock_xml_retriever, mock_json_retriever): mock_json_retriever.return_value = [{ "accession": "10576", "database": "UniProtKB", "species": "Human", "url": "http" }, { "accession": "10576", "database": "UniProtKB", "species": "Rat", "url": "http" }] mock_xml_retriever.side_effect = [["2XG3", "3A1I"], ["1xxx"]] target = Target(self.target_json) pdbs = target.uniprot_pdbs(species="rat") self.assertEqual(pdbs, ["2XG3", "3A1I"])
def test_can_create_target(self): target = Target(self.target_json) self.assertEqual(target.json_data, self.target_json) self.assertEqual(target._target_id, 1) self.assertEqual(target._name, "5-HT<sub>1A</sub> receptor") self.assertEqual(target._abbreviation, "5-HT") self.assertEqual(target._systematic_name, None) self.assertEqual(target._target_type, "GPCR") self.assertEqual(target._family_ids, [1]) self.assertEqual(target._subunit_ids, [2, 3]) self.assertEqual(target._complex_ids, [4])
def test_gene_properties(self, mock_json_retriever): mock_json_retriever.return_value = self.gene_json target = Target(self.target_json) self.assertEqual(len(target.genes()), 3) self.assertIsInstance(target.genes()[0], Gene) self.assertIsInstance(target.genes()[1], Gene) self.assertIsInstance(target.genes()[2], Gene) self.assertEqual(target.genes()[0].gene_symbol(), "KCNMA1") self.assertEqual(target.genes()[1].gene_symbol(), "Kcnma1") self.assertEqual(target.genes()[2].gene_symbol(), "Kcnma2")
def test_can_get_gtop_pdbs_by_species(self, mock_json_retriever): mock_json_retriever.return_value = self.pdb_json target = Target(self.target_json) pdbs = target.gtop_pdbs(species="rat") self.assertEqual(pdbs, ["4IAR"])
def test_gtop_pdbs_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None target = Target(self.target_json) self.assertEqual(target.gtop_pdbs(), [])
def test_gene_properties_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None target = Target(self.target_json) self.assertEqual(target.genes(), [])
def test_interactions_when_no_json(self, mock_json_retriever): mock_json_retriever.return_value = None target = Target(self.target_json) self.assertEqual(target.interactions(), [])
def test_cannot_get_interaction_by_invalid_id(self, mock_json_retriever): mock_json_retriever.return_value = None target = Target(self.target_json) with self.assertRaises(exceptions.NoSuchInteractionError): interaction = target.get_interaction_by_id(0)
def test_interaction_id_id_must_be_int(self, mock_json_retriever): mock_json_retriever.return_value =[self.interaction_json, self.interaction_json] target = Target(self.target_json) with self.assertRaises(TypeError): target.get_interaction_by_id("1")
def test_target_repr(self): target = Target(self.target_json) self.assertEqual(str(target), "<Target 1 (5-HT<sub>1A</sub> receptor)>")
def test_can_get_interaction_by_id(self, mock_json_retriever): mock_json_retriever.return_value = [self.interaction_json, self.interaction_json] target = Target(self.target_json) interaction = target.get_interaction_by_id(self.interaction_json["interactionId"]) self.assertIsInstance(interaction, Interaction)