-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_other_API.py
72 lines (54 loc) · 2.79 KB
/
test_other_API.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import unittest, time
from simple_icd_11 import ICDOtherAPIClient, ICDExplorer, ProxyEntity
url = "http://localhost/"
# Class for testing the API client for unofficial deployments
class TestICDOtherAPIClient(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.client = ICDOtherAPIClient(url)
def testWrongUrl(self):
with self.assertRaises(ConnectionError):
ICDOtherAPIClient("website.invalid")
def testLookupCodeOk(self):
json_dict = self.client.lookupCode("1F0Y","2024-01","en")
self.assertEqual(json_dict["code"],"1F0Y")
self.assertEqual(json_dict["@id"],"http://id.who.int/icd/release/11/2024-01/mms/1646490591/other")
def testLookupCodeNotExists(self):
with self.assertRaises(LookupError):
self.client.lookupCode("banana","2024-01","en")
def testLookupIdOk(self):
json_dict = self.client.lookupId("218513628","2024-01","en")
self.assertEqual(json_dict["code"],"9B71.1")
self.assertEqual(json_dict["@id"],"http://id.who.int/icd/release/11/2024-01/mms/218513628")
def testLookupIdNotExists(self):
with self.assertRaises(LookupError):
self.client.lookupId("5","2024-01","en")
def testGetLatestReleaseOk(self): #needs to be updated when new release comes out
self.assertEqual(self.client.getLatestRelease("en"),"2024-01")
def testGetLatestReleaseWrongLanguage(self):
with self.assertRaises(LookupError):
self.client.getLatestRelease("onion")
def testCheckReleaseTrue(self):
self.assertTrue(self.client.checkRelease("2024-01","en"))
def testCheckReleaseFalse(self):
self.assertFalse(self.client.checkRelease("3124-01","en"))
def testNoDuplicateInstances(self):
t = ICDOtherAPIClient(url)
self.assertTrue(self.client is t)
def testGetBrowserUrl(self):
explorer = ICDExplorer("en","","",release="2024-01",customUrl=url)
e = explorer.getEntityFromCode("V")
self.assertEqual(e.getBrowserUrl(),"http://localhost/browse/2024-01/mms/en#231358748")
e = explorer.getEntityFromId("2091156678")
self.assertEqual(e.getBrowserUrl(),"http://localhost/browse/2024-01/mms/en#2091156678")
class TestProxyEntity(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.explorer = ICDExplorer("en","","",release="2024-01",customUrl=url)
def testNoLookup(self):
fake_uri = "it.wikipedia.org/wiki/Convento_dei_Domenicani_(Pordenone)"
prx = ProxyEntity(self.explorer,"557175275",fake_uri)
self.assertEqual(prx.getURI(),fake_uri)
def testDoesLookup(self):
prx = ProxyEntity(self.explorer,"557175275","icd.who.int/browse/2024-01/mms/557175275")
self.assertEqual(prx.getCode(),"8B25.4")