コード例 #1
0
    def test_unfound_names_return_0(self, mock_get):
        """If we can't find an NCBI taxonomy ID for an organism name
        we can keep things moving for a while without it.
        get_taxonomy_id will log an error message which will prompt
        a developer to investigate what the organism name that was
        unable to be found is. Therefore setting the ID to 0 is the
        right thing to do in this case despite not seeming like it.
        """
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.text = ESEARCH_NOT_FOUND_XML

        taxonomy_id = Organism.get_id_for_name("blah")

        self.assertEqual(taxonomy_id, 0)
        mock_get.assert_has_calls([
            call(ESEARCH_URL, {
                "db": "taxonomy",
                "field": "scin",
                "term": "BLAH"
            }),
            call(ESEARCH_URL, {
                "db": "taxonomy",
                "term": "BLAH"
            })
        ])

        # 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_id = Organism.get_id_for_name("BLAH")

        self.assertEqual(new_id, 0)
        mock_get.assert_not_called()
コード例 #2
0
    def test_uncached_other_names_are_found(self, mock_get):
        mock_get.side_effect = mocked_requests_get

        taxonomy_id = Organism.get_id_for_name("Human")

        self.assertEqual(taxonomy_id, 9606)
        mock_get.assert_has_calls([
            call(ESEARCH_URL, {
                "db": "taxonomy",
                "field": "scin",
                "term": "HUMAN"
            }),
            call(ESEARCH_URL, {
                "db": "taxonomy",
                "term": "HUMAN"
            })
        ])

        # 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_id = Organism.get_id_for_name("Human")

        self.assertEqual(new_id, 9606)
        mock_get.assert_not_called()
コード例 #3
0
    def test_unfound_names_raise(self, mock_get):
        """If we can't find the taxonomy id, it's likely a bad organism name.
        """
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.text = ESEARCH_NOT_FOUND_XML

        with self.assertRaises(UnknownOrganismId):
            Organism.get_id_for_name("blah")

        mock_get.assert_has_calls(
            [
                call(
                    ESEARCH_URL,
                    {
                        "db": "taxonomy",
                        "field": "scin",
                        "api_key": "3a1f8d818b0aa05d1aa3c334fa2cc9a17e09",
                        "term": "BLAH",
                    },
                ),
                call(
                    ESEARCH_URL,
                    {
                        "db": "taxonomy",
                        "api_key": "3a1f8d818b0aa05d1aa3c334fa2cc9a17e09",
                        "term": "BLAH",
                    },
                ),
            ]
        )
コード例 #4
0
    def test_cached_ids_are_found(self, mock_get):
        Organism.objects.create(name="HOMO_SAPIENS", taxonomy_id=9606, is_scientific_name=True)

        id = Organism.get_id_for_name("H**o Sapiens")

        self.assertEqual(id, 9606)
        mock_get.assert_not_called()
コード例 #5
0
    def test_uncached_scientific_names_are_found(self, mock_get):
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.text = ESEARCH_RESPONSE_XML

        taxonomy_id = Organism.get_id_for_name("H**o Sapiens")

        self.assertEqual(taxonomy_id, 9606)
        mock_get.assert_called_once_with(ESEARCH_URL, {
            "db": "taxonomy",
            "field": "scin",
            "term": "HOMO_SAPIENS"
        })

        # 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_id = Organism.get_id_for_name("H**o Sapiens")

        self.assertEqual(new_id, 9606)
        mock_get.assert_not_called()