"""Unit tests for the snowflake connector.""" from unittest.mock import patch import pytest from charts.connectors import snowflake @pytest.fixture def mock_fetchone(): """Mock Snowflake fetchall.""" with patch( 'charts.connectors.snowflake.snowflake_conn.fetchone') \ as fetchone: fetchone.return_value = {} yield fetchone @pytest.fixture def mock_fetchall(): """Mock Snowflake fetchall.""" with patch( 'charts.connectors.snowflake.snowflake_conn.fetchall') \ as fetchall: fetchall.return_value = [] yield fetchall def test_fetchone(mock_fetchone): """Test fetchone.""" sql = 'DATA PLEASE' snowflake.fetchone(sql) mock_fetchone.assert_called_with( sql, **snowflake.DEFAULT_CONFIG ) def test_fetchone_with_config(mock_fetchone): """Test fetchone with config.""" sql = 'DATA PLEASE' params = { 'param1': 'value1' } config = { 'pool_pre_ping': True } snowflake.fetchone(sql, params, **config) mock_fetchone.assert_called_with( sql, params, **{ **config, **snowflake.DEFAULT_CONFIG } ) def test_fetchall(mock_fetchall): """Test fetchall.""" sql = 'DATA PLEASE' snowflake.fetchall(sql) mock_fetchall.assert_called_with( sql, **snowflake.DEFAULT_CONFIG ) def test_fetchall_with_config(mock_fetchall): """Test fetchall.""" sql = 'DATA PLEASE' params = { 'param1': 'value1' } config = { 'pool_pre_ping': True } snowflake.fetchall(sql, params, **config) mock_fetchall.assert_called_with( sql, params, **{ **config, **snowflake.DEFAULT_CONFIG } ) def test_fetchall_nocache(mock_fetchall): """Test fetchall_nocache.""" sql = 'DATA PLEASE' snowflake.fetchall_nocache(sql) mock_fetchall.assert_called_with( sql, **snowflake.DEFAULT_CONFIG ) def test_fetchall_nocache_with_config(mock_fetchall): """Test fetchall_nocache.""" sql = 'DATA PLEASE' params = { 'param1': 'value1' } config = { 'pool_pre_ping': True } snowflake.fetchall_nocache(sql, params, **config) mock_fetchall.assert_called_with( sql, params, **{ **config, **snowflake.DEFAULT_CONFIG } )