|
12 | 12 | from databricks.sql.exc import RequestError |
13 | 13 | from databricks.sql.auth.common import ClientContext |
14 | 14 | from databricks.sql.types import SSLOptions |
| 15 | +from databricks.sql.auth.retry import CommandType |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class TestUnifiedHttpClientMaxRetryError: |
@@ -134,3 +135,66 @@ def test_generic_exception_no_crash(self, http_client): |
134 | 135 |
|
135 | 136 | error = exc_info.value |
136 | 137 | assert "HTTP request error" in str(error) |
| 138 | + |
| 139 | + |
| 140 | +class TestUnifiedHttpClientFeatureFlagsDetection: |
| 141 | + """Test feature flags URL detection and CommandType setting.""" |
| 142 | + |
| 143 | + @pytest.fixture |
| 144 | + def client_context(self): |
| 145 | + """Create a minimal ClientContext for testing.""" |
| 146 | + context = Mock(spec=ClientContext) |
| 147 | + context.hostname = "https://test.databricks.com" |
| 148 | + context.ssl_options = SSLOptions( |
| 149 | + tls_verify=True, |
| 150 | + tls_verify_hostname=True, |
| 151 | + tls_trusted_ca_file=None, |
| 152 | + tls_client_cert_file=None, |
| 153 | + tls_client_cert_key_file=None, |
| 154 | + tls_client_cert_key_password=None, |
| 155 | + ) |
| 156 | + context.socket_timeout = 30 |
| 157 | + context.retry_stop_after_attempts_count = 3 |
| 158 | + context.retry_delay_min = 1.0 |
| 159 | + context.retry_delay_max = 10.0 |
| 160 | + context.retry_stop_after_attempts_duration = 300.0 |
| 161 | + context.retry_delay_default = 5.0 |
| 162 | + context.retry_dangerous_codes = [] |
| 163 | + context.proxy_auth_method = None |
| 164 | + context.pool_connections = 10 |
| 165 | + context.pool_maxsize = 20 |
| 166 | + context.user_agent = "test-agent" |
| 167 | + return context |
| 168 | + |
| 169 | + @pytest.fixture |
| 170 | + def http_client(self, client_context): |
| 171 | + """Create UnifiedHttpClient instance.""" |
| 172 | + return UnifiedHttpClient(client_context) |
| 173 | + |
| 174 | + def test_feature_flags_url_sets_feature_flags_command_type(self, http_client): |
| 175 | + """Test that feature flags URL sets CommandType.FEATURE_FLAGS""" |
| 176 | + feature_flags_url = "https://test.databricks.com/connector-service/feature-flags/v1" |
| 177 | + |
| 178 | + # Call _prepare_retry_policy with feature flags URL |
| 179 | + http_client._prepare_retry_policy(feature_flags_url) |
| 180 | + |
| 181 | + # Verify CommandType is set to FEATURE_FLAGS |
| 182 | + assert http_client._retry_policy.command_type == CommandType.FEATURE_FLAGS |
| 183 | + |
| 184 | + def test_non_feature_flags_url_sets_other_command_type(self, http_client): |
| 185 | + """Test that non-feature-flags URLs set CommandType.OTHER""" |
| 186 | + normal_url = "https://test.databricks.com/api/2.0/sql/statements" |
| 187 | + |
| 188 | + # Call _prepare_retry_policy with normal URL |
| 189 | + http_client._prepare_retry_policy(normal_url) |
| 190 | + |
| 191 | + # Verify CommandType is set to OTHER |
| 192 | + assert http_client._retry_policy.command_type == CommandType.OTHER |
| 193 | + |
| 194 | + def test_empty_url_sets_other_command_type(self, http_client): |
| 195 | + """Test that empty URL defaults to CommandType.OTHER""" |
| 196 | + # Call _prepare_retry_policy with empty URL |
| 197 | + http_client._prepare_retry_policy("") |
| 198 | + |
| 199 | + # Verify CommandType is set to OTHER |
| 200 | + assert http_client._retry_policy.command_type == CommandType.OTHER |
0 commit comments