|
6 | 6 | class TestNormalizeHostWithProtocol: |
7 | 7 | """Tests for normalize_host_with_protocol function.""" |
8 | 8 |
|
9 | | - @pytest.mark.parametrize("input_host,expected_output", [ |
10 | | - # Hostname without protocol - should add https:// |
11 | | - ("myserver.com", "https://myserver.com"), |
12 | | - ("workspace.databricks.com", "https://workspace.databricks.com"), |
13 | | - |
14 | | - # Hostname with https:// - should not duplicate |
15 | | - ("https://myserver.com", "https://myserver.com"), |
16 | | - ("https://workspace.databricks.com", "https://workspace.databricks.com"), |
17 | | - |
18 | | - # Hostname with http:// - should preserve |
19 | | - ("http://localhost", "http://localhost"), |
20 | | - ("http://myserver.com:8080", "http://myserver.com:8080"), |
21 | | - |
22 | | - # Hostname with port numbers |
23 | | - ("myserver.com:443", "https://myserver.com:443"), |
24 | | - ("https://myserver.com:443", "https://myserver.com:443"), |
25 | | - ("http://localhost:8080", "http://localhost:8080"), |
26 | | - |
27 | | - # Trailing slash - should be removed |
28 | | - ("myserver.com/", "https://myserver.com"), |
29 | | - ("https://myserver.com/", "https://myserver.com"), |
30 | | - ("http://localhost/", "http://localhost"), |
31 | | - |
32 | | - # Case-insensitive protocol handling - should normalize to lowercase |
33 | | - ("HTTPS://myserver.com", "https://myserver.com"), |
34 | | - ("HTTP://myserver.com", "http://myserver.com"), |
35 | | - ("HttPs://workspace.databricks.com", "https://workspace.databricks.com"), |
36 | | - ("HtTp://localhost:8080", "http://localhost:8080"), |
37 | | - ("HTTPS://MYSERVER.COM", "https://MYSERVER.COM"), # Only protocol lowercased |
38 | | - |
39 | | - # Case-insensitive with trailing slashes |
40 | | - ("HTTPS://myserver.com/", "https://myserver.com"), |
41 | | - ("HTTP://localhost:8080/", "http://localhost:8080"), |
42 | | - ("HttPs://workspace.databricks.com//", "https://workspace.databricks.com"), |
43 | | - |
44 | | - # Mixed case protocols with ports |
45 | | - ("HTTPS://myserver.com:443", "https://myserver.com:443"), |
46 | | - ("HtTp://myserver.com:8080", "http://myserver.com:8080"), |
47 | | - |
48 | | - # Case preservation - only protocol lowercased, hostname case preserved |
49 | | - ("HTTPS://MyServer.DataBricks.COM", "https://MyServer.DataBricks.COM"), |
50 | | - ("HttPs://CamelCase.Server.com", "https://CamelCase.Server.com"), |
51 | | - ("HTTP://UPPERCASE.COM:8080", "http://UPPERCASE.COM:8080"), |
52 | | - ]) |
53 | | - def test_normalize_host_with_protocol(self, input_host, expected_output): |
| 9 | + @pytest.mark.parametrize( |
| 10 | + "input_url,expected_output", |
| 11 | + [ |
| 12 | + ("myserver.com", "https://myserver.com"), # Add https:// |
| 13 | + ("https://myserver.com", "https://myserver.com"), # No duplicate |
| 14 | + ("http://localhost:8080", "http://localhost:8080"), # Preserve http:// |
| 15 | + ("myserver.com:443", "https://myserver.com:443"), # With port |
| 16 | + ("myserver.com/", "https://myserver.com"), # Remove trailing slash |
| 17 | + ("https://myserver.com///", "https://myserver.com"), # Multiple slashes |
| 18 | + ("HTTPS://MyServer.COM", "https://MyServer.COM"), # Case handling |
| 19 | + ], |
| 20 | + ) |
| 21 | + def test_normalize_host_with_protocol(self, input_url, expected_output): |
54 | 22 | """Test host normalization with various input formats.""" |
55 | | - result = normalize_host_with_protocol(input_host) |
| 23 | + result = normalize_host_with_protocol(input_url) |
56 | 24 | assert result == expected_output |
57 | | - |
58 | | - # Additional assertion: verify protocol is always lowercase |
| 25 | + |
| 26 | + # Additional assertions |
59 | 27 | assert result.startswith("https://") or result.startswith("http://") |
| 28 | + assert not result.endswith("/") |
60 | 29 |
|
61 | | - @pytest.mark.parametrize("invalid_host", [ |
62 | | - None, |
63 | | - "", |
64 | | - " ", # Whitespace only |
65 | | - ]) |
| 30 | + @pytest.mark.parametrize( |
| 31 | + "invalid_host", |
| 32 | + [ |
| 33 | + None, |
| 34 | + "", |
| 35 | + " ", # Whitespace only |
| 36 | + ], |
| 37 | + ) |
66 | 38 | def test_normalize_host_with_protocol_raises_on_invalid_input(self, invalid_host): |
67 | 39 | """Test that function raises ValueError for None or empty host.""" |
68 | 40 | with pytest.raises(ValueError, match="Host cannot be None or empty"): |
69 | 41 | normalize_host_with_protocol(invalid_host) |
70 | | - |
0 commit comments