forked from Just249/DATA534_WebandCloudComputingProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_wrapperAPI_ingredientVeterinarySpecies.py
45 lines (32 loc) · 2.29 KB
/
test_wrapperAPI_ingredientVeterinarySpecies.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
import unittest
import pandas as pd
from api_wrapper.JCingredientVeterinarySpecies import ingredientVeterinarySpecies as ivs
from api_wrapper.JCingredientVeterinarySpecies import web_request as wr
from api_wrapper.JCingredientVeterinarySpecies import check_filter as cf
t1 = ivs("SULFAMETHAZINE","9ec4bb641b31ddeeb9bfd84908c8dbb1")
t2 = ivs("","9ec4bb641b31ddeeb9bfd84908c8dbb1")
class test_ingredientVeterinarySpecies(unittest.TestCase):
def setUp(self):
print("\n\033[1mThis is the setUp of test_jdrugconsumption.\n\n All good.")
self.key = "9ec4bb641b31ddeeb9bfd84908c8dbb1"
self.api1_url = "https://dpd-hc-sc-apicast-production.api.canada.ca/v1/activeingredient?lang=en&type=json"
self.wrong_api1_url = "https://dpd-hc-sc-apicast-production.api.canada.ca/v1"
self.filters = ['SULFAMETHAZINE']
self.filters_ids = [724]
self.id_with_ingredients = [724]
def tearDown(self):
print("\nThis is the tearDown of test_jdrugconsumption")
def test_ingredientVeterinarySpecies(self):
self.assertEqual(t2, 'There is no match for that brand name.')
self.assertEqual(str(type(t1)),"<class 'pandas.core.frame.DataFrame'>")
self.assertEqual(wr(self.key, self.wrong_api1_url),"The website did not respond, please try again!")
self.assertEqual(isinstance(cf(['SULFAMETHAZINE'],"9ec4bb641b31ddeeb9bfd84908c8dbb1",self.id_with_ingredients,self.filters_ids),pd.DataFrame), True)
self.assertEqual(cf([],"9ec4bb641b31ddeeb9bfd84908c8dbb1",self.id_with_ingredients,self.filters_ids), "There is no match for that brand name.")
self.assertEqual(isinstance(wr(self.key, self.api1_url), list), True)
self.assertEqual(isinstance(wr(self.key, self.wrong_api1_url), list), False)
# self.assertEqual(str(type(t2)),"<class 'NoneType'>")
self.assertEqual(isinstance(t1, pd.DataFrame), True)
self.assertEqual(isinstance(t2, pd.DataFrame), False)
self.assertAlmostEqual(t1.iloc[0,0], "Sulfamethazine")
self.assertAlmostEqual(str(ivs("","9ec4bb641b31ddeeb9bfd84908c8dbb1")), "There is no match for that brand name.")
unittest.main(argv=[''], verbosity=2, exit=False)