|
| 1 | +"""Tests for the S3 client user agent. |
| 2 | +
|
| 3 | +Verifies get_client_and_resource attaches a label-studio user agent to both the |
| 4 | +client and resource while preserving signature_version and a custom endpoint_url |
| 5 | +(the path used for Amazon S3 and any S3-compatible object store such as |
| 6 | +Backblaze B2, Cloudflare R2, or MinIO). |
| 7 | +""" |
| 8 | + |
| 9 | +import unittest |
| 10 | + |
| 11 | +from io_storages.s3.utils import _get_user_agent_extra, get_client_and_resource |
| 12 | + |
| 13 | + |
| 14 | +class TestS3ClientUserAgent(unittest.TestCase): |
| 15 | + def test_user_agent_extra_format(self): |
| 16 | + ua = _get_user_agent_extra() |
| 17 | + assert ua.startswith('label-studio/') |
| 18 | + |
| 19 | + def test_client_and_resource_carry_user_agent(self): |
| 20 | + client, resource = get_client_and_resource() |
| 21 | + expected = _get_user_agent_extra() |
| 22 | + assert expected in (client.meta.config.user_agent_extra or '') |
| 23 | + assert expected in (resource.meta.client.meta.config.user_agent_extra or '') |
| 24 | + |
| 25 | + def test_signature_version_preserved(self): |
| 26 | + client, _ = get_client_and_resource() |
| 27 | + assert client.meta.config.signature_version == 's3v4' |
| 28 | + |
| 29 | + def test_custom_endpoint_preserved(self): |
| 30 | + endpoint = 'https://your-s3-endpoint.example.com' |
| 31 | + client, resource = get_client_and_resource(s3_endpoint=endpoint) |
| 32 | + assert client.meta.endpoint_url == endpoint |
| 33 | + assert resource.meta.client.meta.endpoint_url == endpoint |
| 34 | + assert _get_user_agent_extra() in (client.meta.config.user_agent_extra or '') |
0 commit comments