"""Unit tests for the market ranks logic layer.""" from unittest.mock import patch import pytest from analytics.api import app from analytics.connectors import redis from analytics.logic import market_ranks @pytest.fixture(autouse=True) def mock_context(): """Mock context.""" with app.test_request_context(): yield {} def test_empty_db_result( mock_context, ): redis.client.flushall() # flush Fakeredis cache with patch( "analytics.logic.market_ranks.MarketRanks.execute", return_value=[], ): result = market_ranks.get_market_ranks({}, {}) assert result.message == {"items": []} MOCK_SNOWFLAKE_ROWS = [ { "store_id": 1, "country_code": "GLOBAL", "market_rank": 1, } ] def test_get_mocked_db_result( mock_context, ): redis.client.flushall() # flush Fakeredis cache with patch( "analytics.logic.market_ranks.MarketRanks.execute", return_value=MOCK_SNOWFLAKE_ROWS, ): result = market_ranks.get_market_ranks({}, {}) assert result.message == { "items": [ { "store_id": 1, "country_code": "GLOBAL", "market_rank": 1, } ] }