Skip to content

Commit 265c30c

Browse files
authored
🐛 Fix issues with parsing S3Settings (ITISFoundation#3042)
1 parent cc46b6b commit 265c30c

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

packages/settings-library/src/settings_library/r_clone.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import Enum
22

33
from pydantic import Field
4+
45
from .base import BaseCustomSettings
56
from .s3 import S3Settings
67

packages/settings-library/src/settings_library/s3.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
from typing import Optional
22

3-
from .base import BaseCustomSettings
43
from pydantic import validator
54

5+
from .base import BaseCustomSettings
6+
67

78
class S3Settings(BaseCustomSettings):
9+
S3_SECURE: bool = False
810
S3_ENDPOINT: str
911
S3_ACCESS_KEY: str
1012
S3_SECRET_KEY: str
1113
S3_ACCESS_TOKEN: Optional[str] = None
1214
S3_BUCKET_NAME: str
13-
S3_SECURE: bool = False
1415
S3_REGION: str = "us-east-1"
1516

1617
@validator("S3_ENDPOINT", pre=True)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# pylint:disable=redefined-outer-name
2+
# pylint:disable=unused-argument
3+
4+
import pytest
5+
from pytest import MonkeyPatch
6+
from settings_library.s3 import S3Settings
7+
8+
9+
@pytest.fixture
10+
def base_env(monkeypatch: MonkeyPatch) -> None:
11+
monkeypatch.setenv("S3_ACCESS_KEY", "mocked")
12+
monkeypatch.setenv("S3_SECRET_KEY", "mocked")
13+
monkeypatch.setenv("S3_BUCKET_NAME", "mocked")
14+
15+
16+
@pytest.mark.parametrize(
17+
"endpoint, secure, expected",
18+
[
19+
("osparc.io", "true", "https://osparc.io"),
20+
("osparc.io", "false", "http://osparc.io"),
21+
("https://osparc.io", "true", "https://osparc.io"),
22+
("https://osparc.io", "false", "https://osparc.io"),
23+
("http://osparc.io", "true", "http://osparc.io"),
24+
("http://osparc.io", "false", "http://osparc.io"),
25+
],
26+
)
27+
def test_regression(
28+
monkeypatch: MonkeyPatch, endpoint: str, secure: str, expected: str, base_env: None
29+
) -> None:
30+
monkeypatch.setenv("S3_ENDPOINT", endpoint)
31+
monkeypatch.setenv("S3_SECURE", secure)
32+
33+
s3_settings = S3Settings()
34+
assert s3_settings.S3_ENDPOINT == expected

0 commit comments

Comments
 (0)