|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client.http.client_utils import validate_base_url |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize( |
| 7 | + ("input_url", "expected"), |
| 8 | + [ |
| 9 | + ("//[2001:db8:85a3::8a2e:370:7334]:80/a", "https://[2001:db8:85a3::8a2e:370:7334]:80/a"), |
| 10 | + ("//example.com", "https://example.com"), |
| 11 | + ("http://example.com", "http://example.com"), |
| 12 | + ("http://example.com:88/something/else", "http://example.com:88/something/else"), |
| 13 | + ("http://user@example.com:88/", "http://example.com:88"), |
| 14 | + ("http://user:pass@example.com:88/", "http://example.com:88"), |
| 15 | + ("http://example.com/public", "http://example.com"), |
| 16 | + ("http://example.com/public/", "http://example.com"), |
| 17 | + ("http://example.com/public/else", "http://example.com/public/else"), |
| 18 | + ("http://example.com/public/v1", "http://example.com"), |
| 19 | + ("http://example.com/public/v1/", "http://example.com"), |
| 20 | + ("http://example.com/else/public", "http://example.com/else/public"), |
| 21 | + ("http://example.com/elsepublic", "http://example.com/elsepublic"), |
| 22 | + ], |
| 23 | +) |
| 24 | +def test_protocol_and_host(input_url, expected): |
| 25 | + result = validate_base_url(input_url) |
| 26 | + |
| 27 | + assert result == expected |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.parametrize( |
| 31 | + "input_url", |
| 32 | + [ |
| 33 | + "", |
| 34 | + "http//example.com", |
| 35 | + "://example.com", |
| 36 | + "http:example.com", |
| 37 | + "http:/example.com", |
| 38 | + ], |
| 39 | +) |
| 40 | +def test_protocol_and_host_error(input_url): |
| 41 | + with pytest.raises(ValueError): |
| 42 | + validate_base_url(input_url) |
0 commit comments