-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: rate limiting tests to NCBI Entrez
- Loading branch information
Showing
1 changed file
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,15 @@ | |
import Bio.Entrez | ||
import ftplib | ||
import os | ||
import random | ||
import shutil | ||
import string | ||
import tempfile | ||
import time | ||
import unittest | ||
|
||
Bio.Entrez.email = '[email protected]' | ||
email_suffix = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(8)) | ||
Bio.Entrez.email = 'biosimulators.daemon-{}@gmail.com'.format(email_suffix) | ||
|
||
|
||
class RefUtilsTestCase(unittest.TestCase): | ||
|
@@ -19,7 +23,10 @@ def tearDown(self): | |
|
||
def test_search_entrez_records(self): | ||
self.assertEqual(utils.search_entrez_records('pmc', '23184105[pmid]')['IdList'], ['5813803']) | ||
time.sleep(1) | ||
|
||
self.assertEqual(utils.search_entrez_records('pmc', 'abc[pmid]')['Count'], '0') | ||
time.sleep(1) | ||
|
||
with self.assertRaisesRegex(TypeError, 'must be a non-empty string'): | ||
utils.search_entrez_records('pmc', None) | ||
|
@@ -30,6 +37,7 @@ def test_search_entrez_records(self): | |
|
||
def test_get_entrez_record(self): | ||
self.assertEqual(utils.get_entrez_record('pmc', '5813803')['Id'], '5813803') | ||
time.sleep(1) | ||
|
||
with self.assertRaisesRegex(ValueError, 'is not a valid id'): | ||
utils.get_entrez_record('pubmed', 'abc') | ||
|
@@ -39,38 +47,54 @@ def test_get_entrez_record(self): | |
|
||
def test_get_pubmed_central_id(self): | ||
self.assertEqual(utils.get_pubmed_central_id('23184105'), 'PMC5813803') | ||
time.sleep(1) | ||
|
||
self.assertEqual(utils.get_pubmed_central_id('1234'), None) | ||
time.sleep(1) | ||
|
||
self.assertEqual(utils.get_pubmed_central_id(1234), None) | ||
time.sleep(1) | ||
|
||
self.assertEqual(utils.get_pubmed_central_id('abc'), None) | ||
time.sleep(1) | ||
|
||
self.assertEqual(utils.get_pubmed_central_id(None), None) | ||
time.sleep(1) | ||
|
||
def test_get_reference_from_pubmed(self): | ||
ref = utils.get_reference_from_pubmed('1234') | ||
self.assertEqual(ref.journal, 'Drug metabolism and disposition: the biological fate of chemicals') | ||
self.assertEqual(ref.year, '1975') | ||
time.sleep(1) | ||
|
||
ref = utils.get_reference_from_pubmed('23184105') | ||
self.assertEqual(ref.year, '2012') | ||
self.assertEqual(ref.pubmed_central_id, 'PMC5813803') | ||
self.assertEqual(ref.doi, '10.1542/peds.2012-2758') | ||
time.sleep(1) | ||
|
||
ref = utils.get_reference_from_pubmed(pubmed_id=None, doi='10.1542/peds.2012-2758') | ||
self.assertEqual(ref.year, '2012') | ||
self.assertEqual(ref.pubmed_id, '23184105') | ||
self.assertEqual(ref.pubmed_central_id, 'PMC5813803') | ||
self.assertEqual(ref.doi, '10.1542/peds.2012-2758') | ||
time.sleep(1) | ||
|
||
ref = utils.get_reference_from_pubmed(pubmed_id=None, doi='10.1103/PhysRevLett.127.104301x') | ||
self.assertEqual(ref, None) | ||
time.sleep(1) | ||
|
||
ref = utils.get_reference_from_pubmed(None, None) | ||
self.assertEqual(ref, None) | ||
time.sleep(1) | ||
|
||
with self.assertRaisesRegex(ValueError, 'not a valid id'): | ||
utils.get_reference_from_pubmed(pubmed_id='abc') | ||
time.sleep(1) | ||
|
||
with self.assertRaises(ValueError): | ||
utils.get_reference_from_pubmed('000') | ||
time.sleep(1) | ||
|
||
def test_get_reference_from_crossref(self): | ||
ref = utils.get_reference_from_crossref('10.1542/peds.2012-2758') | ||
|
@@ -109,6 +133,7 @@ def test_get_reference(self): | |
self.assertEqual(ref.pubmed_id, '23184105') | ||
self.assertEqual(ref.pubmed_central_id, 'PMC5813803') | ||
self.assertEqual(ref.doi, '10.1542/peds.2012-2758') | ||
time.sleep(1) | ||
|
||
ref = utils.get_reference(doi='10.1542/peds.2012-2758') | ||
self.assertIn(ref.authors, authors) | ||
|
@@ -117,9 +142,11 @@ def test_get_reference(self): | |
self.assertEqual(ref.pubmed_id, '23184105') | ||
self.assertEqual(ref.pubmed_central_id, 'PMC5813803') | ||
self.assertEqual(ref.doi, '10.1542/peds.2012-2758') | ||
time.sleep(1) | ||
|
||
ref = utils.get_reference(pubmed_id='1234') | ||
self.assertEqual(ref.doi, None) | ||
time.sleep(1) | ||
|
||
with self.assertRaises(ValueError): | ||
utils.get_reference() | ||
|