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

Merged
merged 2 commits into from
Feb 10, 2025
Merged
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
Next Next commit
first tests for data/
BielStela committed Nov 14, 2023
commit 6e8ffbfb9508e1e41aa45ee8e1b62cb8fcca7084
Empty file.
59 changes: 59 additions & 0 deletions data/h3_data_importer/tests/test_h3_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
from pathlib import Path

import pytest
import psycopg
from dotenv import load_dotenv


from ..utils import get_connection_info


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


@pytest.fixture(autouse=True)
def test_env_variables():
print(f"Using DB {os.getenv('API_POSTGRES_DATABASE')} on {os.getenv('API_POSTGRES_HOST')}")
if os.getenv("API_POSTGRES_DATABASE") is None:
pytest.fail("API_POSTGRES_DATABASE is not set -> .env not found")


def test_db_connection():
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"
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
"""
)
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'
"""
)
result = cur.fetchall()
assert len(result) > 0, "The query result is empty"