-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_obc_pubmed.py
47 lines (31 loc) · 1.27 KB
/
test_obc_pubmed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import unittest
import requests
import xml.etree.ElementTree as ET
from obc import PubmedArticle, sort_xml
class TestObcPubmed(unittest.TestCase):
PUBMED_XML_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id={}&rettype=xml"
PARSE_TEST_PMID = "27812667"
# a pmid from a publication that is returned by obc.ide api
OBC_IDE_TEST_PMID = "26890470"
def test_parse_doi_pmid(self):
expected = {"doi": "10.1590/0037-8682-0145-2016", "pmid": "27812667"}
res = requests.get(
self.PUBMED_XML_URL.format(self.PARSE_TEST_PMID)
).text
root = ET.fromstring(res)[0]
print(root)
article_obj = PubmedArticle(root)
self.assertEqual(article_obj.doi, expected["doi"])
self.assertEqual(article_obj.pmid, expected["pmid"])
def test_publication_in_obc(self):
# testing a pmid lookup
res = requests.get(self.PUBMED_XML_URL.format(self.OBC_IDE_TEST_PMID)).text
root = ET.fromstring(res)[0]
article_obj = PubmedArticle(root)
self.assertEqual(
article_obj.publication_in_obc(), True
)
def test_sort_xml(self):
in_obc, not_in_obc = sort_xml('real_output.xml')
print(len(in_obc))
print(len(not_in_obc))