|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 | from databento.common.enums import Encoding |
6 | | -from databento.common.validation import validate_enum, validate_maybe_enum |
| 6 | +from databento.common.validation import ( |
| 7 | + validate_enum, |
| 8 | + validate_gateway, |
| 9 | + validate_maybe_enum, |
| 10 | +) |
7 | 11 |
|
8 | 12 |
|
9 | 13 | class TestValidation: |
@@ -47,3 +51,28 @@ def test_validate_enum_given_valid_value_returns_expected_output( |
47 | 51 | def test_validate_maybe_enum_give_none_returns_none(self) -> None: |
48 | 52 | # Arrange, Act, Assert |
49 | 53 | assert validate_maybe_enum(None, Encoding, "encoding") is None |
| 54 | + |
| 55 | + @pytest.mark.parametrize( |
| 56 | + "url, expected", |
| 57 | + [ |
| 58 | + pytest.param("databento.com", "https://databento.com"), |
| 59 | + pytest.param("hist.databento.com", "https://hist.databento.com"), |
| 60 | + pytest.param("http://databento.com", "https://databento.com"), |
| 61 | + pytest.param("http://hist.databento.com", "https://hist.databento.com"), |
| 62 | + pytest.param("//", ValueError), |
| 63 | + pytest.param("", ValueError), |
| 64 | + ], |
| 65 | + ) |
| 66 | + def test_validate_gateway( |
| 67 | + self, |
| 68 | + url: str, |
| 69 | + expected: Union[str, Type[Exception]], |
| 70 | + ) -> None: |
| 71 | + """ |
| 72 | + Tests several correct and malformed URLs. |
| 73 | + """ |
| 74 | + if isinstance(expected, str): |
| 75 | + assert validate_gateway(url) == expected |
| 76 | + else: |
| 77 | + with pytest.raises(expected): |
| 78 | + validate_gateway(url) |
0 commit comments