From 1564805dc7188a9c716ba00a3f9d3f5612386305 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Thu, 20 Jul 2023 18:03:24 +0300 Subject: [PATCH 01/14] Added basic integration tests for all endpoints --- integrations/server/test_cdc.py | 86 ++++++++++++ integrations/server/test_delphi.py | 97 +++++++++++++ integrations/server/test_dengue_nowcast.py | 84 ++++++++++++ integrations/server/test_dengue_sensors.py | 90 +++++++++++++ integrations/server/test_ecdc_ili.py | 75 +++++++++++ integrations/server/test_flusurv.py | 80 +++++++++++ integrations/server/test_fluview_clinical.py | 80 +++++++++++ integrations/server/test_gft.py | 62 +++++++++ integrations/server/test_ght.py | 67 +++++++++ integrations/server/test_kcdc_ili.py | 75 +++++++++++ integrations/server/test_meta.py | 72 ++++++++++ integrations/server/test_meta_norostat.py | 135 +++++++++++++++++++ integrations/server/test_nidss_dengue.py | 62 +++++++++ integrations/server/test_nidss_flu.py | 76 +++++++++++ integrations/server/test_norostat.py | 93 +++++++++++++ integrations/server/test_nowcast.py | 66 +++++++++ integrations/server/test_paho_dengue.py | 80 +++++++++++ integrations/server/test_quidel.py | 67 +++++++++ integrations/server/test_sensors.py | 71 ++++++++++ integrations/server/test_signal_dashboard.py | 102 ++++++++++++++ integrations/server/test_twitter.py | 71 ++++++++++ integrations/server/test_wiki.py | 72 ++++++++++ 22 files changed, 1763 insertions(+) create mode 100644 integrations/server/test_cdc.py create mode 100644 integrations/server/test_delphi.py create mode 100644 integrations/server/test_dengue_nowcast.py create mode 100644 integrations/server/test_dengue_sensors.py create mode 100644 integrations/server/test_ecdc_ili.py create mode 100644 integrations/server/test_flusurv.py create mode 100644 integrations/server/test_fluview_clinical.py create mode 100644 integrations/server/test_gft.py create mode 100644 integrations/server/test_ght.py create mode 100644 integrations/server/test_kcdc_ili.py create mode 100644 integrations/server/test_meta.py create mode 100644 integrations/server/test_meta_norostat.py create mode 100644 integrations/server/test_nidss_dengue.py create mode 100644 integrations/server/test_nidss_flu.py create mode 100644 integrations/server/test_norostat.py create mode 100644 integrations/server/test_nowcast.py create mode 100644 integrations/server/test_paho_dengue.py create mode 100644 integrations/server/test_quidel.py create mode 100644 integrations/server/test_sensors.py create mode 100644 integrations/server/test_signal_dashboard.py create mode 100644 integrations/server/test_twitter.py create mode 100644 integrations/server/test_wiki.py diff --git a/integrations/server/test_cdc.py b/integrations/server/test_cdc.py new file mode 100644 index 000000000..2b81d562c --- /dev/null +++ b/integrations/server/test_cdc.py @@ -0,0 +1,86 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class CdcTest(unittest.TestCase): + """Basic integration tests for cdc endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + cur.execute("TRUNCATE TABLE cdc_extract") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("cdc_key", "cdc_email")') + cur.execute('INSERT INTO user_role(name) VALUES("cdc") ON DUPLICATE KEY UPDATE name="cdc"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="cdc_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_cdc(self): + """Basic integration test for cdc endpoint""" + self.cur.execute( + "INSERT INTO cdc_extract(epiweek, state, num1, num2, num3, num4, num5, num6, num7, num8, total) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + ("201102", "AK", "16", "35", "51", "96", "30", "748", "243", "433", "65"), + ) + self.cnx.commit() + response = Epidata.cdc(auth="cdc_key", epiweeks=201102, locations="cen9") + self.assertEqual( + response, + { + "epidata": [ + { + "location": "cen9", + "epiweek": 201102, + "num1": 16, + "num2": 35, + "num3": 51, + "num4": 96, + "num5": 30, + "num6": 748, + "num7": 243, + "num8": 433, + "total": 65, + "value": None, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_delphi.py b/integrations/server/test_delphi.py new file mode 100644 index 000000000..ee6780cd9 --- /dev/null +++ b/integrations/server/test_delphi.py @@ -0,0 +1,97 @@ +# standard library +import unittest + +# third party +import mysql.connector +import json + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class DelphiTest(unittest.TestCase): + """Basic integration tests for delphi endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE forecasts") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_delphi(self): + """Basic integration test for delphi endpoint""" + self.cur.execute( + "INSERT INTO forecasts (`system`, `epiweek`, `json`) VALUES(%s, %s, %s)", + ( + "eb", + "201441", + json.dumps( + { + "_version": "version", + "name": "name", + "season": "season", + "epiweek": "epiweek", + "year_weeks": 222, + "season_weeks": 111, + "ili_bins": "ili_bins_123", + "ili_bin_size": "ili_bin_size231", + } + ), + ), + ) + self.cnx.commit() + response = Epidata.delphi(system="eb", epiweek=201441) + self.assertEqual( + response, + { + "epidata": [ + { + "epiweek": 201441, + "forecast": { + "_version": "version", + "epiweek": "epiweek", + "ili_bin_size": "ili_bin_size231", + "ili_bins": "ili_bins_123", + "name": "name", + "season": "season", + "season_weeks": 111, + "year_weeks": 222, + }, + "system": "eb", + } + ], + "message": "success", + "result": 1, + }, + ) diff --git a/integrations/server/test_dengue_nowcast.py b/integrations/server/test_dengue_nowcast.py new file mode 100644 index 000000000..de40ae5c3 --- /dev/null +++ b/integrations/server/test_dengue_nowcast.py @@ -0,0 +1,84 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class DengueNowcastTest(unittest.TestCase): + """Basic integration tests for dengue_nowcast endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `dengue_nowcasts` ( + `id` int NOT NULL AUTO_INCREMENT, + `target` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `epiweek` int NOT NULL, + `location` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `value` float NOT NULL, + `std` float NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `entry` (`target`,`epiweek`,`location`), + KEY `target` (`target`), + KEY `epiweek` (`epiweek`), + KEY `location` (`location`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE dengue_nowcasts") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_dengue_nowcasts(self): + """Basic integration test for dengue_nowcasts endpoint""" + self.cur.execute( + "INSERT INTO dengue_nowcasts(target, epiweek, location, value, std) VALUES(%s, %s, %s, %s, %s)", + ("num_dengue", "201409", "ar", "85263", "351456"), + ) + self.cnx.commit() + response = Epidata.dengue_nowcast(locations="ar", epiweeks=201409) + self.assertEqual( + response, + { + "epidata": [{"location": "ar", "epiweek": 201409, "value": 85263.0, "std": 351456.0}], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_dengue_sensors.py b/integrations/server/test_dengue_sensors.py new file mode 100644 index 000000000..5a690969f --- /dev/null +++ b/integrations/server/test_dengue_sensors.py @@ -0,0 +1,90 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class DengueSensorsTest(unittest.TestCase): + """Basic integration tests for dengue_sensors endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `dengue_sensors` ( + `id` int NOT NULL AUTO_INCREMENT, + `target` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `name` varchar(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `epiweek` int NOT NULL, + `location` varchar(12) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `value` float NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `entry` (`target`,`name`,`epiweek`,`location`), + KEY `sensor` (`target`,`name`), + KEY `epiweek` (`epiweek`), + KEY `location` (`location`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + cur.execute("TRUNCATE TABLE dengue_sensors") + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("sensors_key", "sensors_email")') + cur.execute('INSERT INTO user_role(name) VALUES("sensors") ON DUPLICATE KEY UPDATE name="sensors"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="sensors_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_dengue_sensors(self): + """Basic integration test for dengue_sensors endpoint""" + self.cur.execute( + "INSERT INTO dengue_sensors(target, name, epiweek, location, value) VALUES(%s, %s, %s, %s, %s)", + ("num_dengue", "ght", "201432", "ag", "1234"), + ) + self.cnx.commit() + response = Epidata.dengue_sensors(auth="sensors_key", names="ght", locations="ag", epiweeks="201432") + self.assertEqual( + response, + { + "epidata": [{"name": "ght", "location": "ag", "epiweek": 201432, "value": 1234.0}], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_ecdc_ili.py b/integrations/server/test_ecdc_ili.py new file mode 100644 index 000000000..d68bbe7a0 --- /dev/null +++ b/integrations/server/test_ecdc_ili.py @@ -0,0 +1,75 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class EcdcIliTest(unittest.TestCase): + """Basic integration tests for edcd_ili endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE ecdc_ili") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_ecdc_ili(self): + """Basic integration test for ecdc_ili endpoint""" + self.cur.execute( + "INSERT INTO ecdc_ili(`release_date`, `issue`, `epiweek`, `lag`, `region`, `incidence_rate`) VALUES(%s, %s, %s, %s, %s, %s)", + ("2020-03-26", "202012", "201840", "76", "Armenia", "0"), + ) + self.cnx.commit() + response = Epidata.ecdc_ili(regions="Armenia", epiweeks="201840") + self.assertEqual( + response, + { + "epidata": [ + { + "release_date": "2020-03-26", + "region": "Armenia", + "issue": 202012, + "epiweek": 201840, + "lag": 76, + "incidence_rate": 0.0, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_flusurv.py b/integrations/server/test_flusurv.py new file mode 100644 index 000000000..f6fd4bc16 --- /dev/null +++ b/integrations/server/test_flusurv.py @@ -0,0 +1,80 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class FlusurvTest(unittest.TestCase): + """Basic integration tests for flusurv endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE flusurv") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_ecdc_ili(self): + """Basic integration test for flusurv endpoint""" + self.cur.execute( + "INSERT INTO flusurv(`release_date`, `issue`, `epiweek`, `location`, `lag`, `rate_age_0`, `rate_age_1`, `rate_age_2`, `rate_age_3`, `rate_age_4`, `rate_overall`, `rate_age_5`, `rate_age_6`, `rate_age_7`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + ("2012-11-02", "201243", "201143", "CA", "52", "0", "0", "0", "0.151", "0", "0.029", "0", "0", "0"), + ) + self.cnx.commit() + response = Epidata.flusurv(epiweeks=201143, locations="CA") + self.assertEqual( + response, + { + "epidata": [ + { + "release_date": "2012-11-02", + "location": "CA", + "issue": 201243, + "epiweek": 201143, + "lag": 52, + "rate_age_0": 0.0, + "rate_age_1": 0.0, + "rate_age_2": 0.0, + "rate_age_3": 0.151, + "rate_age_4": 0.0, + "rate_overall": 0.029, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_fluview_clinical.py b/integrations/server/test_fluview_clinical.py new file mode 100644 index 000000000..5e87dde10 --- /dev/null +++ b/integrations/server/test_fluview_clinical.py @@ -0,0 +1,80 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class FluviewClinicalTest(unittest.TestCase): + """Basic integration tests for fluview_clinical endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE fluview_clinical") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_ecdc_ili(self): + """Basic integration test for fluview_clinical endpoint""" + self.cur.execute( + "INSERT INTO fluview_clinical(`release_date`, `issue`, `epiweek`, `region`, `lag`, `total_specimens`, `total_a`, `total_b`, `percent_positive`, `percent_a`, `percent_b`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + ("2018-10-10", "201839", "201640", "al", "103", "406", "4", "1", "1.32", "0.99", "0.25"), + ) + self.cnx.commit() + response = Epidata.fluview_clinical(epiweeks=201640, regions="al") + self.assertEqual( + response, + { + "epidata": [ + { + "release_date": "2018-10-10", + "region": "al", + "issue": 201839, + "epiweek": 201640, + "lag": 103, + "total_specimens": 406, + "total_a": 4, + "total_b": 1, + "percent_positive": 1.32, + "percent_a": 0.99, + "percent_b": 0.25, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_gft.py b/integrations/server/test_gft.py new file mode 100644 index 000000000..ee5d8365b --- /dev/null +++ b/integrations/server/test_gft.py @@ -0,0 +1,62 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class GftTest(unittest.TestCase): + """Basic integration tests for gft endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE gft") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_gft(self): + """Basic integration test for gft endpoint""" + self.cur.execute( + "INSERT INTO gft(epiweek, location, num) VALUES(%s, %s, %s)", + ("200340", "nat", "902"), + ) + self.cnx.commit() + response = Epidata.gft(locations="nat", epiweeks="200340") + self.assertEqual( + response, + {"epidata": [{"location": "nat", "epiweek": 200340, "num": 902}], "result": 1, "message": "success"}, + ) diff --git a/integrations/server/test_ght.py b/integrations/server/test_ght.py new file mode 100644 index 000000000..595ddc700 --- /dev/null +++ b/integrations/server/test_ght.py @@ -0,0 +1,67 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class GhtTest(unittest.TestCase): + """Basic integration tests for gft endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + cur.execute("TRUNCATE TABLE ght") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("ght_key", "ght_email")') + cur.execute('INSERT INTO user_role(name) VALUES("ght") ON DUPLICATE KEY UPDATE name="ght"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="ght_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_ght(self): + """Basic integration test for ght endpoint""" + self.cur.execute( + "INSERT INTO ght(`query`, `location`, `epiweek`, `value`) VALUES(%s, %s, %s, %s)", + ("/n/query", "US", "200101", "12345"), + ) + self.cnx.commit() + response = Epidata.ght(locations="US", epiweeks="200101", query="/n/query", auth="ght_key") + self.assertEqual( + response, + {"epidata": [{"location": "US", "epiweek": 200101, "value": 12345.0}], "result": 1, "message": "success"}, + ) diff --git a/integrations/server/test_kcdc_ili.py b/integrations/server/test_kcdc_ili.py new file mode 100644 index 000000000..c337db29f --- /dev/null +++ b/integrations/server/test_kcdc_ili.py @@ -0,0 +1,75 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class KcdcIliTest(unittest.TestCase): + """Basic integration tests for kcdc_ili endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE kcdc_ili") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_kcdc_ili(self): + """Basic integration test for kcdc_ili endpoint""" + self.cur.execute( + "INSERT INTO kcdc_ili(`release_date`, `issue`, `epiweek`, `lag`, `region`, `ili`) VALUES(%s, %s, %s, %s, %s, %s)", + ("2020-03-27", "202013", "200432", "222", "REG", "0.25"), + ) + self.cnx.commit() + response = Epidata.kcdc_ili(regions="REG", epiweeks="200432") + self.assertEqual( + response, + { + "epidata": [ + { + "release_date": "2020-03-27", + "region": "REG", + "issue": 202013, + "epiweek": 200432, + "lag": 222, + "ili": 0.25, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_meta.py b/integrations/server/test_meta.py new file mode 100644 index 000000000..45cbff125 --- /dev/null +++ b/integrations/server/test_meta.py @@ -0,0 +1,72 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class MetaTest(unittest.TestCase): + """Basic integration tests for meta endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE forecasts") + cur.execute("TRUNCATE TABLE fluview") + cur.execute("TRUNCATE TABLE wiki") + cur.execute("TRUNCATE TABLE wiki_meta") + cur.execute("TRUNCATE TABLE twitter") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_meta(self): + """Basic integration test for meta endpoint""" + response = Epidata.meta() + self.assertEqual( + response, + { + "epidata": [ + { + "delphi": [], + "fluview": [{"latest_issue": None, "latest_update": None, "table_rows": 0}], + "twitter": [], + "wiki": [{"latest_update": None, "table_rows": 0}], + } + ], + "message": "success", + "result": 1, + }, + ) diff --git a/integrations/server/test_meta_norostat.py b/integrations/server/test_meta_norostat.py new file mode 100644 index 000000000..5462af750 --- /dev/null +++ b/integrations/server/test_meta_norostat.py @@ -0,0 +1,135 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class MetaNorostatTest(unittest.TestCase): + """Basic integration tests for meta_norostat endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_version_list` ( + `release_date` date NOT NULL, + `parse_time` datetime NOT NULL, + PRIMARY KEY (`release_date`,`parse_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + # cnx.commit() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `norostat_point_version_list` ( + `release_date` date NOT NULL, + `parse_time` datetime NOT NULL, + PRIMARY KEY (`release_date`,`parse_time`), + CONSTRAINT `norostat_point_version_list_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_raw_datatable_version_list` (`release_date`, `parse_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + # cnx.commit() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_location_pool` ( + `location_id` int NOT NULL AUTO_INCREMENT, + `location` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + PRIMARY KEY (`location_id`), + UNIQUE KEY `location` (`location`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + # cnx.commit() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `norostat_point_diffs` ( + `release_date` date NOT NULL, + `parse_time` datetime NOT NULL, + `location_id` int NOT NULL, + `epiweek` int NOT NULL, + `new_value` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + PRIMARY KEY (`release_date`,`parse_time`,`location_id`,`epiweek`), + UNIQUE KEY `location_id` (`location_id`,`epiweek`,`release_date`,`parse_time`,`new_value`), + CONSTRAINT `norostat_point_diffs_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_point_version_list` (`release_date`, `parse_time`), + CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + cur.execute("DELETE FROM norostat_point_diffs") + cur.execute("DELETE FROM norostat_point_version_list") + cur.execute("DELETE FROM norostat_raw_datatable_location_pool") + cur.execute("DELETE FROM norostat_raw_datatable_version_list") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("norostat_key", "norostat_email")') + cur.execute('INSERT INTO user_role(name) VALUES("norostat") ON DUPLICATE KEY UPDATE name="norostat"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="norostat_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_meta_norostat(self): + """Basic integration test for meta_norostat endpoint""" + + self.cur.execute( + "INSERT INTO norostat_raw_datatable_version_list(release_date, parse_time) VALUES (%s, %s)", + ("2014-10-22", "2048-12-08 15:22:51"), + ) + self.cur.execute( + 'INSERT INTO norostat_raw_datatable_location_pool(`location`) VALUES ("Minnesota, Ohio, Oregon, Tennessee, and Wisconsin")' + ) + self.cnx.commit() + response = Epidata.meta_norostat(auth="norostat_key") + self.assertEqual( + response, + { + "epidata": { + "locations": [{"location": "Minnesota, Ohio, Oregon, Tennessee, and Wisconsin"}], + "releases": [{"release_date": "2014-10-22"}], + }, + "message": "success", + "result": 1, + }, + ) diff --git a/integrations/server/test_nidss_dengue.py b/integrations/server/test_nidss_dengue.py new file mode 100644 index 000000000..d57d2a18a --- /dev/null +++ b/integrations/server/test_nidss_dengue.py @@ -0,0 +1,62 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class NiddsDengueTest(unittest.TestCase): + """Basic integration tests for nids_dengue endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE nidss_dengue") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_nidss_dengue(self): + """Basic integration test for nidds_dengue endpoint""" + self.cur.execute( + "INSERT INTO nidss_dengue(epiweek, location, region, count) VALUES(%s, %s, %s, %s)", + ("200340", "SomeCity", "Central", "0"), + ) + self.cnx.commit() + response = Epidata.nidss_dengue(locations="SomeCity", epiweeks="200340") + self.assertEqual( + response, + {"epidata": [{"location": "SomeCity", "epiweek": 200340, "count": 0}], "result": 1, "message": "success"}, + ) diff --git a/integrations/server/test_nidss_flu.py b/integrations/server/test_nidss_flu.py new file mode 100644 index 000000000..6f38559ae --- /dev/null +++ b/integrations/server/test_nidss_flu.py @@ -0,0 +1,76 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class NiddsFluTest(unittest.TestCase): + """Basic integration tests for nids_flu endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE nidss_flu") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_nidss_flu(self): + """Basic integration test for nidds_flu endpoint""" + self.cur.execute( + "INSERT INTO nidss_flu(`release_date`, `issue`, `epiweek`, `region`, `lag`, `visits`, `ili`) VALUES(%s, %s, %s, %s, %s, %s, %s)", + ("2015-09-05", "201530", "200111", "SomeRegion", "222", "333", "444"), + ) + self.cnx.commit() + response = Epidata.nidss_flu(regions="SomeRegion", epiweeks="200111") + self.assertEqual( + response, + { + "epidata": [ + { + "release_date": "2015-09-05", + "region": "SomeRegion", + "issue": 201530, + "epiweek": 200111, + "lag": 222, + "visits": 333, + "ili": 444.0, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_norostat.py b/integrations/server/test_norostat.py new file mode 100644 index 000000000..461dfc779 --- /dev/null +++ b/integrations/server/test_norostat.py @@ -0,0 +1,93 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class NorostatTest(unittest.TestCase): + """Basic integration tests for norostat endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute( + """ + CREATE TABLE IF NOT EXISTS `norostat_point_diffs` ( + `release_date` date NOT NULL, + `parse_time` datetime NOT NULL, + `location_id` int NOT NULL, + `epiweek` int NOT NULL, + `new_value` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + PRIMARY KEY (`release_date`,`parse_time`,`location_id`,`epiweek`), + UNIQUE KEY `location_id` (`location_id`,`epiweek`,`release_date`,`parse_time`,`new_value`), + CONSTRAINT `norostat_point_diffs_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_point_version_list` (`release_date`, `parse_time`), + CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + ) + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + + cur.execute("DELETE FROM norostat_point_diffs") + cur.execute("DELETE FROM norostat_point_version_list") + cur.execute("DELETE FROM norostat_raw_datatable_location_pool") + cur.execute("DELETE FROM norostat_raw_datatable_version_list") + + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("norostat_key", "norostat_email")') + cur.execute('INSERT INTO user_role(name) VALUES("norostat") ON DUPLICATE KEY UPDATE name="norostat"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="norostat_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_norostat(self): + """Basic integration test for norostat endpoint""" + self.cur.execute('INSERT INTO norostat_raw_datatable_version_list(release_date, parse_time) VALUES ("2023-07-19", "2023-07-10 15:24:51")') + self.cur.execute('INSERT INTO norostat_raw_datatable_location_pool(location_id, location) VALUES("1", "SomeTestLocation")') + self.cur.execute('INSERT INTO norostat_point_version_list(`release_date`, `parse_time`) VALUES("2023-07-19", "2023-07-10 15:24:51")') + self.cur.execute('INSERT INTO norostat_point_diffs(release_date, parse_time, location_id, epiweek, new_value) VALUES("2023-07-19", "2023-07-10 15:24:51", "1", "202329", 10)') + self.cnx.commit() + response = Epidata.norostat(auth="norostat_key", location="SomeTestLocation", epiweeks="202329") + self.assertEqual( + response, + { + "epidata": [{"release_date": "2023-07-19", "epiweek": 202329, "value": 10}], + "result": 1, + "message": "success", + }, + ) + return True diff --git a/integrations/server/test_nowcast.py b/integrations/server/test_nowcast.py new file mode 100644 index 000000000..8f3d4293b --- /dev/null +++ b/integrations/server/test_nowcast.py @@ -0,0 +1,66 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class NowcastTest(unittest.TestCase): + """Basic integration tests for nowcast endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE nowcasts") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_nowcast(self): + """Basic integration test for nowcast endpoint""" + self.cur.execute( + "INSERT INTO nowcasts(`epiweek`, `location`, `value`, `std`) VALUES(%s, %s, %s, %s)", + ("201145", "nat", "12345", "0.01234"), + ) + self.cnx.commit() + response = Epidata.nowcast(locations="nat", epiweeks="201145") + self.assertEqual( + response, + { + "epidata": [{"location": "nat", "epiweek": 201145, "value": 12345.0, "std": 0.01234}], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_paho_dengue.py b/integrations/server/test_paho_dengue.py new file mode 100644 index 000000000..01767a582 --- /dev/null +++ b/integrations/server/test_paho_dengue.py @@ -0,0 +1,80 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class PahoDengueTest(unittest.TestCase): + """Basic integration tests for paho_dengue endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE paho_dengue") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_paho_dengue(self): + """Basic integration test for paho_dengue endpoint""" + self.cur.execute( + "INSERT INTO paho_dengue(`release_date`, `issue`, `epiweek`, `lag`, `region`, `total_pop`, `serotype`, `num_dengue`, `incidence_rate`, `num_severe`, `num_deaths`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + ("2018-12-01", "201848", "201454", "204", "AG", "91", "DEN 1,4", "37", "40.66", "0", "0"), + ) + self.cnx.commit() + response = Epidata.paho_dengue(regions="AG", epiweeks="201454") + self.assertEqual( + response, + { + "epidata": [ + { + "release_date": "2018-12-01", + "region": "AG", + "serotype": "DEN 1,4", + "issue": 201848, + "epiweek": 201454, + "lag": 204, + "total_pop": 91, + "num_dengue": 37, + "num_severe": 0, + "num_deaths": 0, + "incidence_rate": 40.66, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_quidel.py b/integrations/server/test_quidel.py new file mode 100644 index 000000000..c16d4e770 --- /dev/null +++ b/integrations/server/test_quidel.py @@ -0,0 +1,67 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class QuidelTest(unittest.TestCase): + """Basic integration tests for quidel endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + cur.execute("TRUNCATE TABLE quidel") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("quidel_key", "quidel_email")') + cur.execute('INSERT INTO user_role(name) VALUES("quidel") ON DUPLICATE KEY UPDATE name="quidel"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="quidel_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_quidel(self): + """Basic integration test for quidel endpoint""" + self.cur.execute( + "INSERT INTO quidel(location, epiweek, value, num_rows, num_devices) VALUES(%s, %s, %s, %s, %s)", + ("loc1", "201111", "1", "0", "0"), + ) + self.cnx.commit() + response = Epidata.quidel(locations="loc1", epiweeks="201111", auth="quidel_key") + self.assertEqual( + response, + {"epidata": [{"location": "loc1", "epiweek": 201111, "value": 1.0}], "result": 1, "message": "success"}, + ) diff --git a/integrations/server/test_sensors.py b/integrations/server/test_sensors.py new file mode 100644 index 000000000..6cf851519 --- /dev/null +++ b/integrations/server/test_sensors.py @@ -0,0 +1,71 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class SensorsTest(unittest.TestCase): + """Basic integration tests for sensors endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + cur.execute("TRUNCATE TABLE sensors") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("sensors_key", "sensors_email")') + cur.execute('INSERT INTO user_role(name) VALUES("sensors") ON DUPLICATE KEY UPDATE name="sensors"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="sensors_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_gft(self): + """Basic integration test for sensors endpoint""" + self.cur.execute( + "INSERT INTO sensors(name, epiweek, location, value) VALUES(%s, %s, %s, %s)", + ("sens1", "201111", "loc1", "222"), + ) + self.cnx.commit() + response = Epidata.sensors(names="sens1", locations="loc1", epiweeks="201111", auth="sensors_key") + self.assertEqual( + response, + { + "epidata": [{"name": "sens1", "location": "loc1", "epiweek": 201111, "value": 222.0}], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_signal_dashboard.py b/integrations/server/test_signal_dashboard.py new file mode 100644 index 000000000..a442d49a0 --- /dev/null +++ b/integrations/server/test_signal_dashboard.py @@ -0,0 +1,102 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class SignalDashboardTest(unittest.TestCase): + """Basic integration tests for signal_dashboard_coverage and signal_dashboard_status endpints.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + + cur.execute("DELETE FROM dashboard_signal_coverage") + cur.execute("DELETE FROM dashboard_signal") + + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cur.execute( + "INSERT INTO dashboard_signal(id, name, source, covidcast_signal, enabled, latest_coverage_update, latest_status_update) VALUES(%s, %s, %s, %s, %s, %s, %s)", + ("1", "Change", "chng", "smoothed_outpatient_covid", "1", "2021-10-02", "2021-11-27"), + ) + cur.execute( + "INSERT INTO dashboard_signal_coverage(signal_id, date, geo_type, count) VALUES(%s, %s, %s, %s)", + ("1", "2021-10-02", "county", "2222"), + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_signal_dashboard_coverage(self): + """Basic integration test for signal_dashboard_coverage endpoint""" + + params = { + "endpoint": "signal_dashboard_coverage", + } + response = Epidata._request(params=params) + self.assertEqual( + response, + { + "epidata": {"Change": {"county": [{"count": 2222, "date": "2021-10-02"}]}}, + "message": "success", + "result": 1, + }, + ) + + def test_signal_dashboard_status(self): + """Basic integration test for signal_dashboard_status endpoint""" + + params = { + "endpoint": "signal_dashboard_status", + } + response = Epidata._request(params=params) + self.assertEqual( + response, + { + "epidata": [ + { + "name": "Change", + "source": "chng", + "covidcast_signal": "smoothed_outpatient_covid", + "latest_issue": None, + "latest_time_value": None, + "coverage": {"county": [{"date": "2021-10-02", "count": 2222}]}, + } + ], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_twitter.py b/integrations/server/test_twitter.py new file mode 100644 index 000000000..46cda4acc --- /dev/null +++ b/integrations/server/test_twitter.py @@ -0,0 +1,71 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class TwitterTest(unittest.TestCase): + """Basic integration tests for twitter endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE user_role") + cur.execute("TRUNCATE TABLE user_role_link") + cur.execute("TRUNCATE TABLE twitter") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("twitter_key", "twitter_email")') + cur.execute('INSERT INTO user_role(name) VALUES("twitter") ON DUPLICATE KEY UPDATE name="twitter"') + cur.execute( + 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="twitter_key"' + ) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_twitter(self): + """Basic integration test for twitter endpoint""" + + self.cur.execute( + 'INSERT INTO twitter(date, state, num, total) VALUES ("2015-07-29", "AK", "1", "223"), ("2020-07-29", "CT", "12", "778")', + ) + self.cnx.commit() + response = Epidata.twitter(auth="twitter_key", locations="cen9", dates="20150701-20160101") + self.assertEqual( + response, + { + "epidata": [{"location": "cen9", "date": "2015-07-29", "num": 1, "total": 223, "percent": 0.4484}], + "result": 1, + "message": "success", + }, + ) diff --git a/integrations/server/test_wiki.py b/integrations/server/test_wiki.py new file mode 100644 index 000000000..6763d7d62 --- /dev/null +++ b/integrations/server/test_wiki.py @@ -0,0 +1,72 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class WikiTest(unittest.TestCase): + """Basic integration tests for wiki endpint.""" + + @classmethod + def setUpClass(cls) -> None: + """Perform one-time setup.""" + + # use local instance of the Epidata API + Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + Epidata.auth = ("epidata", "key") + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM api_user") + cur.execute("TRUNCATE TABLE wiki") + cur.execute("TRUNCATE TABLE wiki_meta") + + cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits(): + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() + + def test_wiki(self): + """Basic integration test for wiki endpoint""" + + self.cur.execute( + 'INSERT INTO wiki(datetime, article, count, language) VALUES ("2007-12-09 18:00:00", "amantadine", "3", "en"), ("2008-12-09 18:00:00", "test", "5", "en")', + ) + self.cur.execute( + 'INSERT INTO wiki_meta(datetime, date, epiweek, total, language) VALUES ("2007-12-09 18:00:00", "2007-12-09", "200750", "969214", "en"), ("2008-12-09 18:00:00", "2008-12-09", "200750", "123321", "en")' + ) + self.cnx.commit() + response = Epidata.wiki(articles="test", epiweeks="200701-200801") + self.assertEqual( + response, + { + "epidata": [ + {"article": "test", "count": 5, "total": 123321, "hour": -1, "epiweek": 200750, "value": 40.544595} + ], + "result": 1, + "message": "success", + }, + ) From e95bcaa6a5155f6bc41706856385880dd1c021a6 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 21 Jul 2023 14:40:52 +0300 Subject: [PATCH 02/14] Added base class for tests. Added API keys tests --- dev/local/Makefile | 1 + integrations/server/test_api_keys.py | 243 +++++++++++++++++++ integrations/server/test_cdc.py | 57 +---- integrations/server/test_delphi.py | 46 +--- integrations/server/test_dengue_nowcast.py | 53 +--- integrations/server/test_dengue_sensors.py | 64 +---- integrations/server/test_ecdc_ili.py | 49 +--- integrations/server/test_flusurv.py | 51 +--- integrations/server/test_fluview_clinical.py | 51 +--- integrations/server/test_gft.py | 49 +--- integrations/server/test_ght.py | 57 +---- integrations/server/test_kcdc_ili.py | 49 +--- integrations/server/test_meta.py | 54 +---- integrations/server/test_meta_norostat.py | 90 ++----- integrations/server/test_nidss_dengue.py | 49 +--- integrations/server/test_nidss_flu.py | 49 +--- integrations/server/test_norostat.py | 84 ++----- integrations/server/test_nowcast.py | 49 +--- integrations/server/test_paho_dengue.py | 49 +--- integrations/server/test_quidel.py | 55 +---- integrations/server/test_sensors.py | 57 +---- integrations/server/test_signal_dashboard.py | 60 +---- integrations/server/test_twitter.py | 55 +---- integrations/server/test_wiki.py | 52 +--- src/common/integration_test_base_class.py | 79 ++++++ src/server/_config.py | 8 + 26 files changed, 519 insertions(+), 1041 deletions(-) create mode 100644 integrations/server/test_api_keys.py create mode 100644 src/common/integration_test_base_class.py diff --git a/dev/local/Makefile b/dev/local/Makefile index e7e896aa6..018413f2a 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -102,6 +102,7 @@ web: --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \ --env "REDIS_HOST=delphi_redis" \ --env "REDIS_PASSWORD=1234" \ + --env "TESTING_MODE=True" \ --env "API_KEY_ADMIN_PASSWORD=test_admin_password" \ --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \ --network delphi-net --name delphi_web_epidata \ diff --git a/integrations/server/test_api_keys.py b/integrations/server/test_api_keys.py new file mode 100644 index 000000000..19bc4d3ff --- /dev/null +++ b/integrations/server/test_api_keys.py @@ -0,0 +1,243 @@ +"""Integration tests for the API Keys""" +import requests + +# first party +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest + + +class APIKeysTets(BasicIntegrationTest): + """Tests the API Keys behaviour""" + + def setUp(self): + """Perform per-test setup.""" + + self.role_name = "cdc" + super().setUp() + + def _make_request(self, url: str = None, params: dict = {}, auth: tuple = None): + if not url: + url = self.epidata.BASE_URL + response = requests.get(url, params=params, auth=auth) + return response + + def test_public_route(self): + """Test public route""" + public_route = "http://delphi_web_epidata/epidata/version" + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(public_route).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_no_multiples_data_source(self): + """Test requests with no multiples and with provided `data_source` and `signal` as a separate query params.""" + params = { + "source": "covidcast", + "data_source": "fb-survey", + "signal": "smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa", + "time_values": "20200406", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_no_multiples_source_signal(self): + """Test requests with colon-delimited source-signal param presentation.""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa", + "time_values": "20200406", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_multiples_allowed_signal(self): + """Test requests with 2 multiples and allowed dashboard signal""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa,ny", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_multiples_non_allowed_signal(self): + """Test requests with 2 multiples and non-allowed dashboard signal""" + params = { + "source": "covidcast", + "signal": "hospital-admissions:smoothed_adj_covid19_from_claims", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa,ny", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 2) + self.assertEqual(status_codes, {200, 429}) + + def test_multiples_mixed_allowed_signal(self): + """Test requests with 2 multiples and mixed-allowed dashboard signal""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli,hospital-admissions:smoothed_adj_covid19_from_claims", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 2) + self.assertEqual(status_codes, {200, 429}) + + def test_multiples_allowed_signal(self): + """Test requests with 3 multiples and allowed dashboard signal""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli,fb-survey:smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa,ny", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 401) + + def test_multiples_mixed_allowed_signal(self): + """Test requests with 3 multiples and mixed-allowed dashboard signal""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli,fb-survey:smoothed_wcli1", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa,ny", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 401) + + def test_multiples_mixed_allowed_signal_api_key(self): + """Test requests with 3 multiples and mixed-allowed dashboard signal + valid API Key""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli,fb-survey:smoothed_wcli1", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa,ny", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params, auth=self.epidata.auth).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_multiples_allowed_signal_api_key(self): + """Test requests with 3 multiples and allowed dashboard signal + valid API Key""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli,fb-survey:smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa,ny", + "time_values": "20200406,20200407", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params, auth=self.epidata.auth).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_no_multiples_allowed_signal_api_key(self): + """Test requests with no multiples and allowed dashboard signal + valid API Key""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa", + "time_values": "20200406", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params, auth=self.epidata.auth).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_no_multiples_allowed_signal_bad_api_key(self): + """Test requests with no multiples and allowed dashboard signal + bad API Key""" + params = { + "source": "covidcast", + "signal": "fb-survey:smoothed_wcli", + "time_type": "day", + "geo_type": "state", + "geo_value": "pa", + "time_values": "20200406", + } + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params, auth=("bad_key", "bad_email")).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) + + def test_restricted_endpoint_no_key(self): + """Test restricted endpoint with no auth key""" + params = {"source": "cdc", "regions": "1as", "epiweeks": "202020"} + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 401) + + def test_restricted_endpoint_invalid_key(self): + """Test restricted endpoint with invalid auth key""" + params = {"source": "cdc", "regions": "1as", "epiweeks": "202020", "auth": "invalid_key"} + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 401) + + def test_restricted_endpoint_no_roles_key(self): + """Test restricted endpoint with no roles key""" + params = {"source": "cdc", "regions": "1as", "epiweeks": "202020", "auth": "key"} + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 401) + + def test_restricted_endpoint_valid_roles_key(self): + """Test restricted endpoint with valid auth key with required role""" + params = {"source": "cdc", "regions": "1as", "epiweeks": "202020", "auth": "cdc_key"} + status_codes = set() + for _ in range(10): + status_codes.add(self._make_request(params=params).status_code) + self.assertEqual(len(status_codes), 1) + self.assertEqual(next(iter(status_codes)), 200) diff --git a/integrations/server/test_cdc.py b/integrations/server/test_cdc.py index 2b81d562c..7234f9eb0 100644 --- a/integrations/server/test_cdc.py +++ b/integrations/server/test_cdc.py @@ -1,66 +1,23 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class CdcTest(unittest.TestCase): +class CdcTest(BasicIntegrationTest): """Basic integration tests for cdc endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: - """Perform per-test setup.""" - - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - cur.execute("TRUNCATE TABLE cdc_extract") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("cdc_key", "cdc_email")') - cur.execute('INSERT INTO user_role(name) VALUES("cdc") ON DUPLICATE KEY UPDATE name="cdc"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="cdc_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["cdc_extract"] + self.role_name = "cdc" + super().setUp() def test_cdc(self): """Basic integration test for cdc endpoint""" self.cur.execute( - "INSERT INTO cdc_extract(epiweek, state, num1, num2, num3, num4, num5, num6, num7, num8, total) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + "INSERT INTO `cdc_extract`(`epiweek`, `state`, `num1`, `num2`, `num3`, `num4`, `num5`, `num6`, `num7`, `num8`, `total`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ("201102", "AK", "16", "35", "51", "96", "30", "748", "243", "433", "65"), ) self.cnx.commit() - response = Epidata.cdc(auth="cdc_key", epiweeks=201102, locations="cen9") + response = self.epidata.cdc(auth="cdc_key", epiweeks=201102, locations="cen9") self.assertEqual( response, { diff --git a/integrations/server/test_delphi.py b/integrations/server/test_delphi.py index ee6780cd9..481b9d3f5 100644 --- a/integrations/server/test_delphi.py +++ b/integrations/server/test_delphi.py @@ -2,57 +2,23 @@ import unittest # third party -import mysql.connector import json # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class DelphiTest(unittest.TestCase): +class DelphiTest(BasicIntegrationTest): """Basic integration tests for delphi endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: - """Perform per-test setup.""" - - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE forecasts") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["forecasts"] + super().setUp() def test_delphi(self): """Basic integration test for delphi endpoint""" self.cur.execute( - "INSERT INTO forecasts (`system`, `epiweek`, `json`) VALUES(%s, %s, %s)", + "INSERT INTO `forecasts` (`system`, `epiweek`, `json`) VALUES(%s, %s, %s)", ( "eb", "201441", @@ -71,7 +37,7 @@ def test_delphi(self): ), ) self.cnx.commit() - response = Epidata.delphi(system="eb", epiweek=201441) + response = self.epidata.delphi(system="eb", epiweek=201441) self.assertEqual( response, { diff --git a/integrations/server/test_dengue_nowcast.py b/integrations/server/test_dengue_nowcast.py index de40ae5c3..dea91979d 100644 --- a/integrations/server/test_dengue_nowcast.py +++ b/integrations/server/test_dengue_nowcast.py @@ -1,34 +1,14 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class DengueNowcastTest(unittest.TestCase): +class DengueNowcastTest(BasicIntegrationTest): """Basic integration tests for dengue_nowcast endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute( - """ + create_dengue_nowcasts = """ CREATE TABLE IF NOT EXISTS `dengue_nowcasts` ( `id` int NOT NULL AUTO_INCREMENT, `target` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, @@ -43,28 +23,9 @@ def setUp(self) -> None: KEY `location` (`location`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE dengue_nowcasts") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.create_tables_list = [create_dengue_nowcasts] + self.truncate_tables_list = ["dengue_nowcasts"] + super().setUp() def test_dengue_nowcasts(self): """Basic integration test for dengue_nowcasts endpoint""" @@ -73,7 +34,7 @@ def test_dengue_nowcasts(self): ("num_dengue", "201409", "ar", "85263", "351456"), ) self.cnx.commit() - response = Epidata.dengue_nowcast(locations="ar", epiweeks=201409) + response = self.epidata.dengue_nowcast(locations="ar", epiweeks=201409) self.assertEqual( response, { diff --git a/integrations/server/test_dengue_sensors.py b/integrations/server/test_dengue_sensors.py index 5a690969f..75ff9028a 100644 --- a/integrations/server/test_dengue_sensors.py +++ b/integrations/server/test_dengue_sensors.py @@ -1,33 +1,14 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class DengueSensorsTest(unittest.TestCase): +class DengueSensorsTest(BasicIntegrationTest): """Basic integration tests for dengue_sensors endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: - """Perform per-test setup.""" + """Perfor per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute( - """ + create_dengue_sensors = """ CREATE TABLE IF NOT EXISTS `dengue_sensors` ( `id` int NOT NULL AUTO_INCREMENT, `target` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, @@ -42,44 +23,19 @@ def setUp(self) -> None: KEY `location` (`location`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - - cur.execute("TRUNCATE TABLE dengue_sensors") - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("sensors_key", "sensors_email")') - cur.execute('INSERT INTO user_role(name) VALUES("sensors") ON DUPLICATE KEY UPDATE name="sensors"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="sensors_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.create_tables_list = [create_dengue_sensors] + self.truncate_tables_list = ["dengue_sensors"] + self.role_name = "sensors" + super().setUp() def test_dengue_sensors(self): """Basic integration test for dengue_sensors endpoint""" self.cur.execute( - "INSERT INTO dengue_sensors(target, name, epiweek, location, value) VALUES(%s, %s, %s, %s, %s)", + "INSERT INTO `dengue_sensors`(`target`, `name`, `epiweek`, `location`, `value`) VALUES(%s, %s, %s, %s, %s)", ("num_dengue", "ght", "201432", "ag", "1234"), ) self.cnx.commit() - response = Epidata.dengue_sensors(auth="sensors_key", names="ght", locations="ag", epiweeks="201432") + response = self.epidata.dengue_sensors(auth="sensors_key", names="ght", locations="ag", epiweeks="201432") self.assertEqual( response, { diff --git a/integrations/server/test_ecdc_ili.py b/integrations/server/test_ecdc_ili.py index d68bbe7a0..3c65cb2c2 100644 --- a/integrations/server/test_ecdc_ili.py +++ b/integrations/server/test_ecdc_ili.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class EcdcIliTest(unittest.TestCase): +class EcdcIliTest(BasicIntegrationTest): """Basic integration tests for edcd_ili endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE ecdc_ili") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["ecdc_ili"] + super().setUp() def test_ecdc_ili(self): """Basic integration test for ecdc_ili endpoint""" self.cur.execute( - "INSERT INTO ecdc_ili(`release_date`, `issue`, `epiweek`, `lag`, `region`, `incidence_rate`) VALUES(%s, %s, %s, %s, %s, %s)", + "INSERT INTO `ecdc_ili`(`release_date`, `issue`, `epiweek`, `lag`, `region`, `incidence_rate`) VALUES(%s, %s, %s, %s, %s, %s)", ("2020-03-26", "202012", "201840", "76", "Armenia", "0"), ) self.cnx.commit() - response = Epidata.ecdc_ili(regions="Armenia", epiweeks="201840") + response = self.epidata.ecdc_ili(regions="Armenia", epiweeks="201840") self.assertEqual( response, { diff --git a/integrations/server/test_flusurv.py b/integrations/server/test_flusurv.py index f6fd4bc16..e818a2698 100644 --- a/integrations/server/test_flusurv.py +++ b/integrations/server/test_flusurv.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class FlusurvTest(unittest.TestCase): +class FlusurvTest(BasicIntegrationTest): """Basic integration tests for flusurv endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE flusurv") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["flusurv"] + super().setUp() - def test_ecdc_ili(self): + def test_flusurv(self): """Basic integration test for flusurv endpoint""" self.cur.execute( - "INSERT INTO flusurv(`release_date`, `issue`, `epiweek`, `location`, `lag`, `rate_age_0`, `rate_age_1`, `rate_age_2`, `rate_age_3`, `rate_age_4`, `rate_overall`, `rate_age_5`, `rate_age_6`, `rate_age_7`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + "INSERT INTO `flusurv`(`release_date`, `issue`, `epiweek`, `location`, `lag`, `rate_age_0`, `rate_age_1`, `rate_age_2`, `rate_age_3`, `rate_age_4`, `rate_overall`, `rate_age_5`, `rate_age_6`, `rate_age_7`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ("2012-11-02", "201243", "201143", "CA", "52", "0", "0", "0", "0.151", "0", "0.029", "0", "0", "0"), ) self.cnx.commit() - response = Epidata.flusurv(epiweeks=201143, locations="CA") + response = self.epidata.flusurv(epiweeks=201143, locations="CA") self.assertEqual( response, { diff --git a/integrations/server/test_fluview_clinical.py b/integrations/server/test_fluview_clinical.py index 5e87dde10..77f0d76ea 100644 --- a/integrations/server/test_fluview_clinical.py +++ b/integrations/server/test_fluview_clinical.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class FluviewClinicalTest(unittest.TestCase): +class FluviewClinicalTest(BasicIntegrationTest): """Basic integration tests for fluview_clinical endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE fluview_clinical") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["fluview_clinical"] + super().setUp() - def test_ecdc_ili(self): + def test_fluview_clinical(self): """Basic integration test for fluview_clinical endpoint""" self.cur.execute( - "INSERT INTO fluview_clinical(`release_date`, `issue`, `epiweek`, `region`, `lag`, `total_specimens`, `total_a`, `total_b`, `percent_positive`, `percent_a`, `percent_b`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + "INSERT INTO `fluview_clinical`(`release_date`, `issue`, `epiweek`, `region`, `lag`, `total_specimens`, `total_a`, `total_b`, `percent_positive`, `percent_a`, `percent_b`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ("2018-10-10", "201839", "201640", "al", "103", "406", "4", "1", "1.32", "0.99", "0.25"), ) self.cnx.commit() - response = Epidata.fluview_clinical(epiweeks=201640, regions="al") + response = self.epidata.fluview_clinical(epiweeks=201640, regions="al") self.assertEqual( response, { diff --git a/integrations/server/test_gft.py b/integrations/server/test_gft.py index ee5d8365b..f241769f4 100644 --- a/integrations/server/test_gft.py +++ b/integrations/server/test_gft.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class GftTest(unittest.TestCase): +class GftTest(BasicIntegrationTest): """Basic integration tests for gft endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE gft") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["gft"] + super().setUp() def test_gft(self): """Basic integration test for gft endpoint""" self.cur.execute( - "INSERT INTO gft(epiweek, location, num) VALUES(%s, %s, %s)", + "INSERT INTO `gft`(`epiweek`, `location`, `num`) VALUES(%s, %s, %s)", ("200340", "nat", "902"), ) self.cnx.commit() - response = Epidata.gft(locations="nat", epiweeks="200340") + response = self.epidata.gft(locations="nat", epiweeks="200340") self.assertEqual( response, {"epidata": [{"location": "nat", "epiweek": 200340, "num": 902}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_ght.py b/integrations/server/test_ght.py index 595ddc700..a8ea6f33d 100644 --- a/integrations/server/test_ght.py +++ b/integrations/server/test_ght.py @@ -1,66 +1,25 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter - +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class GhtTest(unittest.TestCase): - """Basic integration tests for gft endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" +class GhtTest(BasicIntegrationTest): + """Basic integration tests for ght endpint.""" def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - cur.execute("TRUNCATE TABLE ght") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("ght_key", "ght_email")') - cur.execute('INSERT INTO user_role(name) VALUES("ght") ON DUPLICATE KEY UPDATE name="ght"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="ght_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["ght"] + self.role_name = "ght" + super().setUp() def test_ght(self): """Basic integration test for ght endpoint""" self.cur.execute( - "INSERT INTO ght(`query`, `location`, `epiweek`, `value`) VALUES(%s, %s, %s, %s)", + "INSERT INTO `ght`(`query`, `location`, `epiweek`, `value`) VALUES(%s, %s, %s, %s)", ("/n/query", "US", "200101", "12345"), ) self.cnx.commit() - response = Epidata.ght(locations="US", epiweeks="200101", query="/n/query", auth="ght_key") + response = self.epidata.ght(locations="US", epiweeks="200101", query="/n/query", auth="ght_key") self.assertEqual( response, {"epidata": [{"location": "US", "epiweek": 200101, "value": 12345.0}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_kcdc_ili.py b/integrations/server/test_kcdc_ili.py index c337db29f..5474c28b9 100644 --- a/integrations/server/test_kcdc_ili.py +++ b/integrations/server/test_kcdc_ili.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class KcdcIliTest(unittest.TestCase): +class KcdcIliTest(BasicIntegrationTest): """Basic integration tests for kcdc_ili endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE kcdc_ili") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["kcdc_ili"] + super().setUp() def test_kcdc_ili(self): """Basic integration test for kcdc_ili endpoint""" self.cur.execute( - "INSERT INTO kcdc_ili(`release_date`, `issue`, `epiweek`, `lag`, `region`, `ili`) VALUES(%s, %s, %s, %s, %s, %s)", + "INSERT INTO `kcdc_ili`(`release_date`, `issue`, `epiweek`, `lag`, `region`, `ili`) VALUES(%s, %s, %s, %s, %s, %s)", ("2020-03-27", "202013", "200432", "222", "REG", "0.25"), ) self.cnx.commit() - response = Epidata.kcdc_ili(regions="REG", epiweeks="200432") + response = self.epidata.kcdc_ili(regions="REG", epiweeks="200432") self.assertEqual( response, { diff --git a/integrations/server/test_meta.py b/integrations/server/test_meta.py index 45cbff125..c32214222 100644 --- a/integrations/server/test_meta.py +++ b/integrations/server/test_meta.py @@ -1,60 +1,18 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class MetaTest(unittest.TestCase): +class MetaTest(BasicIntegrationTest): """Basic integration tests for meta endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: - """Perform per-test setup.""" - - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE forecasts") - cur.execute("TRUNCATE TABLE fluview") - cur.execute("TRUNCATE TABLE wiki") - cur.execute("TRUNCATE TABLE wiki_meta") - cur.execute("TRUNCATE TABLE twitter") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["forecasts", "fluview", "wiki", "wiki_meta", "twitter"] + super().setUp() def test_meta(self): + """Basic integration test for meta endpoint""" - response = Epidata.meta() + response = self.epidata.meta() self.assertEqual( response, { diff --git a/integrations/server/test_meta_norostat.py b/integrations/server/test_meta_norostat.py index 5462af750..b75b86a1e 100644 --- a/integrations/server/test_meta_norostat.py +++ b/integrations/server/test_meta_norostat.py @@ -1,45 +1,22 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class MetaNorostatTest(unittest.TestCase): +class MetaNorostatTest(BasicIntegrationTest): """Basic integration tests for meta_norostat endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute( - """ + create_raw_datatable_version_list = """ CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_version_list` ( `release_date` date NOT NULL, `parse_time` datetime NOT NULL, PRIMARY KEY (`release_date`,`parse_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - - # cnx.commit() - cur.execute( - """ + create_norostat_version_list = """ CREATE TABLE IF NOT EXISTS `norostat_point_version_list` ( `release_date` date NOT NULL, `parse_time` datetime NOT NULL, @@ -47,12 +24,8 @@ def setUp(self) -> None: CONSTRAINT `norostat_point_version_list_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_raw_datatable_version_list` (`release_date`, `parse_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - # cnx.commit() - - cur.execute( - """ + create_norostat_datatable_location_pool = """ CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_location_pool` ( `location_id` int NOT NULL AUTO_INCREMENT, `location` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, @@ -60,12 +33,8 @@ def setUp(self) -> None: UNIQUE KEY `location` (`location`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - # cnx.commit() - - cur.execute( - """ + create_norostat_point_diffs = """ CREATE TABLE IF NOT EXISTS `norostat_point_diffs` ( `release_date` date NOT NULL, `parse_time` datetime NOT NULL, @@ -78,50 +47,37 @@ def setUp(self) -> None: CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - cur.execute("DELETE FROM norostat_point_diffs") - cur.execute("DELETE FROM norostat_point_version_list") - cur.execute("DELETE FROM norostat_raw_datatable_location_pool") - cur.execute("DELETE FROM norostat_raw_datatable_version_list") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("norostat_key", "norostat_email")') - cur.execute('INSERT INTO user_role(name) VALUES("norostat") ON DUPLICATE KEY UPDATE name="norostat"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="norostat_key"' - ) - cnx.commit() - cur.close() + self.create_tables_list = [ + create_raw_datatable_version_list, + create_norostat_version_list, + create_norostat_datatable_location_pool, + create_norostat_point_diffs, + ] - self.cnx = cnx - self.cur = cnx.cursor() + self.delete_from_tables_list = [ + "norostat_point_diffs", + "norostat_point_version_list", + "norostat_raw_datatable_location_pool", + "norostat_raw_datatable_version_list", + ] - @staticmethod - def _clear_limits(): - limiter.storage.reset() + self.role_name = "norostat" - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + super().setUp() def test_meta_norostat(self): """Basic integration test for meta_norostat endpoint""" self.cur.execute( - "INSERT INTO norostat_raw_datatable_version_list(release_date, parse_time) VALUES (%s, %s)", + "INSERT INTO `norostat_raw_datatable_version_list`(`release_date`, `parse_time`) VALUES (%s, %s)", ("2014-10-22", "2048-12-08 15:22:51"), ) self.cur.execute( - 'INSERT INTO norostat_raw_datatable_location_pool(`location`) VALUES ("Minnesota, Ohio, Oregon, Tennessee, and Wisconsin")' + 'INSERT INTO `norostat_raw_datatable_location_pool`(`location`) VALUES ("Minnesota, Ohio, Oregon, Tennessee, and Wisconsin")' ) self.cnx.commit() - response = Epidata.meta_norostat(auth="norostat_key") + response = self.epidata.meta_norostat(auth="norostat_key") self.assertEqual( response, { diff --git a/integrations/server/test_nidss_dengue.py b/integrations/server/test_nidss_dengue.py index d57d2a18a..fc537ffcc 100644 --- a/integrations/server/test_nidss_dengue.py +++ b/integrations/server/test_nidss_dengue.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class NiddsDengueTest(unittest.TestCase): +class NiddsDengueTest(BasicIntegrationTest): """Basic integration tests for nids_dengue endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE nidss_dengue") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["nidss_dengue"] + super().setUp() def test_nidss_dengue(self): """Basic integration test for nidds_dengue endpoint""" self.cur.execute( - "INSERT INTO nidss_dengue(epiweek, location, region, count) VALUES(%s, %s, %s, %s)", + "INSERT INTO `nidss_dengue`(`epiweek`, `location`, `region`, `count`) VALUES(%s, %s, %s, %s)", ("200340", "SomeCity", "Central", "0"), ) self.cnx.commit() - response = Epidata.nidss_dengue(locations="SomeCity", epiweeks="200340") + response = self.epidata.nidss_dengue(locations="SomeCity", epiweeks="200340") self.assertEqual( response, {"epidata": [{"location": "SomeCity", "epiweek": 200340, "count": 0}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_nidss_flu.py b/integrations/server/test_nidss_flu.py index 6f38559ae..9cb06e1fd 100644 --- a/integrations/server/test_nidss_flu.py +++ b/integrations/server/test_nidss_flu.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class NiddsFluTest(unittest.TestCase): +class NiddsFluTest(BasicIntegrationTest): """Basic integration tests for nids_flu endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE nidss_flu") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["nidss_flu"] + super().setUp() def test_nidss_flu(self): """Basic integration test for nidds_flu endpoint""" self.cur.execute( - "INSERT INTO nidss_flu(`release_date`, `issue`, `epiweek`, `region`, `lag`, `visits`, `ili`) VALUES(%s, %s, %s, %s, %s, %s, %s)", + "INSERT INTO `nidss_flu`(`release_date`, `issue`, `epiweek`, `region`, `lag`, `visits`, `ili`) VALUES(%s, %s, %s, %s, %s, %s, %s)", ("2015-09-05", "201530", "200111", "SomeRegion", "222", "333", "444"), ) self.cnx.commit() - response = Epidata.nidss_flu(regions="SomeRegion", epiweeks="200111") + response = self.epidata.nidss_flu(regions="SomeRegion", epiweeks="200111") self.assertEqual( response, { diff --git a/integrations/server/test_norostat.py b/integrations/server/test_norostat.py index 461dfc779..7adb901e7 100644 --- a/integrations/server/test_norostat.py +++ b/integrations/server/test_norostat.py @@ -1,33 +1,14 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class NorostatTest(unittest.TestCase): +class NorostatTest(BasicIntegrationTest): """Basic integration tests for norostat endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute( - """ + create_norostat_point_diffs = """ CREATE TABLE IF NOT EXISTS `norostat_point_diffs` ( `release_date` date NOT NULL, `parse_time` datetime NOT NULL, @@ -40,48 +21,33 @@ def setUp(self) -> None: CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ - ) - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - - cur.execute("DELETE FROM norostat_point_diffs") - cur.execute("DELETE FROM norostat_point_version_list") - cur.execute("DELETE FROM norostat_raw_datatable_location_pool") - cur.execute("DELETE FROM norostat_raw_datatable_version_list") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("norostat_key", "norostat_email")') - cur.execute('INSERT INTO user_role(name) VALUES("norostat") ON DUPLICATE KEY UPDATE name="norostat"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="norostat_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.create_tables_list = [create_norostat_point_diffs] + self.delete_from_tables_list = [ + "norostat_point_diffs", + "norostat_point_version_list", + "norostat_raw_datatable_location_pool", + "norostat_raw_datatable_version_list", + ] + self.role_name = "norostat" + super().setUp() def test_norostat(self): """Basic integration test for norostat endpoint""" - self.cur.execute('INSERT INTO norostat_raw_datatable_version_list(release_date, parse_time) VALUES ("2023-07-19", "2023-07-10 15:24:51")') - self.cur.execute('INSERT INTO norostat_raw_datatable_location_pool(location_id, location) VALUES("1", "SomeTestLocation")') - self.cur.execute('INSERT INTO norostat_point_version_list(`release_date`, `parse_time`) VALUES("2023-07-19", "2023-07-10 15:24:51")') - self.cur.execute('INSERT INTO norostat_point_diffs(release_date, parse_time, location_id, epiweek, new_value) VALUES("2023-07-19", "2023-07-10 15:24:51", "1", "202329", 10)') + self.cur.execute( + 'INSERT INTO `norostat_raw_datatable_version_list`(`release_date`, `parse_time`) VALUES ("2023-07-19", "2023-07-10 15:24:51")' + ) + self.cur.execute( + 'INSERT INTO `norostat_raw_datatable_location_pool`(`location_id`, `location`) VALUES("1", "SomeTestLocation")' + ) + self.cur.execute( + 'INSERT INTO `norostat_point_version_list`(`release_date`, `parse_time`) VALUES("2023-07-19", "2023-07-10 15:24:51")' + ) + self.cur.execute( + 'INSERT INTO `norostat_point_diffs`(`release_date`, `parse_time`, `location_id`, `epiweek`, `new_value`) VALUES("2023-07-19", "2023-07-10 15:24:51", "1", "202329", 10)' + ) self.cnx.commit() - response = Epidata.norostat(auth="norostat_key", location="SomeTestLocation", epiweeks="202329") + response = self.epidata.norostat(auth="norostat_key", location="SomeTestLocation", epiweeks="202329") self.assertEqual( response, { diff --git a/integrations/server/test_nowcast.py b/integrations/server/test_nowcast.py index 8f3d4293b..51332d342 100644 --- a/integrations/server/test_nowcast.py +++ b/integrations/server/test_nowcast.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class NowcastTest(unittest.TestCase): +class NowcastTest(BasicIntegrationTest): """Basic integration tests for nowcast endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE nowcasts") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["nowcasts"] + super().setUp() def test_nowcast(self): """Basic integration test for nowcast endpoint""" self.cur.execute( - "INSERT INTO nowcasts(`epiweek`, `location`, `value`, `std`) VALUES(%s, %s, %s, %s)", + "INSERT INTO `nowcasts`(`epiweek`, `location`, `value`, `std`) VALUES(%s, %s, %s, %s)", ("201145", "nat", "12345", "0.01234"), ) self.cnx.commit() - response = Epidata.nowcast(locations="nat", epiweeks="201145") + response = self.epidata.nowcast(locations="nat", epiweeks="201145") self.assertEqual( response, { diff --git a/integrations/server/test_paho_dengue.py b/integrations/server/test_paho_dengue.py index 01767a582..0bb5391ed 100644 --- a/integrations/server/test_paho_dengue.py +++ b/integrations/server/test_paho_dengue.py @@ -1,61 +1,24 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class PahoDengueTest(unittest.TestCase): +class PahoDengueTest(BasicIntegrationTest): """Basic integration tests for paho_dengue endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE paho_dengue") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["paho_dengue"] + super().setUp() def test_paho_dengue(self): """Basic integration test for paho_dengue endpoint""" self.cur.execute( - "INSERT INTO paho_dengue(`release_date`, `issue`, `epiweek`, `lag`, `region`, `total_pop`, `serotype`, `num_dengue`, `incidence_rate`, `num_severe`, `num_deaths`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", + "INSERT INTO `paho_dengue`(`release_date`, `issue`, `epiweek`, `lag`, `region`, `total_pop`, `serotype`, `num_dengue`, `incidence_rate`, `num_severe`, `num_deaths`) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", ("2018-12-01", "201848", "201454", "204", "AG", "91", "DEN 1,4", "37", "40.66", "0", "0"), ) self.cnx.commit() - response = Epidata.paho_dengue(regions="AG", epiweeks="201454") + response = self.epidata.paho_dengue(regions="AG", epiweeks="201454") self.assertEqual( response, { diff --git a/integrations/server/test_quidel.py b/integrations/server/test_quidel.py index c16d4e770..6ceefd273 100644 --- a/integrations/server/test_quidel.py +++ b/integrations/server/test_quidel.py @@ -1,66 +1,25 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class QuidelTest(unittest.TestCase): +class QuidelTest(BasicIntegrationTest): """Basic integration tests for quidel endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - cur.execute("TRUNCATE TABLE quidel") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("quidel_key", "quidel_email")') - cur.execute('INSERT INTO user_role(name) VALUES("quidel") ON DUPLICATE KEY UPDATE name="quidel"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="quidel_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["quidel"] + self.role_name = "quidel" + super().setUp() def test_quidel(self): """Basic integration test for quidel endpoint""" self.cur.execute( - "INSERT INTO quidel(location, epiweek, value, num_rows, num_devices) VALUES(%s, %s, %s, %s, %s)", + "INSERT INTO `quidel`(`location`, `epiweek`, `value`, `num_rows`, `num_devices`) VALUES(%s, %s, %s, %s, %s)", ("loc1", "201111", "1", "0", "0"), ) self.cnx.commit() - response = Epidata.quidel(locations="loc1", epiweeks="201111", auth="quidel_key") + response = self.epidata.quidel(locations="loc1", epiweeks="201111", auth="quidel_key") self.assertEqual( response, {"epidata": [{"location": "loc1", "epiweek": 201111, "value": 1.0}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_sensors.py b/integrations/server/test_sensors.py index 6cf851519..d236bf7eb 100644 --- a/integrations/server/test_sensors.py +++ b/integrations/server/test_sensors.py @@ -1,66 +1,25 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class SensorsTest(unittest.TestCase): +class SensorsTest(BasicIntegrationTest): """Basic integration tests for sensors endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - cur.execute("TRUNCATE TABLE sensors") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("sensors_key", "sensors_email")') - cur.execute('INSERT INTO user_role(name) VALUES("sensors") ON DUPLICATE KEY UPDATE name="sensors"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="sensors_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["sensors"] + self.role_name = "sensors" + super().setUp() - def test_gft(self): + def test_sensors(self): """Basic integration test for sensors endpoint""" self.cur.execute( - "INSERT INTO sensors(name, epiweek, location, value) VALUES(%s, %s, %s, %s)", + "INSERT INTO `sensors`(`name`, `epiweek`, `location`, `value`) VALUES(%s, %s, %s, %s)", ("sens1", "201111", "loc1", "222"), ) self.cnx.commit() - response = Epidata.sensors(names="sens1", locations="loc1", epiweeks="201111", auth="sensors_key") + response = self.epidata.sensors(names="sens1", locations="loc1", epiweeks="201111", auth="sensors_key") self.assertEqual( response, { diff --git a/integrations/server/test_signal_dashboard.py b/integrations/server/test_signal_dashboard.py index a442d49a0..bebf6357f 100644 --- a/integrations/server/test_signal_dashboard.py +++ b/integrations/server/test_signal_dashboard.py @@ -1,64 +1,26 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class SignalDashboardTest(unittest.TestCase): +class SignalDashboardTest(BasicIntegrationTest): """Basic integration tests for signal_dashboard_coverage and signal_dashboard_status endpints.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") + self.delete_from_tables_list = ["dashboard_signal_coverage", "dashboard_signal"] + super().setUp() - cur.execute("DELETE FROM dashboard_signal_coverage") - cur.execute("DELETE FROM dashboard_signal") - - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cur.execute( - "INSERT INTO dashboard_signal(id, name, source, covidcast_signal, enabled, latest_coverage_update, latest_status_update) VALUES(%s, %s, %s, %s, %s, %s, %s)", + self.cur.execute( + "INSERT INTO `dashboard_signal`(`id`, `name`, `source`, `covidcast_signal`, `enabled`, `latest_coverage_update`, `latest_status_update`) VALUES(%s, %s, %s, %s, %s, %s, %s)", ("1", "Change", "chng", "smoothed_outpatient_covid", "1", "2021-10-02", "2021-11-27"), ) - cur.execute( - "INSERT INTO dashboard_signal_coverage(signal_id, date, geo_type, count) VALUES(%s, %s, %s, %s)", + self.cur.execute( + "INSERT INTO `dashboard_signal_coverage`(`signal_id`, `date`, `geo_type`, `count`) VALUES(%s, %s, %s, %s)", ("1", "2021-10-02", "county", "2222"), ) - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.cnx.commit() def test_signal_dashboard_coverage(self): """Basic integration test for signal_dashboard_coverage endpoint""" @@ -66,7 +28,7 @@ def test_signal_dashboard_coverage(self): params = { "endpoint": "signal_dashboard_coverage", } - response = Epidata._request(params=params) + response = self.epidata._request(params=params) self.assertEqual( response, { @@ -82,7 +44,7 @@ def test_signal_dashboard_status(self): params = { "endpoint": "signal_dashboard_status", } - response = Epidata._request(params=params) + response = self.epidata._request(params=params) self.assertEqual( response, { diff --git a/integrations/server/test_twitter.py b/integrations/server/test_twitter.py index 46cda4acc..b32ad8290 100644 --- a/integrations/server/test_twitter.py +++ b/integrations/server/test_twitter.py @@ -1,66 +1,25 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class TwitterTest(unittest.TestCase): +class TwitterTest(BasicIntegrationTest): """Basic integration tests for twitter endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE user_role") - cur.execute("TRUNCATE TABLE user_role_link") - cur.execute("TRUNCATE TABLE twitter") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("twitter_key", "twitter_email")') - cur.execute('INSERT INTO user_role(name) VALUES("twitter") ON DUPLICATE KEY UPDATE name="twitter"') - cur.execute( - 'INSERT INTO user_role_link(user_id, role_id) SELECT api_user.id, 1 FROM api_user WHERE api_key="twitter_key"' - ) - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["twitter"] + self.role_name = "twitter" + super().setUp() def test_twitter(self): """Basic integration test for twitter endpoint""" self.cur.execute( - 'INSERT INTO twitter(date, state, num, total) VALUES ("2015-07-29", "AK", "1", "223"), ("2020-07-29", "CT", "12", "778")', + 'INSERT INTO `twitter`(`date`, `state`, `num`, `total`) VALUES ("2015-07-29", "AK", "1", "223"), ("2020-07-29", "CT", "12", "778")', ) self.cnx.commit() - response = Epidata.twitter(auth="twitter_key", locations="cen9", dates="20150701-20160101") + response = self.epidata.twitter(auth="twitter_key", locations="cen9", dates="20150701-20160101") self.assertEqual( response, { diff --git a/integrations/server/test_wiki.py b/integrations/server/test_wiki.py index 6763d7d62..982c1448b 100644 --- a/integrations/server/test_wiki.py +++ b/integrations/server/test_wiki.py @@ -1,65 +1,27 @@ -# standard library -import unittest - -# third party -import mysql.connector - # first party -from delphi.epidata.client.delphi_epidata import Epidata -from delphi.epidata.server._limiter import limiter +from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest -class WikiTest(unittest.TestCase): +class WikiTest(BasicIntegrationTest): """Basic integration tests for wiki endpint.""" - @classmethod - def setUpClass(cls) -> None: - """Perform one-time setup.""" - - # use local instance of the Epidata API - Epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - Epidata.auth = ("epidata", "key") - def setUp(self) -> None: """Perform per-test setup.""" - # connect to the `epidata` database - cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") - cur = cnx.cursor() - - cur.execute("DELETE FROM api_user") - cur.execute("TRUNCATE TABLE wiki") - cur.execute("TRUNCATE TABLE wiki_meta") - - cur.execute('INSERT INTO api_user(api_key, email) VALUES("key", "email")') - - cnx.commit() - cur.close() - - self.cnx = cnx - self.cur = cnx.cursor() - - @staticmethod - def _clear_limits(): - limiter.storage.reset() - - def tearDown(self) -> None: - """Perform per-test teardown.""" - self.cur.close() - self.cnx.close() - self._clear_limits() + self.truncate_tables_list = ["wiki", "wiki_meta"] + super().setUp() def test_wiki(self): """Basic integration test for wiki endpoint""" self.cur.execute( - 'INSERT INTO wiki(datetime, article, count, language) VALUES ("2007-12-09 18:00:00", "amantadine", "3", "en"), ("2008-12-09 18:00:00", "test", "5", "en")', + 'INSERT INTO `wiki`(`datetime`, `article`, `count`, `language`) VALUES ("2007-12-09 18:00:00", "amantadine", "3", "en"), ("2008-12-09 18:00:00", "test", "5", "en")', ) self.cur.execute( - 'INSERT INTO wiki_meta(datetime, date, epiweek, total, language) VALUES ("2007-12-09 18:00:00", "2007-12-09", "200750", "969214", "en"), ("2008-12-09 18:00:00", "2008-12-09", "200750", "123321", "en")' + 'INSERT INTO `wiki_meta`(`datetime`, `date`, `epiweek`, `total`, `language`) VALUES ("2007-12-09 18:00:00", "2007-12-09", "200750", "969214", "en"), ("2008-12-09 18:00:00", "2008-12-09", "200750", "123321", "en")' ) self.cnx.commit() - response = Epidata.wiki(articles="test", epiweeks="200701-200801") + response = self.epidata.wiki(articles="test", epiweeks="200701-200801") self.assertEqual( response, { diff --git a/src/common/integration_test_base_class.py b/src/common/integration_test_base_class.py new file mode 100644 index 000000000..580331d4a --- /dev/null +++ b/src/common/integration_test_base_class.py @@ -0,0 +1,79 @@ +# standard library +import unittest + +# third party +import mysql.connector + +# first party +from delphi.epidata.client.delphi_epidata import Epidata +from delphi.epidata.server._limiter import limiter + + +class BasicIntegrationTest(unittest.TestCase): + """Basic integration test class""" + + def __init__(self, methodName: str = "runTest") -> None: + super().__init__(methodName) + self.delete_from_tables_list = [] + self.truncate_tables_list = [] + self.create_tables_list = [] + self.role_name = None + self.epidata = Epidata + self.epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + self.epidata.auth = ("epidata", "key") + + def delete_from_table(self, cur, table_name: str) -> None: + cur.execute(f"DELETE FROM `{table_name}`") + + def truncate_table(self, cur, table_name: str) -> None: + cur.execute(f"TRUNCATE TABLE `{table_name}`") + + def create_table(self, cur, create_table_stmt: str): + cur.execute(create_table_stmt) + + def create_key_with_role(self, cur, role_name: str): + cur.execute("TRUNCATE TABLE `user_role`") + cur.execute("TRUNCATE TABLE `user_role_link`") + cur.execute(f'INSERT INTO `api_user`(`api_key`, `email`) VALUES("{role_name}_key", "{role_name}_email")') + cur.execute(f'INSERT INTO `user_role`(`name`) VALUES("{role_name}")') + cur.execute( + f'INSERT INTO `user_role_link`(`user_id`, `role_id`) SELECT `api_user`.`id`, 1 FROM `api_user` WHERE `api_key`="{role_name}_key"' + ) + + def setUp(self) -> None: + """Perform per-test setup.""" + + # connect to the `epidata` database + cnx = mysql.connector.connect(user="user", password="pass", host="delphi_database_epidata", database="epidata") + cur = cnx.cursor() + + cur.execute("DELETE FROM `api_user`") + cur.execute('INSERT INTO `api_user`(`api_key`, `email`) VALUES ("key", "email")') + + for stmt in self.create_tables_list: + self.create_table(cur, stmt) + + for table_name in self.delete_from_tables_list: + self.delete_from_table(cur, table_name) + + for table_name in self.truncate_tables_list: + self.truncate_table(cur, table_name) + + if self.role_name: + self.create_key_with_role(cur, self.role_name) + + cnx.commit() + cur.close() + + self.cnx = cnx + self.cur = cnx.cursor() + + @staticmethod + def _clear_limits() -> None: + limiter.storage.reset() + + def tearDown(self) -> None: + """Perform per-test teardown.""" + self.cur.close() + self.cnx.close() + self._clear_limits() diff --git a/src/server/_config.py b/src/server/_config.py index 5d905c968..f6bbf28a0 100644 --- a/src/server/_config.py +++ b/src/server/_config.py @@ -93,8 +93,16 @@ REDIS_HOST = os.environ.get("REDIS_HOST", "delphi_redis") REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD", "1234") +# testing mode to lower rate-limit in order to reduce number of required requests to hit the rate limit while runnig tests +# by default is set to False when is not provided +TESTING_MODE = os.environ.get("TESTING_MODE", False) + # https://flask-limiter.readthedocs.io/en/stable/#rate-limit-string-notation RATE_LIMIT = os.environ.get("RATE_LIMIT", "60/hour") + +if TESTING_MODE is not False: + RATE_LIMIT = "5/hour" + # fixed-window, fixed-window-elastic-expiry, or moving-window # see also https://flask-limiter.readthedocs.io/en/stable/#rate-limiting-strategies RATELIMIT_STRATEGY = os.environ.get("RATELIMIT_STRATEGY", "fixed-window") From 34d9194fac538bb51a2bf00b6d5b2820b4049a32 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 21 Jul 2023 15:52:24 +0300 Subject: [PATCH 03/14] Added TESTING_MODE to the ci.yaml, removed from Makefile --- .github/workflows/ci.yaml | 2 +- dev/local/Makefile | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1f7664b46..37ea90819 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -75,7 +75,7 @@ jobs: - name: Start delphi_web_epidata run: | - docker run --rm -d -p 10080:80 --env "MODULE_NAME=delphi.epidata.server.main" --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "REDIS_HOST=delphi_redis" --env "REDIS_PASSWORD=1234" --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" --env "API_KEY_ADMIN_PASSWORD=test_admin_password" --network delphi-net --name delphi_web_epidata delphi_web_epidata + docker run --rm -d -p 10080:80 --env "MODULE_NAME=delphi.epidata.server.main" --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "REDIS_HOST=delphi_redis" --env "REDIS_PASSWORD=1234" --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" --env "API_KEY_ADMIN_PASSWORD=test_admin_password" --env "TESTING_MODE=True" --network delphi-net --name delphi_web_epidata delphi_web_epidata docker ps - name: Run Unit Tests diff --git a/dev/local/Makefile b/dev/local/Makefile index 018413f2a..e7e896aa6 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -102,7 +102,6 @@ web: --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \ --env "REDIS_HOST=delphi_redis" \ --env "REDIS_PASSWORD=1234" \ - --env "TESTING_MODE=True" \ --env "API_KEY_ADMIN_PASSWORD=test_admin_password" \ --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \ --network delphi-net --name delphi_web_epidata \ From 64a2b39348046df70f499d3ba5b9d14591d2f758 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Wed, 26 Jul 2023 18:13:30 +0300 Subject: [PATCH 04/14] Updated acquisition tests with missing api_key creation --- .../covidcast/test_covidcast_meta_caching.py | 13 +++++++++++++ .../acquisition/covidcast/test_csv_uploading.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/integrations/acquisition/covidcast/test_covidcast_meta_caching.py b/integrations/acquisition/covidcast/test_covidcast_meta_caching.py index e746c4ef1..fc903896a 100644 --- a/integrations/acquisition/covidcast/test_covidcast_meta_caching.py +++ b/integrations/acquisition/covidcast/test_covidcast_meta_caching.py @@ -58,6 +58,19 @@ def setUp(self): secrets.db.host = 'delphi_database_epidata' secrets.db.epi = ('user', 'pass') + epidata_cnx = mysql.connector.connect( + user='user', + password='pass', + host='delphi_database_epidata', + database='epidata') + epidata_cur = epidata_cnx.cursor() + + epidata_cur.execute("DELETE FROM `api_user`") + epidata_cur.execute('INSERT INTO `api_user`(`api_key`, `email`) VALUES("key", "email")') + epidata_cnx.commit() + epidata_cur.close() + epidata_cnx.close() + # use the local instance of the Epidata API Epidata.BASE_URL = BASE_URL Epidata.auth = ('epidata', 'key') diff --git a/integrations/acquisition/covidcast/test_csv_uploading.py b/integrations/acquisition/covidcast/test_csv_uploading.py index e4c9d881e..e9c066f6a 100644 --- a/integrations/acquisition/covidcast/test_csv_uploading.py +++ b/integrations/acquisition/covidcast/test_csv_uploading.py @@ -55,6 +55,19 @@ def setUp(self): secrets.db.host = 'delphi_database_epidata' secrets.db.epi = ('user', 'pass') + epidata_cnx = mysql.connector.connect( + user='user', + password='pass', + host='delphi_database_epidata', + database='epidata') + epidata_cur = epidata_cnx.cursor() + + epidata_cur.execute("DELETE FROM `api_user`") + epidata_cur.execute('INSERT INTO `api_user`(`api_key`, `email`) VALUES("key", "email")') + epidata_cnx.commit() + epidata_cur.close() + epidata_cnx.close() + # use the local instance of the Epidata API Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php' Epidata.auth = ('epidata', 'key') From 4320bac72e76661a33e1f504a1f0878dacb6a806 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Tue, 19 Sep 2023 15:09:46 +0300 Subject: [PATCH 05/14] Update src/server/_config.py Comments fix Co-authored-by: melange396 --- src/server/_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/_config.py b/src/server/_config.py index f6bbf28a0..43ca0c113 100644 --- a/src/server/_config.py +++ b/src/server/_config.py @@ -93,8 +93,8 @@ REDIS_HOST = os.environ.get("REDIS_HOST", "delphi_redis") REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD", "1234") -# testing mode to lower rate-limit in order to reduce number of required requests to hit the rate limit while runnig tests -# by default is set to False when is not provided +# mode to reduce number of required requests to hit rate limit while running tests, +# by default is set to False TESTING_MODE = os.environ.get("TESTING_MODE", False) # https://flask-limiter.readthedocs.io/en/stable/#rate-limit-string-notation From f637b32636ef03122bae76b89ffcb53ee632a45c Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Tue, 19 Sep 2023 15:10:29 +0300 Subject: [PATCH 06/14] Update integrations/server/test_delphi.py Remove unused lib Co-authored-by: melange396 --- integrations/server/test_delphi.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/integrations/server/test_delphi.py b/integrations/server/test_delphi.py index 481b9d3f5..d8610a5ce 100644 --- a/integrations/server/test_delphi.py +++ b/integrations/server/test_delphi.py @@ -1,7 +1,3 @@ -# standard library -import unittest - -# third party import json # first party From 961d339d41d3e6f64ee4eef916edb25dddd8d9a5 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Wed, 20 Sep 2023 19:31:51 +0300 Subject: [PATCH 07/14] Update integrations/server/test_meta.py Remove extra newline Co-authored-by: melange396 --- integrations/server/test_meta.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integrations/server/test_meta.py b/integrations/server/test_meta.py index c32214222..4bcc6e7cb 100644 --- a/integrations/server/test_meta.py +++ b/integrations/server/test_meta.py @@ -10,7 +10,6 @@ def setUp(self) -> None: super().setUp() def test_meta(self): - """Basic integration test for meta endpoint""" response = self.epidata.meta() self.assertEqual( From 0108ed3784cd12c4f95853b1b774ac7a31cbc562 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Thu, 21 Sep 2023 22:23:01 +0300 Subject: [PATCH 08/14] Requested changes from PR's comments --- dev/local/Makefile | 1 + integrations/server/test_api_keys.py | 103 ++++++++++--------- integrations/server/test_cdc.py | 9 +- integrations/server/test_delphi.py | 9 +- integrations/server/test_dengue_nowcast.py | 11 +- integrations/server/test_dengue_sensors.py | 11 +- integrations/server/test_ecdc_ili.py | 11 +- integrations/server/test_flusurv.py | 11 +- integrations/server/test_fluview_clinical.py | 11 +- integrations/server/test_gft.py | 11 +- integrations/server/test_ght.py | 11 +- integrations/server/test_kcdc_ili.py | 11 +- integrations/server/test_meta.py | 9 +- integrations/server/test_meta_norostat.py | 12 +-- integrations/server/test_nidss_dengue.py | 11 +- integrations/server/test_nidss_flu.py | 11 +- integrations/server/test_norostat.py | 11 +- integrations/server/test_nowcast.py | 11 +- integrations/server/test_paho_dengue.py | 11 +- integrations/server/test_quidel.py | 11 +- integrations/server/test_sensors.py | 11 +- integrations/server/test_signal_dashboard.py | 8 +- integrations/server/test_twitter.py | 11 +- integrations/server/test_wiki.py | 11 +- src/common/integration_test_base_class.py | 36 +++---- 25 files changed, 161 insertions(+), 213 deletions(-) diff --git a/dev/local/Makefile b/dev/local/Makefile index e7e896aa6..fb02668ee 100644 --- a/dev/local/Makefile +++ b/dev/local/Makefile @@ -104,6 +104,7 @@ web: --env "REDIS_PASSWORD=1234" \ --env "API_KEY_ADMIN_PASSWORD=test_admin_password" \ --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \ + --env "TESTING_MODE=True" \ --network delphi-net --name delphi_web_epidata \ delphi_web_epidata >$(LOG_WEB) 2>&1 & diff --git a/integrations/server/test_api_keys.py b/integrations/server/test_api_keys.py index 19bc4d3ff..e522fe9d7 100644 --- a/integrations/server/test_api_keys.py +++ b/integrations/server/test_api_keys.py @@ -2,32 +2,28 @@ import requests # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class APIKeysTets(BasicIntegrationTest): +class APIKeysTets(DelphiTestBase): """Tests the API Keys behaviour""" - def setUp(self): - """Perform per-test setup.""" - + def localSetUp(self): self.role_name = "cdc" - super().setUp() def _make_request(self, url: str = None, params: dict = {}, auth: tuple = None): if not url: - url = self.epidata.BASE_URL + url = self.epidata_client.BASE_URL response = requests.get(url, params=params, auth=auth) return response - + def test_public_route(self): """Test public route""" public_route = "http://delphi_web_epidata/epidata/version" status_codes = set() for _ in range(10): status_codes.add(self._make_request(public_route).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + self.assertEqual(status_codes, {200}) def test_no_multiples_data_source(self): """Test requests with no multiples and with provided `data_source` and `signal` as a separate query params.""" @@ -43,8 +39,7 @@ def test_no_multiples_data_source(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + self.assertEqual(status_codes, {200}) def test_no_multiples_source_signal(self): """Test requests with colon-delimited source-signal param presentation.""" @@ -59,10 +54,9 @@ def test_no_multiples_source_signal(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + self.assertEqual(status_codes, {200}) - def test_multiples_allowed_signal(self): + def test_multiples_allowed_signal_two_multiples(self): """Test requests with 2 multiples and allowed dashboard signal""" params = { "source": "covidcast", @@ -75,8 +69,7 @@ def test_multiples_allowed_signal(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + self.assertEqual(status_codes, {200}) def test_multiples_non_allowed_signal(self): """Test requests with 2 multiples and non-allowed dashboard signal""" @@ -91,10 +84,9 @@ def test_multiples_non_allowed_signal(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 2) self.assertEqual(status_codes, {200, 429}) - def test_multiples_mixed_allowed_signal(self): + def test_multiples_mixed_allowed_signal_two_multiples(self): """Test requests with 2 multiples and mixed-allowed dashboard signal""" params = { "source": "covidcast", @@ -107,10 +99,9 @@ def test_multiples_mixed_allowed_signal(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 2) self.assertEqual(status_codes, {200, 429}) - def test_multiples_allowed_signal(self): + def test_multiples_allowed_signal_three_multiples(self): """Test requests with 3 multiples and allowed dashboard signal""" params = { "source": "covidcast", @@ -123,10 +114,9 @@ def test_multiples_allowed_signal(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 401) + self.assertEqual(status_codes, {401}) - def test_multiples_mixed_allowed_signal(self): + def test_multiples_mixed_allowed_signal_three_multiples(self): """Test requests with 3 multiples and mixed-allowed dashboard signal""" params = { "source": "covidcast", @@ -139,8 +129,7 @@ def test_multiples_mixed_allowed_signal(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 401) + self.assertEqual(status_codes, {401}) def test_multiples_mixed_allowed_signal_api_key(self): """Test requests with 3 multiples and mixed-allowed dashboard signal + valid API Key""" @@ -154,9 +143,11 @@ def test_multiples_mixed_allowed_signal_api_key(self): } status_codes = set() for _ in range(10): - status_codes.add(self._make_request(params=params, auth=self.epidata.auth).status_code) + status_codes.add( + self._make_request(params=params, auth=self.epidata_client.auth).status_code + ) self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + self.assertEqual(status_codes, {200}) def test_multiples_allowed_signal_api_key(self): """Test requests with 3 multiples and allowed dashboard signal + valid API Key""" @@ -170,9 +161,10 @@ def test_multiples_allowed_signal_api_key(self): } status_codes = set() for _ in range(10): - status_codes.add(self._make_request(params=params, auth=self.epidata.auth).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + status_codes.add( + self._make_request(params=params, auth=self.epidata_client.auth).status_code + ) + self.assertEqual(status_codes, {200}) def test_no_multiples_allowed_signal_api_key(self): """Test requests with no multiples and allowed dashboard signal + valid API Key""" @@ -186,9 +178,10 @@ def test_no_multiples_allowed_signal_api_key(self): } status_codes = set() for _ in range(10): - status_codes.add(self._make_request(params=params, auth=self.epidata.auth).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + status_codes.add( + self._make_request(params=params, auth=self.epidata_client.auth).status_code + ) + self.assertEqual(status_codes, {200}) def test_no_multiples_allowed_signal_bad_api_key(self): """Test requests with no multiples and allowed dashboard signal + bad API Key""" @@ -202,9 +195,12 @@ def test_no_multiples_allowed_signal_bad_api_key(self): } status_codes = set() for _ in range(10): - status_codes.add(self._make_request(params=params, auth=("bad_key", "bad_email")).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + status_codes.add( + self._make_request( + params=params, auth=("bad_key", "bad_email") + ).status_code + ) + self.assertEqual(status_codes, {200}) def test_restricted_endpoint_no_key(self): """Test restricted endpoint with no auth key""" @@ -212,32 +208,43 @@ def test_restricted_endpoint_no_key(self): status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 401) + self.assertEqual(status_codes, {401}) def test_restricted_endpoint_invalid_key(self): """Test restricted endpoint with invalid auth key""" - params = {"source": "cdc", "regions": "1as", "epiweeks": "202020", "auth": "invalid_key"} + params = { + "source": "cdc", + "regions": "1as", + "epiweeks": "202020", + "auth": "invalid_key", + } status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 401) + self.assertEqual(status_codes, {401}) def test_restricted_endpoint_no_roles_key(self): """Test restricted endpoint with no roles key""" - params = {"source": "cdc", "regions": "1as", "epiweeks": "202020", "auth": "key"} + params = { + "source": "cdc", + "regions": "1as", + "epiweeks": "202020", + "auth": "key", + } status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 401) + self.assertEqual(status_codes, {401}) def test_restricted_endpoint_valid_roles_key(self): """Test restricted endpoint with valid auth key with required role""" - params = {"source": "cdc", "regions": "1as", "epiweeks": "202020", "auth": "cdc_key"} + params = { + "source": "cdc", + "regions": "1as", + "epiweeks": "202020", + "auth": "cdc_key", + } status_codes = set() for _ in range(10): status_codes.add(self._make_request(params=params).status_code) - self.assertEqual(len(status_codes), 1) - self.assertEqual(next(iter(status_codes)), 200) + self.assertEqual(status_codes, {200}) diff --git a/integrations/server/test_cdc.py b/integrations/server/test_cdc.py index 7234f9eb0..d468bd162 100644 --- a/integrations/server/test_cdc.py +++ b/integrations/server/test_cdc.py @@ -1,14 +1,13 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class CdcTest(BasicIntegrationTest): +class CdcTest(DelphiTestBase): """Basic integration tests for cdc endpint.""" - def setUp(self) -> None: + def localSetUp(self) -> None: self.truncate_tables_list = ["cdc_extract"] self.role_name = "cdc" - super().setUp() def test_cdc(self): """Basic integration test for cdc endpoint""" @@ -17,7 +16,7 @@ def test_cdc(self): ("201102", "AK", "16", "35", "51", "96", "30", "748", "243", "433", "65"), ) self.cnx.commit() - response = self.epidata.cdc(auth="cdc_key", epiweeks=201102, locations="cen9") + response = self.epidata_client.cdc(auth="cdc_key", epiweeks=201102, locations="cen9") self.assertEqual( response, { diff --git a/integrations/server/test_delphi.py b/integrations/server/test_delphi.py index d8610a5ce..fc3e3bc7e 100644 --- a/integrations/server/test_delphi.py +++ b/integrations/server/test_delphi.py @@ -1,15 +1,14 @@ import json # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class DelphiTest(BasicIntegrationTest): +class DelphiTest(DelphiTestBase): """Basic integration tests for delphi endpint.""" - def setUp(self) -> None: + def localSetUp(self): self.truncate_tables_list = ["forecasts"] - super().setUp() def test_delphi(self): """Basic integration test for delphi endpoint""" @@ -33,7 +32,7 @@ def test_delphi(self): ), ) self.cnx.commit() - response = self.epidata.delphi(system="eb", epiweek=201441) + response = self.epidata_client.delphi(system="eb", epiweek=201441) self.assertEqual( response, { diff --git a/integrations/server/test_dengue_nowcast.py b/integrations/server/test_dengue_nowcast.py index dea91979d..79f9765f4 100644 --- a/integrations/server/test_dengue_nowcast.py +++ b/integrations/server/test_dengue_nowcast.py @@ -1,13 +1,11 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class DengueNowcastTest(BasicIntegrationTest): +class DengueNowcastTest(DelphiTestBase): """Basic integration tests for dengue_nowcast endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): create_dengue_nowcasts = """ CREATE TABLE IF NOT EXISTS `dengue_nowcasts` ( `id` int NOT NULL AUTO_INCREMENT, @@ -25,7 +23,6 @@ def setUp(self) -> None: """ self.create_tables_list = [create_dengue_nowcasts] self.truncate_tables_list = ["dengue_nowcasts"] - super().setUp() def test_dengue_nowcasts(self): """Basic integration test for dengue_nowcasts endpoint""" @@ -34,7 +31,7 @@ def test_dengue_nowcasts(self): ("num_dengue", "201409", "ar", "85263", "351456"), ) self.cnx.commit() - response = self.epidata.dengue_nowcast(locations="ar", epiweeks=201409) + response = self.epidata_client.dengue_nowcast(locations="ar", epiweeks=201409) self.assertEqual( response, { diff --git a/integrations/server/test_dengue_sensors.py b/integrations/server/test_dengue_sensors.py index 75ff9028a..55d103367 100644 --- a/integrations/server/test_dengue_sensors.py +++ b/integrations/server/test_dengue_sensors.py @@ -1,13 +1,11 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class DengueSensorsTest(BasicIntegrationTest): +class DengueSensorsTest(DelphiTestBase): """Basic integration tests for dengue_sensors endpint.""" - def setUp(self) -> None: - """Perfor per-test setup.""" - + def localSetUp(self): create_dengue_sensors = """ CREATE TABLE IF NOT EXISTS `dengue_sensors` ( `id` int NOT NULL AUTO_INCREMENT, @@ -26,7 +24,6 @@ def setUp(self) -> None: self.create_tables_list = [create_dengue_sensors] self.truncate_tables_list = ["dengue_sensors"] self.role_name = "sensors" - super().setUp() def test_dengue_sensors(self): """Basic integration test for dengue_sensors endpoint""" @@ -35,7 +32,7 @@ def test_dengue_sensors(self): ("num_dengue", "ght", "201432", "ag", "1234"), ) self.cnx.commit() - response = self.epidata.dengue_sensors(auth="sensors_key", names="ght", locations="ag", epiweeks="201432") + response = self.epidata_client.dengue_sensors(auth="sensors_key", names="ght", locations="ag", epiweeks="201432") self.assertEqual( response, { diff --git a/integrations/server/test_ecdc_ili.py b/integrations/server/test_ecdc_ili.py index 3c65cb2c2..5fe24bcd3 100644 --- a/integrations/server/test_ecdc_ili.py +++ b/integrations/server/test_ecdc_ili.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class EcdcIliTest(BasicIntegrationTest): +class EcdcIliTest(DelphiTestBase): """Basic integration tests for edcd_ili endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["ecdc_ili"] - super().setUp() def test_ecdc_ili(self): """Basic integration test for ecdc_ili endpoint""" @@ -18,7 +15,7 @@ def test_ecdc_ili(self): ("2020-03-26", "202012", "201840", "76", "Armenia", "0"), ) self.cnx.commit() - response = self.epidata.ecdc_ili(regions="Armenia", epiweeks="201840") + response = self.epidata_client.ecdc_ili(regions="Armenia", epiweeks="201840") self.assertEqual( response, { diff --git a/integrations/server/test_flusurv.py b/integrations/server/test_flusurv.py index e818a2698..33f0f00b8 100644 --- a/integrations/server/test_flusurv.py +++ b/integrations/server/test_flusurv.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class FlusurvTest(BasicIntegrationTest): +class FlusurvTest(DelphiTestBase): """Basic integration tests for flusurv endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["flusurv"] - super().setUp() def test_flusurv(self): """Basic integration test for flusurv endpoint""" @@ -18,7 +15,7 @@ def test_flusurv(self): ("2012-11-02", "201243", "201143", "CA", "52", "0", "0", "0", "0.151", "0", "0.029", "0", "0", "0"), ) self.cnx.commit() - response = self.epidata.flusurv(epiweeks=201143, locations="CA") + response = self.epidata_client.flusurv(epiweeks=201143, locations="CA") self.assertEqual( response, { diff --git a/integrations/server/test_fluview_clinical.py b/integrations/server/test_fluview_clinical.py index 77f0d76ea..8ebccfc9e 100644 --- a/integrations/server/test_fluview_clinical.py +++ b/integrations/server/test_fluview_clinical.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class FluviewClinicalTest(BasicIntegrationTest): +class FluviewClinicalTest(DelphiTestBase): """Basic integration tests for fluview_clinical endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["fluview_clinical"] - super().setUp() def test_fluview_clinical(self): """Basic integration test for fluview_clinical endpoint""" @@ -18,7 +15,7 @@ def test_fluview_clinical(self): ("2018-10-10", "201839", "201640", "al", "103", "406", "4", "1", "1.32", "0.99", "0.25"), ) self.cnx.commit() - response = self.epidata.fluview_clinical(epiweeks=201640, regions="al") + response = self.epidata_client.fluview_clinical(epiweeks=201640, regions="al") self.assertEqual( response, { diff --git a/integrations/server/test_gft.py b/integrations/server/test_gft.py index f241769f4..3f2a68526 100644 --- a/integrations/server/test_gft.py +++ b/integrations/server/test_gft.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class GftTest(BasicIntegrationTest): +class GftTest(DelphiTestBase): """Basic integration tests for gft endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["gft"] - super().setUp() def test_gft(self): """Basic integration test for gft endpoint""" @@ -18,7 +15,7 @@ def test_gft(self): ("200340", "nat", "902"), ) self.cnx.commit() - response = self.epidata.gft(locations="nat", epiweeks="200340") + response = self.epidata_client.gft(locations="nat", epiweeks="200340") self.assertEqual( response, {"epidata": [{"location": "nat", "epiweek": 200340, "num": 902}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_ght.py b/integrations/server/test_ght.py index a8ea6f33d..67b135aef 100644 --- a/integrations/server/test_ght.py +++ b/integrations/server/test_ght.py @@ -1,16 +1,13 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class GhtTest(BasicIntegrationTest): +class GhtTest(DelphiTestBase): """Basic integration tests for ght endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["ght"] self.role_name = "ght" - super().setUp() def test_ght(self): """Basic integration test for ght endpoint""" @@ -19,7 +16,7 @@ def test_ght(self): ("/n/query", "US", "200101", "12345"), ) self.cnx.commit() - response = self.epidata.ght(locations="US", epiweeks="200101", query="/n/query", auth="ght_key") + response = self.epidata_client.ght(locations="US", epiweeks="200101", query="/n/query", auth="ght_key") self.assertEqual( response, {"epidata": [{"location": "US", "epiweek": 200101, "value": 12345.0}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_kcdc_ili.py b/integrations/server/test_kcdc_ili.py index 5474c28b9..aab40baa6 100644 --- a/integrations/server/test_kcdc_ili.py +++ b/integrations/server/test_kcdc_ili.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class KcdcIliTest(BasicIntegrationTest): +class KcdcIliTest(DelphiTestBase): """Basic integration tests for kcdc_ili endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["kcdc_ili"] - super().setUp() def test_kcdc_ili(self): """Basic integration test for kcdc_ili endpoint""" @@ -18,7 +15,7 @@ def test_kcdc_ili(self): ("2020-03-27", "202013", "200432", "222", "REG", "0.25"), ) self.cnx.commit() - response = self.epidata.kcdc_ili(regions="REG", epiweeks="200432") + response = self.epidata_client.kcdc_ili(regions="REG", epiweeks="200432") self.assertEqual( response, { diff --git a/integrations/server/test_meta.py b/integrations/server/test_meta.py index 4bcc6e7cb..295a5cd98 100644 --- a/integrations/server/test_meta.py +++ b/integrations/server/test_meta.py @@ -1,17 +1,16 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class MetaTest(BasicIntegrationTest): +class MetaTest(DelphiTestBase): """Basic integration tests for meta endpint.""" - def setUp(self) -> None: + def localSetUp(self): self.truncate_tables_list = ["forecasts", "fluview", "wiki", "wiki_meta", "twitter"] - super().setUp() def test_meta(self): """Basic integration test for meta endpoint""" - response = self.epidata.meta() + response = self.epidata_client.meta() self.assertEqual( response, { diff --git a/integrations/server/test_meta_norostat.py b/integrations/server/test_meta_norostat.py index b75b86a1e..e336edba3 100644 --- a/integrations/server/test_meta_norostat.py +++ b/integrations/server/test_meta_norostat.py @@ -1,13 +1,11 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class MetaNorostatTest(BasicIntegrationTest): +class MetaNorostatTest(DelphiTestBase): """Basic integration tests for meta_norostat endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): create_raw_datatable_version_list = """ CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_version_list` ( `release_date` date NOT NULL, @@ -64,8 +62,6 @@ def setUp(self) -> None: self.role_name = "norostat" - super().setUp() - def test_meta_norostat(self): """Basic integration test for meta_norostat endpoint""" @@ -77,7 +73,7 @@ def test_meta_norostat(self): 'INSERT INTO `norostat_raw_datatable_location_pool`(`location`) VALUES ("Minnesota, Ohio, Oregon, Tennessee, and Wisconsin")' ) self.cnx.commit() - response = self.epidata.meta_norostat(auth="norostat_key") + response = self.epidata_client.meta_norostat(auth="norostat_key") self.assertEqual( response, { diff --git a/integrations/server/test_nidss_dengue.py b/integrations/server/test_nidss_dengue.py index fc537ffcc..679937ea6 100644 --- a/integrations/server/test_nidss_dengue.py +++ b/integrations/server/test_nidss_dengue.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class NiddsDengueTest(BasicIntegrationTest): +class NiddsDengueTest(DelphiTestBase): """Basic integration tests for nids_dengue endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["nidss_dengue"] - super().setUp() def test_nidss_dengue(self): """Basic integration test for nidds_dengue endpoint""" @@ -18,7 +15,7 @@ def test_nidss_dengue(self): ("200340", "SomeCity", "Central", "0"), ) self.cnx.commit() - response = self.epidata.nidss_dengue(locations="SomeCity", epiweeks="200340") + response = self.epidata_client.nidss_dengue(locations="SomeCity", epiweeks="200340") self.assertEqual( response, {"epidata": [{"location": "SomeCity", "epiweek": 200340, "count": 0}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_nidss_flu.py b/integrations/server/test_nidss_flu.py index 9cb06e1fd..0b13ee67f 100644 --- a/integrations/server/test_nidss_flu.py +++ b/integrations/server/test_nidss_flu.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class NiddsFluTest(BasicIntegrationTest): +class NiddsFluTest(DelphiTestBase): """Basic integration tests for nids_flu endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["nidss_flu"] - super().setUp() def test_nidss_flu(self): """Basic integration test for nidds_flu endpoint""" @@ -18,7 +15,7 @@ def test_nidss_flu(self): ("2015-09-05", "201530", "200111", "SomeRegion", "222", "333", "444"), ) self.cnx.commit() - response = self.epidata.nidss_flu(regions="SomeRegion", epiweeks="200111") + response = self.epidata_client.nidss_flu(regions="SomeRegion", epiweeks="200111") self.assertEqual( response, { diff --git a/integrations/server/test_norostat.py b/integrations/server/test_norostat.py index 7adb901e7..956533c1e 100644 --- a/integrations/server/test_norostat.py +++ b/integrations/server/test_norostat.py @@ -1,13 +1,11 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class NorostatTest(BasicIntegrationTest): +class NorostatTest(DelphiTestBase): """Basic integration tests for norostat endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): create_norostat_point_diffs = """ CREATE TABLE IF NOT EXISTS `norostat_point_diffs` ( `release_date` date NOT NULL, @@ -30,7 +28,6 @@ def setUp(self) -> None: "norostat_raw_datatable_version_list", ] self.role_name = "norostat" - super().setUp() def test_norostat(self): """Basic integration test for norostat endpoint""" @@ -47,7 +44,7 @@ def test_norostat(self): 'INSERT INTO `norostat_point_diffs`(`release_date`, `parse_time`, `location_id`, `epiweek`, `new_value`) VALUES("2023-07-19", "2023-07-10 15:24:51", "1", "202329", 10)' ) self.cnx.commit() - response = self.epidata.norostat(auth="norostat_key", location="SomeTestLocation", epiweeks="202329") + response = self.epidata_client.norostat(auth="norostat_key", location="SomeTestLocation", epiweeks="202329") self.assertEqual( response, { diff --git a/integrations/server/test_nowcast.py b/integrations/server/test_nowcast.py index 51332d342..2b48dd0da 100644 --- a/integrations/server/test_nowcast.py +++ b/integrations/server/test_nowcast.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class NowcastTest(BasicIntegrationTest): +class NowcastTest(DelphiTestBase): """Basic integration tests for nowcast endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["nowcasts"] - super().setUp() def test_nowcast(self): """Basic integration test for nowcast endpoint""" @@ -18,7 +15,7 @@ def test_nowcast(self): ("201145", "nat", "12345", "0.01234"), ) self.cnx.commit() - response = self.epidata.nowcast(locations="nat", epiweeks="201145") + response = self.epidata_client.nowcast(locations="nat", epiweeks="201145") self.assertEqual( response, { diff --git a/integrations/server/test_paho_dengue.py b/integrations/server/test_paho_dengue.py index 0bb5391ed..bbe8953f8 100644 --- a/integrations/server/test_paho_dengue.py +++ b/integrations/server/test_paho_dengue.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class PahoDengueTest(BasicIntegrationTest): +class PahoDengueTest(DelphiTestBase): """Basic integration tests for paho_dengue endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["paho_dengue"] - super().setUp() def test_paho_dengue(self): """Basic integration test for paho_dengue endpoint""" @@ -18,7 +15,7 @@ def test_paho_dengue(self): ("2018-12-01", "201848", "201454", "204", "AG", "91", "DEN 1,4", "37", "40.66", "0", "0"), ) self.cnx.commit() - response = self.epidata.paho_dengue(regions="AG", epiweeks="201454") + response = self.epidata_client.paho_dengue(regions="AG", epiweeks="201454") self.assertEqual( response, { diff --git a/integrations/server/test_quidel.py b/integrations/server/test_quidel.py index 6ceefd273..696a7ee41 100644 --- a/integrations/server/test_quidel.py +++ b/integrations/server/test_quidel.py @@ -1,16 +1,13 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class QuidelTest(BasicIntegrationTest): +class QuidelTest(DelphiTestBase): """Basic integration tests for quidel endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["quidel"] self.role_name = "quidel" - super().setUp() def test_quidel(self): """Basic integration test for quidel endpoint""" @@ -19,7 +16,7 @@ def test_quidel(self): ("loc1", "201111", "1", "0", "0"), ) self.cnx.commit() - response = self.epidata.quidel(locations="loc1", epiweeks="201111", auth="quidel_key") + response = self.epidata_client.quidel(locations="loc1", epiweeks="201111", auth="quidel_key") self.assertEqual( response, {"epidata": [{"location": "loc1", "epiweek": 201111, "value": 1.0}], "result": 1, "message": "success"}, diff --git a/integrations/server/test_sensors.py b/integrations/server/test_sensors.py index d236bf7eb..835b53893 100644 --- a/integrations/server/test_sensors.py +++ b/integrations/server/test_sensors.py @@ -1,16 +1,13 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class SensorsTest(BasicIntegrationTest): +class SensorsTest(DelphiTestBase): """Basic integration tests for sensors endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["sensors"] self.role_name = "sensors" - super().setUp() def test_sensors(self): """Basic integration test for sensors endpoint""" @@ -19,7 +16,7 @@ def test_sensors(self): ("sens1", "201111", "loc1", "222"), ) self.cnx.commit() - response = self.epidata.sensors(names="sens1", locations="loc1", epiweeks="201111", auth="sensors_key") + response = self.epidata_client.sensors(names="sens1", locations="loc1", epiweeks="201111", auth="sensors_key") self.assertEqual( response, { diff --git a/integrations/server/test_signal_dashboard.py b/integrations/server/test_signal_dashboard.py index bebf6357f..e99a464fd 100644 --- a/integrations/server/test_signal_dashboard.py +++ b/integrations/server/test_signal_dashboard.py @@ -1,8 +1,8 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class SignalDashboardTest(BasicIntegrationTest): +class SignalDashboardTest(DelphiTestBase): """Basic integration tests for signal_dashboard_coverage and signal_dashboard_status endpints.""" def setUp(self) -> None: @@ -28,7 +28,7 @@ def test_signal_dashboard_coverage(self): params = { "endpoint": "signal_dashboard_coverage", } - response = self.epidata._request(params=params) + response = self.epidata_client._request(params=params) self.assertEqual( response, { @@ -44,7 +44,7 @@ def test_signal_dashboard_status(self): params = { "endpoint": "signal_dashboard_status", } - response = self.epidata._request(params=params) + response = self.epidata_client._request(params=params) self.assertEqual( response, { diff --git a/integrations/server/test_twitter.py b/integrations/server/test_twitter.py index b32ad8290..7ba162480 100644 --- a/integrations/server/test_twitter.py +++ b/integrations/server/test_twitter.py @@ -1,16 +1,13 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class TwitterTest(BasicIntegrationTest): +class TwitterTest(DelphiTestBase): """Basic integration tests for twitter endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["twitter"] self.role_name = "twitter" - super().setUp() def test_twitter(self): """Basic integration test for twitter endpoint""" @@ -19,7 +16,7 @@ def test_twitter(self): 'INSERT INTO `twitter`(`date`, `state`, `num`, `total`) VALUES ("2015-07-29", "AK", "1", "223"), ("2020-07-29", "CT", "12", "778")', ) self.cnx.commit() - response = self.epidata.twitter(auth="twitter_key", locations="cen9", dates="20150701-20160101") + response = self.epidata_client.twitter(auth="twitter_key", locations="cen9", dates="20150701-20160101") self.assertEqual( response, { diff --git a/integrations/server/test_wiki.py b/integrations/server/test_wiki.py index 982c1448b..d53cef0c9 100644 --- a/integrations/server/test_wiki.py +++ b/integrations/server/test_wiki.py @@ -1,15 +1,12 @@ # first party -from delphi.epidata.common.integration_test_base_class import BasicIntegrationTest +from delphi.epidata.common.integration_test_base_class import DelphiTestBase -class WikiTest(BasicIntegrationTest): +class WikiTest(DelphiTestBase): """Basic integration tests for wiki endpint.""" - def setUp(self) -> None: - """Perform per-test setup.""" - + def localSetUp(self): self.truncate_tables_list = ["wiki", "wiki_meta"] - super().setUp() def test_wiki(self): """Basic integration test for wiki endpoint""" @@ -21,7 +18,7 @@ def test_wiki(self): 'INSERT INTO `wiki_meta`(`datetime`, `date`, `epiweek`, `total`, `language`) VALUES ("2007-12-09 18:00:00", "2007-12-09", "200750", "969214", "en"), ("2008-12-09 18:00:00", "2008-12-09", "200750", "123321", "en")' ) self.cnx.commit() - response = self.epidata.wiki(articles="test", epiweeks="200701-200801") + response = self.epidata_client.wiki(articles="test", epiweeks="200701-200801") self.assertEqual( response, { diff --git a/src/common/integration_test_base_class.py b/src/common/integration_test_base_class.py index 580331d4a..8ccbdf3ce 100644 --- a/src/common/integration_test_base_class.py +++ b/src/common/integration_test_base_class.py @@ -9,7 +9,7 @@ from delphi.epidata.server._limiter import limiter -class BasicIntegrationTest(unittest.TestCase): +class DelphiTestBase(unittest.TestCase): """Basic integration test class""" def __init__(self, methodName: str = "runTest") -> None: @@ -18,26 +18,15 @@ def __init__(self, methodName: str = "runTest") -> None: self.truncate_tables_list = [] self.create_tables_list = [] self.role_name = None - self.epidata = Epidata - self.epidata.BASE_URL = "http://delphi_web_epidata/epidata/api.php" - self.epidata.auth = ("epidata", "key") - - def delete_from_table(self, cur, table_name: str) -> None: - cur.execute(f"DELETE FROM `{table_name}`") - - def truncate_table(self, cur, table_name: str) -> None: - cur.execute(f"TRUNCATE TABLE `{table_name}`") - - def create_table(self, cur, create_table_stmt: str): - cur.execute(create_table_stmt) + self.epidata_client = Epidata + self.epidata_client.BASE_URL = "http://delphi_web_epidata/epidata/api.php" + self.epidata_client.auth = ("epidata", "key") def create_key_with_role(self, cur, role_name: str): - cur.execute("TRUNCATE TABLE `user_role`") - cur.execute("TRUNCATE TABLE `user_role_link`") cur.execute(f'INSERT INTO `api_user`(`api_key`, `email`) VALUES("{role_name}_key", "{role_name}_email")') cur.execute(f'INSERT INTO `user_role`(`name`) VALUES("{role_name}")') cur.execute( - f'INSERT INTO `user_role_link`(`user_id`, `role_id`) SELECT `api_user`.`id`, 1 FROM `api_user` WHERE `api_key`="{role_name}_key"' + f'INSERT INTO `user_role_link`(`user_id`, `role_id`) SELECT `api_user`.`id`, `user_role`.`id` FROM `api_user` JOIN `user_role` WHERE `api_user`.`api_key`="{role_name}_key" AND `user_role`.`name`="{role_name}"' ) def setUp(self) -> None: @@ -48,16 +37,20 @@ def setUp(self) -> None: cur = cnx.cursor() cur.execute("DELETE FROM `api_user`") + cur.execute("TRUNCATE TABLE `user_role`") + cur.execute("TRUNCATE TABLE `user_role_link`") cur.execute('INSERT INTO `api_user`(`api_key`, `email`) VALUES ("key", "email")') + self.localSetUp() + for stmt in self.create_tables_list: - self.create_table(cur, stmt) + cur.execute(stmt) for table_name in self.delete_from_tables_list: - self.delete_from_table(cur, table_name) + cur.execute(f"DELETE FROM `{table_name}`") for table_name in self.truncate_tables_list: - self.truncate_table(cur, table_name) + cur.execute(f"TRUNCATE TABLE `{table_name}`") if self.role_name: self.create_key_with_role(cur, self.role_name) @@ -68,6 +61,11 @@ def setUp(self) -> None: self.cnx = cnx self.cur = cnx.cursor() + def localSetUp(self): + # stub; override in subclasses to perform custom setup. + # runs after tables have been truncated but before database changes have been committed + pass + @staticmethod def _clear_limits() -> None: limiter.storage.reset() From 5bb33b2e4e7545b631c4e76931bae02f1416df0b Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Thu, 21 Sep 2023 22:28:31 +0300 Subject: [PATCH 09/14] Moved test_meta_norostat to test_norostat.py --- integrations/server/test_norostat.py | 57 +++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/integrations/server/test_norostat.py b/integrations/server/test_norostat.py index 956533c1e..c6ccfc119 100644 --- a/integrations/server/test_norostat.py +++ b/integrations/server/test_norostat.py @@ -19,8 +19,39 @@ def localSetUp(self): CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ + create_raw_datatable_version_list = """ + CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_version_list` ( + `release_date` date NOT NULL, + `parse_time` datetime NOT NULL, + PRIMARY KEY (`release_date`,`parse_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + + create_norostat_version_list = """ + CREATE TABLE IF NOT EXISTS `norostat_point_version_list` ( + `release_date` date NOT NULL, + `parse_time` datetime NOT NULL, + PRIMARY KEY (`release_date`,`parse_time`), + CONSTRAINT `norostat_point_version_list_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_raw_datatable_version_list` (`release_date`, `parse_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + + create_norostat_datatable_location_pool = """ + CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_location_pool` ( + `location_id` int NOT NULL AUTO_INCREMENT, + `location` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + PRIMARY KEY (`location_id`), + UNIQUE KEY `location` (`location`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + """ + + self.create_tables_list = [ + create_raw_datatable_version_list, + create_norostat_version_list, + create_norostat_datatable_location_pool, + create_norostat_point_diffs, + ] - self.create_tables_list = [create_norostat_point_diffs] self.delete_from_tables_list = [ "norostat_point_diffs", "norostat_point_version_list", @@ -54,3 +85,27 @@ def test_norostat(self): }, ) return True + + def test_meta_norostat(self): + """Basic integration test for meta_norostat endpoint""" + + self.cur.execute( + "INSERT INTO `norostat_raw_datatable_version_list`(`release_date`, `parse_time`) VALUES (%s, %s)", + ("2014-10-22", "2048-12-08 15:22:51"), + ) + self.cur.execute( + 'INSERT INTO `norostat_raw_datatable_location_pool`(`location`) VALUES ("Minnesota, Ohio, Oregon, Tennessee, and Wisconsin")' + ) + self.cnx.commit() + response = self.epidata_client.meta_norostat(auth="norostat_key") + self.assertEqual( + response, + { + "epidata": { + "locations": [{"location": "Minnesota, Ohio, Oregon, Tennessee, and Wisconsin"}], + "releases": [{"release_date": "2014-10-22"}], + }, + "message": "success", + "result": 1, + }, + ) From 580a7d4aa48b7991dbbe59def51831584a901032 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 22 Sep 2023 13:28:06 +0300 Subject: [PATCH 10/14] Remove test_meta_norostat.py as this test was moved to test_norostat.py --- integrations/server/test_meta_norostat.py | 87 ----------------------- 1 file changed, 87 deletions(-) delete mode 100644 integrations/server/test_meta_norostat.py diff --git a/integrations/server/test_meta_norostat.py b/integrations/server/test_meta_norostat.py deleted file mode 100644 index e336edba3..000000000 --- a/integrations/server/test_meta_norostat.py +++ /dev/null @@ -1,87 +0,0 @@ -# first party -from delphi.epidata.common.integration_test_base_class import DelphiTestBase - - -class MetaNorostatTest(DelphiTestBase): - """Basic integration tests for meta_norostat endpint.""" - - def localSetUp(self): - create_raw_datatable_version_list = """ - CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_version_list` ( - `release_date` date NOT NULL, - `parse_time` datetime NOT NULL, - PRIMARY KEY (`release_date`,`parse_time`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; - """ - - create_norostat_version_list = """ - CREATE TABLE IF NOT EXISTS `norostat_point_version_list` ( - `release_date` date NOT NULL, - `parse_time` datetime NOT NULL, - PRIMARY KEY (`release_date`,`parse_time`), - CONSTRAINT `norostat_point_version_list_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_raw_datatable_version_list` (`release_date`, `parse_time`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; - """ - - create_norostat_datatable_location_pool = """ - CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_location_pool` ( - `location_id` int NOT NULL AUTO_INCREMENT, - `location` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, - PRIMARY KEY (`location_id`), - UNIQUE KEY `location` (`location`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; - """ - - create_norostat_point_diffs = """ - CREATE TABLE IF NOT EXISTS `norostat_point_diffs` ( - `release_date` date NOT NULL, - `parse_time` datetime NOT NULL, - `location_id` int NOT NULL, - `epiweek` int NOT NULL, - `new_value` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - PRIMARY KEY (`release_date`,`parse_time`,`location_id`,`epiweek`), - UNIQUE KEY `location_id` (`location_id`,`epiweek`,`release_date`,`parse_time`,`new_value`), - CONSTRAINT `norostat_point_diffs_ibfk_1` FOREIGN KEY (`release_date`, `parse_time`) REFERENCES `norostat_point_version_list` (`release_date`, `parse_time`), - CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; - """ - - self.create_tables_list = [ - create_raw_datatable_version_list, - create_norostat_version_list, - create_norostat_datatable_location_pool, - create_norostat_point_diffs, - ] - - self.delete_from_tables_list = [ - "norostat_point_diffs", - "norostat_point_version_list", - "norostat_raw_datatable_location_pool", - "norostat_raw_datatable_version_list", - ] - - self.role_name = "norostat" - - def test_meta_norostat(self): - """Basic integration test for meta_norostat endpoint""" - - self.cur.execute( - "INSERT INTO `norostat_raw_datatable_version_list`(`release_date`, `parse_time`) VALUES (%s, %s)", - ("2014-10-22", "2048-12-08 15:22:51"), - ) - self.cur.execute( - 'INSERT INTO `norostat_raw_datatable_location_pool`(`location`) VALUES ("Minnesota, Ohio, Oregon, Tennessee, and Wisconsin")' - ) - self.cnx.commit() - response = self.epidata_client.meta_norostat(auth="norostat_key") - self.assertEqual( - response, - { - "epidata": { - "locations": [{"location": "Minnesota, Ohio, Oregon, Tennessee, and Wisconsin"}], - "releases": [{"release_date": "2014-10-22"}], - }, - "message": "success", - "result": 1, - }, - ) From 52abbb2e736e3b243d6c71657c45b522691b7b71 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 22 Sep 2023 13:29:26 +0300 Subject: [PATCH 11/14] Update integrations/server/test_api_keys.py Co-authored-by: melange396 --- integrations/server/test_api_keys.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integrations/server/test_api_keys.py b/integrations/server/test_api_keys.py index e522fe9d7..418e265ac 100644 --- a/integrations/server/test_api_keys.py +++ b/integrations/server/test_api_keys.py @@ -146,7 +146,6 @@ def test_multiples_mixed_allowed_signal_api_key(self): status_codes.add( self._make_request(params=params, auth=self.epidata_client.auth).status_code ) - self.assertEqual(len(status_codes), 1) self.assertEqual(status_codes, {200}) def test_multiples_allowed_signal_api_key(self): From 531be621e00b9f15d4f16e9c95a4e8c5a831b1c3 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 22 Sep 2023 13:31:26 +0300 Subject: [PATCH 12/14] Update integrations/server/test_norostat.py Co-authored-by: melange396 --- integrations/server/test_norostat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integrations/server/test_norostat.py b/integrations/server/test_norostat.py index c6ccfc119..8fc3ca532 100644 --- a/integrations/server/test_norostat.py +++ b/integrations/server/test_norostat.py @@ -19,6 +19,7 @@ def localSetUp(self): CONSTRAINT `norostat_point_diffs_ibfk_2` FOREIGN KEY (`location_id`) REFERENCES `norostat_raw_datatable_location_pool` (`location_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; """ + create_raw_datatable_version_list = """ CREATE TABLE IF NOT EXISTS `norostat_raw_datatable_version_list` ( `release_date` date NOT NULL, From 5209de246f02e6d1d692945ffac8ad1fbbb77c44 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 22 Sep 2023 13:31:51 +0300 Subject: [PATCH 13/14] Update src/common/integration_test_base_class.py Co-authored-by: melange396 --- src/common/integration_test_base_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/integration_test_base_class.py b/src/common/integration_test_base_class.py index 8ccbdf3ce..387c0f617 100644 --- a/src/common/integration_test_base_class.py +++ b/src/common/integration_test_base_class.py @@ -63,7 +63,7 @@ def setUp(self) -> None: def localSetUp(self): # stub; override in subclasses to perform custom setup. - # runs after tables have been truncated but before database changes have been committed + # runs after user/api_key tables have been truncated, but before test-specific tables are created/deleted/truncated and before database changes have been committed pass @staticmethod From 6985004f4fd9b517063486b0c556ad6eb0f04fdd Mon Sep 17 00:00:00 2001 From: Dmytro Trotsko Date: Fri, 22 Sep 2023 13:32:25 +0300 Subject: [PATCH 14/14] Update integrations/server/test_norostat.py Co-authored-by: melange396 --- integrations/server/test_norostat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integrations/server/test_norostat.py b/integrations/server/test_norostat.py index 8fc3ca532..a7866a91d 100644 --- a/integrations/server/test_norostat.py +++ b/integrations/server/test_norostat.py @@ -59,6 +59,7 @@ def localSetUp(self): "norostat_raw_datatable_location_pool", "norostat_raw_datatable_version_list", ] + self.role_name = "norostat" def test_norostat(self):