diff --git a/poetry.lock b/poetry.lock index 34270f1..7d65701 100644 --- a/poetry.lock +++ b/poetry.lock @@ -943,43 +943,6 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] -[[package]] -name = "pytest-aiohttp" -version = "1.0.5" -description = "Pytest plugin for aiohttp support" -optional = false -python-versions = ">=3.7" -files = [ - {file = "pytest-aiohttp-1.0.5.tar.gz", hash = "sha256:880262bc5951e934463b15e3af8bb298f11f7d4d3ebac970aab425aff10a780a"}, - {file = "pytest_aiohttp-1.0.5-py3-none-any.whl", hash = "sha256:63a5360fd2f34dda4ab8e6baee4c5f5be4cd186a403cabd498fced82ac9c561e"}, -] - -[package.dependencies] -aiohttp = ">=3.8.1" -pytest = ">=6.1.0" -pytest-asyncio = ">=0.17.2" - -[package.extras] -testing = ["coverage (==6.2)", "mypy (==0.931)"] - -[[package]] -name = "pytest-asyncio" -version = "0.23.6" -description = "Pytest support for asyncio" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pytest-asyncio-0.23.6.tar.gz", hash = "sha256:ffe523a89c1c222598c76856e76852b787504ddb72dd5d9b6617ffa8aa2cde5f"}, - {file = "pytest_asyncio-0.23.6-py3-none-any.whl", hash = "sha256:68516fdd1018ac57b846c9846b954f0393b26f094764a28c955eabb0536a4e8a"}, -] - -[package.dependencies] -pytest = ">=7.0.0,<9" - -[package.extras] -docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] -testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] - [[package]] name = "pytest-cov" version = "4.1.0" @@ -1047,6 +1010,22 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "setuptools" +version = "69.5.1" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "setuptools-69.5.1-py3-none-any.whl", hash = "sha256:c636ac361bc47580504644275c9ad802c50415c7522212252c033bd15f301f32"}, + {file = "setuptools-69.5.1.tar.gz", hash = "sha256:6c1fccdac05a97e598fb0ae3bbed5904ccb317337a51139dcd51453611bbb987"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mypy (==1.9)", "packaging (>=23.2)", "pip (>=19.1)", "pytest (>=6,!=8.1.1)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + [[package]] name = "six" version = "1.16.0" @@ -1272,4 +1251,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "098b997ed49ae22c646eceef1190bfd379f2d0b453ee279abe6568a1b5957ed4" +content-hash = "762abed752fb5577fa4828ad780d3062263f1ec7dbc12d82687a7a4d834fdcaf" diff --git a/pyproject.toml b/pyproject.toml index df692c6..e8bb250 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,12 +52,12 @@ coverage = "!=4.3" coveralls = "^3.3.1" mypy = "*" pylama = { extras = ["toml"], version = "^8.4.1" } -pytest = "^7.2.1" pytest-cov = "^4.0.0" pytest-timeout = "^2.1.0" tox = "^4.4.6" -pytest-aiohttp = "^1.0.4" freezegun = "^1.5.0" +pytest = "^7.4.4" +setuptools = "^69.5.1" [build-system] requires = ["poetry-core"] diff --git a/tests/test_simple.py b/tests/test_simple.py deleted file mode 100644 index 531af4b..0000000 --- a/tests/test_simple.py +++ /dev/null @@ -1,203 +0,0 @@ -import gzip -import sys -from http import HTTPStatus -from io import BytesIO -from pathlib import Path - -import pytest -from freezegun import freeze_time -from yarl import URL - -from aiohttp_s3_client import S3Client - - -@pytest.mark.parametrize("object_name", ("test/test", "/test/test")) -async def test_put_str(s3_client: S3Client, object_name): - data = "hello, world" - resp = await s3_client.put(object_name, data) - assert resp.status == HTTPStatus.OK - - resp = await s3_client.get(object_name) - result = await resp.text() - assert result == data - - -@pytest.mark.parametrize("object_name", ("test/test", "/test/test")) -async def test_put_bytes(s3_client: S3Client, s3_read, object_name): - data = b"hello, world" - resp = await s3_client.put(object_name, data) - assert resp.status == HTTPStatus.OK - assert (await s3_read()) == data - - -@pytest.mark.parametrize("object_name", ("test/test", "/test/test")) -async def test_put_async_iterable(s3_client: S3Client, s3_read, object_name): - async def async_iterable(iterable: bytes): - for i in iterable: - yield i.to_bytes(1, sys.byteorder) - - data = b"hello, world" - resp = await s3_client.put(object_name, async_iterable(data)) - assert resp.status == HTTPStatus.OK - - assert (await s3_read()) == data - - -async def test_put_file(s3_client: S3Client, s3_read, tmp_path): - data = b"hello, world" - - with (tmp_path / "hello.txt").open("wb") as f: - f.write(data) - f.flush() - - # Test upload by file str path - resp = await s3_client.put_file("/test/test", f.name) - assert resp.status == HTTPStatus.OK - - assert (await s3_read("/test/test")) == data - - # Test upload by file Path - resp = await s3_client.put_file("/test/test2", Path(f.name)) - assert resp.status == HTTPStatus.OK - - assert (await s3_read("/test/test2")) == data - - -async def test_list_objects_v2(s3_client: S3Client, s3_read, tmp_path): - data = b"hello, world" - - with (tmp_path / "hello.txt").open("wb") as f: - f.write(data) - f.flush() - - resp = await s3_client.put_file("/test/list/test1", f.name) - assert resp.status == HTTPStatus.OK - - resp = await s3_client.put_file("/test/list/test2", f.name) - assert resp.status == HTTPStatus.OK - - # Test list file - batch = 0 - async for result, prefixes in s3_client.list_objects_v2( - prefix="test/list/", - delimiter="/", - max_keys=1, - ): - batch += 1 - assert result[0].key == f"test/list/test{batch}" - assert result[0].size == len(data) - - -async def test_list_objects_v2_prefix(s3_client: S3Client, s3_read, tmp_path): - data = b"hello, world" - - with (tmp_path / "hello.txt").open("wb") as f: - f.write(data) - f.flush() - - resp = await s3_client.put_file("/test2/list1/test1", f.name) - assert resp.status == HTTPStatus.OK - - resp = await s3_client.put_file("/test2/list2/test2", f.name) - assert resp.status == HTTPStatus.OK - - # Test list file - batch = 0 - - async for result, prefixes in s3_client.list_objects_v2( - prefix="test2/", - delimiter="/", - ): - batch += 1 - assert len(result) == 0 - assert prefixes[0] == "test2/list1/" - assert prefixes[1] == "test2/list2/" - - -async def test_url_path_with_colon(s3_client: S3Client, s3_read): - data = b"hello, world" - key = "/some-path:with-colon.txt" - resp = await s3_client.put(key, data) - assert resp.status == HTTPStatus.OK - - assert (await s3_read(key)) == data - - -@pytest.mark.parametrize("object_name", ("test/test", "/test/test")) -async def test_put_compression(s3_client: S3Client, s3_read, object_name): - async def async_iterable(iterable: bytes): - for i in iterable: - yield i.to_bytes(1, sys.byteorder) - - data = b"hello, world" - resp = await s3_client.put( - object_name, async_iterable(data), compress="gzip", - ) - assert resp.status == HTTPStatus.OK - - result = await s3_read() - # assert resp.headers[hdrs.CONTENT_ENCODING] == "gzip" - # FIXME: uncomment after update fakes3 image - actual = gzip.GzipFile(fileobj=BytesIO(result)).read() - assert actual == data - - -@pytest.mark.parametrize('method,given_url', [ - # Simple test - ('GET', 'test/object'), - - # Check method name is ok in lowercase - ('get', 'test/object'), - - # Absolute path - ('GET', '/test/object'), - - # Check URL object with path is given - ('get', URL('./test/object')), - - # Check URL object with path is given - ('get', URL('/test/object')), -]) -def test_presign_non_absolute_url(s3_client, s3_url, method, given_url): - presigned = s3_client.presign_url('get', 'test/object') - assert presigned.is_absolute() - assert presigned.scheme == s3_url.scheme - assert presigned.host == s3_url.host - assert presigned.port == s3_url.port - assert presigned.path.startswith(s3_url.path) - assert presigned.path.endswith(str(given_url).lstrip('.')) - - -@pytest.mark.parametrize('method,given_url', [ - # String url - ('GET', 'https://absolute-url:123/path'), - - # URL object - ('GET', URL('https://absolute-url:123/path')), -]) -def test_presign_absolute_url(s3_client, method, given_url): - presigned = s3_client.presign_url(method, given_url) - assert presigned.is_absolute() - - url_object = URL(given_url) - assert presigned.scheme == url_object.scheme - assert presigned.host == url_object.host - assert presigned.port == url_object.port - assert presigned.path == url_object.path - - -@freeze_time("2024-01-01") -def test_presign_url(s3_client): - url = s3_client.presign_url('get', URL('./example'), expires=60 * 60) - assert url.path.endswith('/example') - assert url.query == { - 'X-Amz-Algorithm': 'AWS4-HMAC-SHA256', - 'X-Amz-Content-Sha256': 'UNSIGNED-PAYLOAD', - 'X-Amz-Credential': 'user/20240101/us-east-1/s3/aws4_request', - 'X-Amz-Date': '20240101T000000Z', - 'X-Amz-Expires': '3600', - 'X-Amz-SignedHeaders': 'host', - 'X-Amz-Signature': ( - 'aab128060bd714e4119179d99188716c491394a4bc0dc87f6603bc1312b5c40f' - ) - }