From fd39b8ce0ad86c85636a09ca3ac15975fabf776a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 25 Mar 2022 16:13:00 +0300 Subject: Create a fixture for pcorrs data --- tests/integration/conftest.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/integration/conftest.py') diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 4274233..90cf985 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -78,3 +78,27 @@ def db_conn(): # # b.) Delete the test database db_cursor.execute(f"DROP DATABASE IF EXISTS {test_db_name}") + +@pytest.fixture(scope="function") +def db_conn_with_pcorrs_data(db_conn): + """Fixture with data for partial correlations tests""" + with open( + "tests/integration/test_data/pcorrs_data.json", + encoding="utf8") as data_file: + data = json.loads(data_file.read()) + with db_conn.cursor() as cursor: + for item in data: + row_keys = item["rows"][0].keys() + query = ( + f"INSERT INTO {item['dbtable']}({', '.join(row_keys)}) " + f"VALUES ({', '.join(['%s' for key in row_keys])})") + cursor.executemany( + query, + tuple( + tuple(row[key] for key in row_keys) + for row in item["rows"])) + + yield db_conn + + for item in data: + cursor.execute(f"DELETE FROM {item['dbtable']}") -- cgit v1.2.3