def test_cached_names_are_found(self, mock_get): Organism.objects.create(name="HOMO_SAPIENS", taxonomy_id=9606, is_scientific_name=True) name = Organism.get_name_for_id(9606) self.assertEqual(name, "HOMO_SAPIENS") mock_get.assert_not_called()
def test_uncached_ids_are_found(self, mock_get): mock_get.return_value = Mock(ok=True) mock_get.return_value.text = EFETCH_RESPONSE_XML organism_name = Organism.get_name_for_id(9606) self.assertEqual(organism_name, "HOMO_SAPIENS") mock_get.assert_called_once_with(EFETCH_URL, { "db": "taxonomy", "id": "9606" }) # The first call should have stored the organism record in the # database so this call should not make a request. mock_get.reset_mock() new_name = Organism.get_name_for_id(9606) self.assertEqual(new_name, "HOMO_SAPIENS") mock_get.assert_not_called()
def test_invalid_ids_cause_exceptions(self, mock_get): mock_get.return_value = Mock(ok=True) mock_get.return_value.text = EFETCH_NOT_FOUND_XML with self.assertRaises(InvalidNCBITaxonomyId): Organism.get_name_for_id(0)