🎥 Make videos programmatically with React
Add test s3 client config
Vlad Mf56f5e362a40
diff --git a/packages/lambda-python/remotion_lambda/remotionclient.py b/packages/lambda-python/remotion_lambda/remotionclient.pyindex a4c89e8b29..6721ec66c2 100644--- a/packages/lambda-python/remotion_lambda/remotionclient.py+++ b/packages/lambda-python/remotion_lambda/remotionclient.py@@ -79,19 +79,20 @@ class RemotionClient:def _create_s3_client(self):"""Create S3 client with appropriate credentials."""- config = None+ kwargs = {'region_name': self.region}+if self.force_path_style:- config = Config(s3={'addressing_style': 'path'})+ kwargs['config'] = Config(s3={'addressing_style': 'path'})if self.access_key and self.secret_key:- return boto3.client(- 's3',- aws_access_key_id=self.access_key,- aws_secret_access_key=self.secret_key,- region_name=self.region,- config=config,+ kwargs.update(+ {+ 'aws_access_key_id': self.access_key,+ 'aws_secret_access_key': self.secret_key,+ })- return boto3.client('s3', region_name=self.region, config=config)++ return boto3.client('s3', **kwargs)def _get_remotion_buckets(self):"""Get existing Remotion buckets in the region."""diff --git a/packages/lambda-python/tests/conftest.py b/packages/lambda-python/tests/conftest.pyindex 4d7bd344a8..d5cbf45452 100644--- a/packages/lambda-python/tests/conftest.py+++ b/packages/lambda-python/tests/conftest.py@@ -1,6 +1,13 @@import pytestfrom remotion_lambda.remotionclient import RemotionClient-from tests.constants import TEST_FUNCTION_NAME, TEST_REGION, TEST_SERVE_URL+from tests.constants import (+ TEST_FUNCTION_NAME,+ TEST_REGION,+ TEST_SERVE_URL,+ TEST_AWS_ACCESS_KEY,+ TEST_AWS_SECRET_KEY,+)+from unittest.mock import Mock@pytest.fixture@@ -8,3 +15,19 @@ def remotion_client():return RemotionClient(region=TEST_REGION, serve_url=TEST_SERVE_URL, function_name=TEST_FUNCTION_NAME)+++def remotion_client_with_creds():+ return RemotionClient(+ region=TEST_REGION,+ serve_url=TEST_SERVE_URL,+ function_name=TEST_FUNCTION_NAME,+ access_key=TEST_AWS_ACCESS_KEY,+ secret_key=TEST_AWS_SECRET_KEY,+ )+++def mock_s3_client():+ return Mock()diff --git a/packages/lambda-python/tests/constants.py b/packages/lambda-python/tests/constants.pyindex 2cae16847d..403a812023 100644--- a/packages/lambda-python/tests/constants.py+++ b/packages/lambda-python/tests/constants.py@@ -1,3 +1,5 @@TEST_REGION = "us-east-1"TEST_SERVE_URL = "https://example.com"TEST_FUNCTION_NAME = "remotion-render"+TEST_AWS_SECRET_KEY = "test-secret-key"+TEST_AWS_ACCESS_KEY = "test-access-key"diff --git a/packages/lambda-python/tests/test_remotion_client.py b/packages/lambda-python/tests/test_remotion_client.pyindex 9e677b17fb..676b60f869 100644--- a/packages/lambda-python/tests/test_remotion_client.py+++ b/packages/lambda-python/tests/test_remotion_client.py@@ -1,7 +1,15 @@-from tests.conftest import remotion_client+from tests.conftest import remotion_client, mock_s3_client, remotion_client_with_credsfrom remotion_lambda.remotionclient import RemotionClientimport pytest-from tests.constants import TEST_FUNCTION_NAME, TEST_REGION, TEST_SERVE_URL+from tests.constants import (+ TEST_FUNCTION_NAME,+ TEST_REGION,+ TEST_SERVE_URL,+ TEST_AWS_SECRET_KEY,+ TEST_AWS_ACCESS_KEY,+)+from unittest.mock import patch, Mock+from botocore.config import Configdef test_bucket_name_format(remotion_client: RemotionClient):@@ -39,3 +47,67 @@ def test_generate_hash_basic_string(remotion_client: RemotionClient):assert len(result) == 64assert all(c in '0123456789abcdef' for c in result)+++@patch('boto3.client')+def test_create_s3_client_default(+ mock_boto_client, mock_s3_client, remotion_client: RemotionClient+):+ mock_boto_client.return_value = mock_s3_client+ result = remotion_client._create_s3_client()++ mock_boto_client.assert_called_once_with('s3', region_name=TEST_REGION)+ assert result == mock_s3_client+++@patch('boto3.client')+def test_create_s3_client_partial_creds(mock_boto_client, mock_s3_client):+ remotion_client = RemotionClient(+ region=TEST_REGION,+ serve_url=TEST_SERVE_URL,+ function_name=TEST_FUNCTION_NAME,+ secret_key=TEST_AWS_SECRET_KEY,+ )++ mock_boto_client.return_value = mock_s3_client+ result = remotion_client._create_s3_client()++ mock_boto_client.assert_called_once_with('s3', region_name=TEST_REGION)+ assert result == mock_s3_client+++@patch('boto3.client')+def test_create_s3_client_creds(+ mock_boto_client, mock_s3_client, remotion_client_with_creds+):+ mock_boto_client.return_value = mock_s3_client+ result = remotion_client_with_creds._create_s3_client()++ mock_boto_client.assert_called_once_with(+ 's3',+ region_name=TEST_REGION,+ aws_access_key_id=TEST_AWS_ACCESS_KEY,+ aws_secret_access_key=TEST_AWS_SECRET_KEY,+ )+ assert result == mock_s3_client+++@patch('boto3.client')+def test_create_s3_client_with_path_style(mock_boto_client, mock_s3_client):+ remotion_client = RemotionClient(+ region=TEST_REGION,+ serve_url=TEST_SERVE_URL,+ function_name=TEST_FUNCTION_NAME,+ force_path_style=True,+ )+ mock_boto_client.return_value = mock_s3_client+ result = remotion_client._create_s3_client()++ mock_boto_client.assert_called_once()++ call_args = mock_boto_client.call_args+ assert 'config' in call_args[1]+ config = call_args[1]['config']+ assert isinstance(config, Config)+ assert config.s3['addressing_style'] == 'path'+ assert result == mock_s3_client