|
1 | 1 | import pytest |
| 2 | +from unittest.mock import patch |
2 | 3 |
|
3 | 4 | from testcontainers.core.exceptions import ContainerStartException |
4 | 5 | from testcontainers.generic.sql import SqlContainer |
@@ -96,21 +97,20 @@ def test_connection_url_with_query_params(self): |
96 | 97 | assert "ssl=require" in url |
97 | 98 | assert "timeout=30" in url |
98 | 99 |
|
99 | | - def test_connection_url_validation_errors(self): |
| 100 | + def test_connection_url_type_errors(self): |
| 101 | + """Test that _create_connection_url raises TypeError with invalid types""" |
100 | 102 | container = SimpleSqlContainer() |
101 | | - container._container = type("MockContainer", (), {})() |
102 | | - |
103 | | - # Test missing dialect |
104 | | - with pytest.raises(ValueError, match="Database dialect is required"): |
105 | | - container._create_connection_url("", "user", "pass", port=5432) |
| 103 | + container._container = type("MockContainer", (), {"id": "test-id"})() |
106 | 104 |
|
107 | | - # Test missing username |
108 | | - with pytest.raises(ValueError, match="Database username is required"): |
109 | | - container._create_connection_url("postgresql", "", "pass", port=5432) |
| 105 | + # Mock get_exposed_port to simulate what happens with None port |
| 106 | + with patch.object(container, "get_exposed_port") as mock_get_port: |
| 107 | + # Simulate the TypeError that would occur when int(None) is called |
| 108 | + mock_get_port.side_effect = TypeError( |
| 109 | + "int() argument must be a string, a bytes-like object or a real number, not 'NoneType'" |
| 110 | + ) |
110 | 111 |
|
111 | | - # Test missing port |
112 | | - with pytest.raises(ValueError, match="Database port is required"): |
113 | | - container._create_connection_url("postgresql", "user", "pass", port=None) |
| 112 | + with pytest.raises(TypeError, match="int\\(\\) argument must be a string"): |
| 113 | + container._create_connection_url("postgresql", "user", "pass", port=None) |
114 | 114 |
|
115 | 115 | def test_connection_url_container_not_started(self): |
116 | 116 | container = SimpleSqlContainer() |
|
0 commit comments