Skip to content

Commit d4becfa

Browse files
authored
Merge pull request #1259 from RS-PYTHON/fix/clean-flask-dependencies
Cleanup moto/flask dependencies
2 parents fa76286 + bb72c3e commit d4becfa

29 files changed

+334
-187
lines changed

poetry.lock

Lines changed: 5 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ safety = "^3.3.0"
8080
pylint = "^3.3.7"
8181
flake8-pyproject = "^1.2.3"
8282
httpx = "^0.27.2"
83-
moto = "^5.1.3"
84-
flask = "^3.0.3"
85-
flask-cors = "^5.0.1"
8683
sphinx = "^8.2.3"
8784
sphinx-rtd-theme = "^3.0.1"
8885
sqlalchemy-utils = "^0.41.2"
8986
click = "8.1.8"
87+
responses = "^0.25.7"
9088

9189
[tool.poetry.requires-plugins]
9290
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }

services/catalog/poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/catalog/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ pytest-error-for-skips = "^2.0.2"
5555
pytest-docker = "^3.1.0"
5656
pytest-dotenv = "^0.5.2"
5757
pytest-mock = "^3.14.0"
58-
moto = "^5.1.0"
59-
flask = "^3.0.3"
60-
flask-cors = "^5.0.1"
58+
moto = "^5.1.4"
59+
flask = "^3.1.1" # for moto
60+
flask-cors = "^6.0.0" # for moto
6161
sqlalchemy-utils = "^0.41.2"
6262
psycopg2 = "^2.9.9"
6363
pytest-httpx = ">=0.32,<0.35"

services/catalog/tests/test_authentication_catalog.py

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
"""Unit tests for the authentication."""
1818

1919
import json
20-
import os
2120

2221
import pytest
2322
import requests
24-
import yaml # type: ignore
2523
from moto.server import ThreadedMotoServer
2624
from pytest_httpx import HTTPXMock
2725
from rs_server_catalog.main import app, must_be_authenticated
@@ -48,7 +46,10 @@
4846
HTTP_422_UNPROCESSABLE_ENTITY,
4947
)
5048

51-
from .helpers import RESOURCES_FOLDER # pylint: disable=no-name-in-module
49+
from .helpers import ( # pylint: disable=no-name-in-module
50+
clear_aws_credentials,
51+
export_aws_credentials,
52+
)
5253

5354
logger = Logging.default(__name__)
5455

@@ -1167,36 +1168,6 @@ async def test_several_collections_fails_without_good_perms(
11671168
class TestAuthenticationDownload:
11681169
"""Contains authentication tests when a user wants to do a download."""
11691170

1170-
def export_aws_credentials(self):
1171-
"""Export AWS credentials as environment variables for testing purposes.
1172-
1173-
This function sets the following environment variables with dummy values for AWS credentials:
1174-
- AWS_ACCESS_KEY_ID
1175-
- AWS_SECRET_ACCESS_KEY
1176-
- AWS_SECURITY_TOKEN
1177-
- AWS_SESSION_TOKEN
1178-
- AWS_DEFAULT_REGION
1179-
1180-
Note: This function is intended for testing purposes only, and it should not be used in production.
1181-
1182-
Returns:
1183-
None
1184-
1185-
Raises:
1186-
None
1187-
"""
1188-
with open(RESOURCES_FOLDER / "s3" / "s3.yml", encoding="utf-8") as f:
1189-
s3_config = yaml.safe_load(f)
1190-
os.environ.update(s3_config["s3"])
1191-
os.environ.update(s3_config["boto"])
1192-
1193-
def clear_aws_credentials(self):
1194-
"""Clear AWS credentials from environment variables."""
1195-
with open(RESOURCES_FOLDER / "s3" / "s3.yml", encoding="utf-8") as f:
1196-
s3_config = yaml.safe_load(f)
1197-
for env_var in list(s3_config["s3"].keys()) + list(s3_config["boto"].keys()):
1198-
del os.environ[env_var]
1199-
12001171
@pytest.mark.parametrize("test_apikey, test_oauth2", [[True, False], [False, True]], ids=["apikey", "oauth2"])
12011172
async def test_http200_with_good_authentication(
12021173
self,
@@ -1218,7 +1189,7 @@ async def test_http200_with_good_authentication(
12181189

12191190
# Start moto server
12201191
moto_endpoint = "http://localhost:8077"
1221-
self.export_aws_credentials()
1192+
export_aws_credentials()
12221193
secrets = {"s3endpoint": moto_endpoint, "accesskey": None, "secretkey": None, "region": ""}
12231194
s3_handler = S3StorageHandler(
12241195
secrets["accesskey"],
@@ -1277,7 +1248,7 @@ async def test_http200_with_good_authentication(
12771248
finally:
12781249
server.stop()
12791250
# Remove bucket credentials form env variables / should create a s3_handler without credentials error
1280-
self.clear_aws_credentials()
1251+
clear_aws_credentials()
12811252

12821253
response = client.get(
12831254
"/catalog/collections/toto:S1_L1/items/fe916452-ba6f-4631-9154-c249924a122d/download/"
@@ -1300,14 +1271,8 @@ async def test_fails_without_good_perms(self, mocker, httpx_mock: HTTPXMock, cli
13001271

13011272
# Start moto server
13021273
moto_endpoint = "http://localhost:8077"
1303-
self.export_aws_credentials()
1304-
secrets = {"s3endpoint": moto_endpoint, "accesskey": None, "secretkey": None, "region": ""}
1305-
s3_handler = S3StorageHandler(
1306-
secrets["accesskey"],
1307-
secrets["secretkey"],
1308-
secrets["s3endpoint"],
1309-
secrets["region"],
1310-
)
1274+
export_aws_credentials()
1275+
s3_handler = S3StorageHandler(None, None, moto_endpoint, "")
13111276
server = ThreadedMotoServer(port=8077)
13121277
server.start()
13131278

@@ -1334,7 +1299,7 @@ async def test_fails_without_good_perms(self, mocker, httpx_mock: HTTPXMock, cli
13341299
finally:
13351300
server.stop()
13361301
# Remove bucket credentials form env variables / should create a s3_handler without credentials error
1337-
self.clear_aws_credentials()
1302+
clear_aws_credentials()
13381303

13391304

13401305
class TestAuthenticationDelete:

services/catalog/tests/test_endpoints/test_catalog_publish_feature_with_bucket_transfer_endpoint.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,7 @@ def test_custom_bucket_publish(self, client, a_correct_feature):
491491
"""Test with other temp bucket name."""
492492
moto_endpoint = "http://localhost:8077"
493493
export_aws_credentials()
494-
secrets = {"s3endpoint": moto_endpoint, "accesskey": None, "secretkey": None, "region": ""}
495-
s3_handler = S3StorageHandler(
496-
secrets["accesskey"],
497-
secrets["secretkey"],
498-
secrets["s3endpoint"],
499-
secrets["region"],
500-
)
494+
s3_handler = S3StorageHandler(None, None, moto_endpoint, "")
501495
os.environ["RSPY_LOCAL_CATALOG_MODE"] = "0"
502496
server = ThreadedMotoServer(port=8077)
503497
server.start()

0 commit comments

Comments
 (0)