Skip to content

Commit

Permalink
fix: Refactor fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Dec 11, 2024
1 parent 6bd8420 commit 3e2a8a8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
39 changes: 39 additions & 0 deletions tests/fixtures/household_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
import json
from unittest.mock import patch


SAMPLE_HOUSEHOLD_DATA = {
"data": {"people": {"person1": {"age": 30, "income": 50000}}},
"label": "Test Household",
}

SAMPLE_DB_ROW = {
"id": 1,
"country_id": "us",
"household_json": json.dumps(SAMPLE_HOUSEHOLD_DATA["data"]),
"household_hash": "some-hash",
"label": "Test Household",
"api_version": "3.0.0",
}


# These will be moved to the correct location once
# testing PR that creates folder structure is merged
@pytest.fixture
def mock_database():
"""Mock the database module."""
with patch(
"policyengine_api.services.household_service.database"
) as mock_db:
yield mock_db


@pytest.fixture
def mock_hash_object():
"""Mock the hash_object function."""
with patch(
"policyengine_api.services.household_service.hash_object"
) as mock:
mock.return_value = "some-hash"
yield mock
45 changes: 7 additions & 38 deletions tests/python/test_household.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
import pytest
from flask import Flask
import json
from unittest.mock import MagicMock, patch
from sqlalchemy.engine.row import LegacyRow

from policyengine_api.routes.household_routes import household_bp
from policyengine_api.services.household_service import HouseholdService
from policyengine_api.constants import COUNTRY_PACKAGE_VERSIONS

# TODO: Check if this format is correct
SAMPLE_HOUSEHOLD_DATA = {
"data": {"people": {"person1": {"age": 30, "income": 50000}}},
"label": "Test Household",
}

SAMPLE_DB_ROW = {
"id": 1,
"country_id": "us",
"household_json": json.dumps(SAMPLE_HOUSEHOLD_DATA["data"]),
"household_hash": "some-hash",
"label": "Test Household",
"api_version": "3.0.0",
}


# These will be moved to the correct location once
# testing PR that creates folder structure is merged
@pytest.fixture
def mock_database():
"""Mock the database module."""
with patch(
"policyengine_api.services.household_service.database"
) as mock_db:
yield mock_db


@pytest.fixture
def mock_hash_object():
"""Mock the hash_object function."""
with patch(
"policyengine_api.services.household_service.hash_object"
) as mock:
mock.return_value = "some-hash"
yield mock

from tests.fixtures.household_fixtures import (
SAMPLE_HOUSEHOLD_DATA,
SAMPLE_DB_ROW,
mock_database,
mock_hash_object,
)


class TestGetHousehold:
Expand Down

0 comments on commit 3e2a8a8

Please sign in to comment.