|
| 1 | +# pylint: disable=redefined-outer-name |
| 2 | +# pylint: disable=unused-argument |
| 3 | +# pylint: disable=unused-variable |
| 4 | +# pylint: disable=too-many-arguments |
| 5 | + |
| 6 | + |
| 7 | +import pytest |
| 8 | +from pydantic import ValidationError |
| 9 | +from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict |
| 10 | +from settings_library.ec2 import EC2Settings |
| 11 | + |
| 12 | + |
| 13 | +def test_ec2_endpoint_defaults_to_null(monkeypatch: pytest.MonkeyPatch): |
| 14 | + setenvs_from_dict( |
| 15 | + monkeypatch, |
| 16 | + { |
| 17 | + "EC2_ACCESS_KEY_ID": "my_access_key_id", |
| 18 | + "EC2_REGION_NAME": "us-east-1", |
| 19 | + "EC2_SECRET_ACCESS_KEY": "my_secret_access_key", |
| 20 | + }, |
| 21 | + ) |
| 22 | + |
| 23 | + settings = EC2Settings.create_from_envs() |
| 24 | + assert settings.EC2_ENDPOINT is None |
| 25 | + |
| 26 | + |
| 27 | +def test_ec2_endpoint_is_nullified(monkeypatch: pytest.MonkeyPatch): |
| 28 | + setenvs_from_dict( |
| 29 | + monkeypatch, |
| 30 | + { |
| 31 | + "EC2_ACCESS_KEY_ID": "my_access_key_id", |
| 32 | + "EC2_ENDPOINT": "null", |
| 33 | + "EC2_REGION_NAME": "us-east-1", |
| 34 | + "EC2_SECRET_ACCESS_KEY": "my_secret_access_key", |
| 35 | + }, |
| 36 | + ) |
| 37 | + |
| 38 | + settings = EC2Settings.create_from_envs() |
| 39 | + assert settings.EC2_ENDPOINT is None |
| 40 | + |
| 41 | + |
| 42 | +def test_ec2_endpoint_invalid(monkeypatch: pytest.MonkeyPatch): |
| 43 | + setenvs_from_dict( |
| 44 | + monkeypatch, |
| 45 | + { |
| 46 | + "EC2_ACCESS_KEY_ID": "my_access_key_id", |
| 47 | + "EC2_ENDPOINT": "ftp://my_ec2_endpoint.com", |
| 48 | + "EC2_REGION_NAME": "us-east-1", |
| 49 | + "EC2_SECRET_ACCESS_KEY": "my_secret_access_key", |
| 50 | + }, |
| 51 | + ) |
| 52 | + |
| 53 | + with pytest.raises(ValidationError) as err_info: |
| 54 | + EC2Settings.create_from_envs() |
| 55 | + |
| 56 | + assert err_info.value.errors() |
| 57 | + err_info.value.errors()[0]["loc"] == ("EC2_ENDPOINT") |
| 58 | + err_info.value.errors()[0]["type"] == "url_scheme" |
| 59 | + |
| 60 | + |
| 61 | +def test_ec2_endpoint_description(): |
| 62 | + assert EC2Settings.model_fields["EC2_ACCESS_KEY_ID"].description is None |
| 63 | + assert EC2Settings.model_fields["EC2_ENDPOINT"].description is not None |
0 commit comments