Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data testing #1092

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Share connection as fixture
  • Loading branch information
BielStela committed Nov 23, 2023
commit 8c8cd8ee057189139a0c2cbbf804b17d7c1f9dff
58 changes: 31 additions & 27 deletions data/h3_data_importer/tests/test_h3_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@pytest.fixture(scope="session", autouse=True)
def load_env():
project_root = Path(__file__).resolve().parents[4]
project_root = Path(__file__).resolve().parents[3]
load_dotenv(project_root / ".env")


Expand All @@ -22,38 +22,42 @@ def test_env_variables():
pytest.fail("API_POSTGRES_DATABASE is not set -> .env not found")


def test_db_connection():
@pytest.fixture()
def conn():
conn = psycopg.connect(conninfo=get_connection_info())
yield conn
conn.close()


def test_db_connection(conn):
try:
with psycopg.connect(conninfo=get_connection_info()) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
result = cur.fetchone()
assert result[0] == 1, "The query result is not 1"
with conn.cursor() as cur:
cur.execute("SELECT 1")
result = cur.fetchone()
assert result[0] == 1, "The query result is not 1"
except Exception as e:
pytest.fail(f"DB connection Error: {e}")


def test_indicator_coefficient_has_any_link_to_material():
with psycopg.connect(conninfo=get_connection_info()) as conn:
with conn.cursor() as cur:
cur.execute(
"""
select "materialId" from indicator_coefficient
def test_indicator_coefficient_has_any_link_to_material(conn):
with conn.cursor() as cur:
cur.execute(
"""
)
result = cur.fetchall()
assert len(result) > 0, "The query result is empty"
select "materialId" from indicator_coefficient
"""
)
result = cur.fetchall()
assert len(result) > 0, "The query result is empty"


def test_material_is_linked_in_indicator_coefficients():
with psycopg.connect(conninfo=get_connection_info()) as conn:
with conn.cursor() as cur:
cur.execute(
"""
select ic.id from indicator_coefficient ic
join material on "materialId" = material.id
where material."hsCodeId" = '0407'
def test_material_is_linked_in_indicator_coefficients(conn):
with conn.cursor() as cur:
cur.execute(
"""
)
result = cur.fetchall()
assert len(result) > 0, "The query result is empty"
select ic.id from indicator_coefficient ic
join material on "materialId" = material.id
where material."hsCodeId" = '0407'
"""
)
result = cur.fetchall()
assert len(result) > 0, "The query result is empty"