|
| 1 | +"""Integration tests for the `fluview_meta` endpoint.""" |
| 2 | + |
| 3 | +# standard library |
| 4 | +import unittest |
| 5 | + |
| 6 | +# third party |
| 7 | +import mysql.connector |
| 8 | + |
| 9 | +# first party |
| 10 | +from delphi.epidata.client.delphi_epidata import Epidata |
| 11 | + |
| 12 | + |
| 13 | +class FluviewMetaTests(unittest.TestCase): |
| 14 | + """Tests the `fluview_meta` endpoint.""" |
| 15 | + |
| 16 | + @classmethod |
| 17 | + def setUpClass(cls): |
| 18 | + """Perform one-time setup.""" |
| 19 | + |
| 20 | + # use the local instance of the Epidata API |
| 21 | + Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php' |
| 22 | + |
| 23 | + def setUp(self): |
| 24 | + """Perform per-test setup.""" |
| 25 | + |
| 26 | + # connect to the `epidata` database and clear the `fluview` table |
| 27 | + cnx = mysql.connector.connect( |
| 28 | + user='user', |
| 29 | + password='pass', |
| 30 | + host='delphi_database_epidata', |
| 31 | + database='epidata') |
| 32 | + cur = cnx.cursor() |
| 33 | + cur.execute('truncate table fluview') |
| 34 | + cnx.commit() |
| 35 | + cur.close() |
| 36 | + |
| 37 | + # make connection and cursor available to test cases |
| 38 | + self.cnx = cnx |
| 39 | + self.cur = cnx.cursor() |
| 40 | + |
| 41 | + def tearDown(self): |
| 42 | + """Perform per-test teardown.""" |
| 43 | + self.cur.close() |
| 44 | + self.cnx.close() |
| 45 | + |
| 46 | + def test_round_trip(self): |
| 47 | + """Make a simple round-trip with some sample data.""" |
| 48 | + |
| 49 | + # insert dummy data |
| 50 | + self.cur.execute(''' |
| 51 | + insert into fluview values |
| 52 | + (0, "2020-04-07", 202021, 202020, "nat", 1, 2, 3, 4, 3.14159, 1.41421, |
| 53 | + 10, 11, 12, 13, 14, 15), |
| 54 | + (0, "2020-04-28", 202022, 202022, "hhs1", 5, 6, 7, 8, 1.11111, 2.22222, |
| 55 | + 20, 21, 22, 23, 24, 25) |
| 56 | + ''') |
| 57 | + self.cnx.commit() |
| 58 | + |
| 59 | + # make the request |
| 60 | + response = Epidata.fluview_meta() |
| 61 | + |
| 62 | + # assert that the right data came back |
| 63 | + self.assertEqual(response, { |
| 64 | + 'result': 1, |
| 65 | + 'epidata': [{ |
| 66 | + 'latest_update': '2020-04-28', |
| 67 | + 'latest_issue': 202022, |
| 68 | + 'table_rows': 2, |
| 69 | + }], |
| 70 | + 'message': 'success', |
| 71 | + }) |
0 commit comments