Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #782

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
rev: v0.6.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
from pathlib import Path

import pytest

from platform_storage_api.fs.local import FileSystem, LocalFileSystem


@pytest.fixture()
@pytest.fixture
async def local_fs() -> AsyncIterator[FileSystem]:
async with LocalFileSystem() as fs:
yield fs


@pytest.fixture()
@pytest.fixture
def local_tmp_dir_path() -> Iterator[Path]:
with tempfile.TemporaryDirectory() as d:
yield Path(os.path.realpath(d))
23 changes: 12 additions & 11 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import pytest_asyncio
import uvicorn
from neuro_admin_client import AdminClient
from yarl import URL

from platform_storage_api.api import create_app
from platform_storage_api.config import (
AWSConfig,
Expand All @@ -27,7 +29,6 @@
from platform_storage_api.s3_storage import StorageMetricsAsyncS3Storage
from platform_storage_api.storage import SingleStoragePathResolver
from platform_storage_api.storage_usage import StorageUsageService
from yarl import URL


pytest_plugins = [
Expand Down Expand Up @@ -67,17 +68,17 @@ def ping_url(self) -> str:
return self.endpoint + "/ping"


@pytest.fixture()
@pytest.fixture
def server_url(api: ApiConfig) -> str:
return api.storage_base_url


@pytest.fixture()
@pytest.fixture
def multi_storage_server_url(multi_storage_api: ApiConfig) -> str:
return multi_storage_api.storage_base_url


@pytest.fixture()
@pytest.fixture
def platform_config(
auth_server: URL, admin_token: str, cluster_name: str
) -> PlatformConfig:
Expand All @@ -89,7 +90,7 @@ def platform_config(
)


@pytest.fixture()
@pytest.fixture
def config(
platform_config: PlatformConfig, aws_config: AWSConfig, local_tmp_dir_path: Path
) -> Config:
Expand All @@ -103,12 +104,12 @@ def config(
)


@pytest.fixture()
@pytest.fixture
def metrics_config(aws_config: AWSConfig) -> MetricsConfig:
return MetricsConfig(aws=aws_config)


@pytest.fixture()
@pytest.fixture
def multi_storage_config(config: Config) -> Config:
config = replace(config, storage=replace(config.storage, mode=StorageMode.MULTIPLE))
Path(config.storage.fs_local_base_path, config.platform.cluster_name).mkdir(
Expand Down Expand Up @@ -147,7 +148,7 @@ async def client() -> AsyncIterator[aiohttp.ClientSession]:
yield session


@pytest.fixture()
@pytest.fixture
def cluster_name() -> str:
return "test-cluster"

Expand All @@ -166,15 +167,15 @@ def get_filestatus_dict(response_json: dict[str, Any]) -> dict[str, Any]:
return response_json["FileStatus"]


@pytest.fixture()
@pytest.fixture
async def admin_client() -> AsyncIterator[AdminClient]:
async with AdminClient(
base_url=URL("http://platform-admin/apis/admin/v1")
) as client:
yield client


@pytest.fixture()
@pytest.fixture
def storage_metrics_s3_storage(
s3_client: aiobotocore.client.AioBaseClient, aws_config: AWSConfig
) -> StorageMetricsAsyncS3Storage:
Expand All @@ -183,7 +184,7 @@ def storage_metrics_s3_storage(
)


@pytest.fixture()
@pytest.fixture
def storage_usage_service(
config: Config,
admin_client: AdminClient,
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/conftest_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def auth_jwt_secret() -> str:
_TokenFactory = Callable[[str], str]


@pytest.fixture()
@pytest.fixture
def token_factory() -> _TokenFactory:
def _factory(name: str) -> str:
payload = {"identity": name}
Expand All @@ -40,23 +40,23 @@ def _factory(name: str) -> str:
return _factory


@pytest.fixture()
@pytest.fixture
def admin_token(token_factory: Callable[[str], str]) -> str:
return token_factory("admin")


@pytest.fixture()
@pytest.fixture
def cluster_token(token_factory: Callable[[str], str]) -> str:
return token_factory("cluster")


@pytest.fixture()
@pytest.fixture
def no_claim_token(auth_jwt_secret: str) -> str:
payload: dict[str, Any] = {}
return jwt.encode(payload, auth_jwt_secret, algorithm="HS256")


@pytest.fixture()
@pytest.fixture
async def auth_client(auth_server: URL, admin_token: str) -> AsyncIterator[AuthClient]:
async with AuthClient(url=auth_server, token=admin_token) as client:
yield client
Expand All @@ -71,7 +71,7 @@ class _User:
_UserFactory = Callable[..., Awaitable[_User]]


@pytest.fixture()
@pytest.fixture
async def granter(auth_client: AuthClient, admin_token: str) -> Any:
async def f(whom: Any, what: Any, sourcer: Any) -> None:
headers = auth_client._generate_headers(sourcer.token)
Expand All @@ -83,7 +83,7 @@ async def f(whom: Any, what: Any, sourcer: Any) -> None:
return f


@pytest.fixture()
@pytest.fixture
async def regular_user_factory(
auth_client: AuthClient,
token_factory: _TokenFactory,
Expand Down
11 changes: 6 additions & 5 deletions tests/integration/conftest_moto.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
import pytest
from aiobotocore.client import AioBaseClient
from aiobotocore.session import AioSession
from platform_storage_api.config import AWSConfig
from pytest_docker.plugin import Services
from yarl import URL

from platform_storage_api.config import AWSConfig


@pytest.fixture(scope="session")
def _moto_server(docker_ip: str, docker_services: Services) -> URL:
port = docker_services.port_for("moto", 5000)
return URL(f"http://{docker_ip}:{port}")


@pytest.fixture()
@pytest.fixture
async def moto_server(_moto_server: URL) -> AsyncIterator[URL]:
yield _moto_server
await _reset_moto_server(_moto_server)
Expand All @@ -30,7 +31,7 @@ async def _reset_moto_server(moto_url: URL) -> None:
pass


@pytest.fixture()
@pytest.fixture
def aws_config(moto_server: URL) -> AWSConfig:
return AWSConfig(
region="us-east-1",
Expand All @@ -41,12 +42,12 @@ def aws_config(moto_server: URL) -> AWSConfig:
)


@pytest.fixture()
@pytest.fixture
def _session() -> AioSession:
return aiobotocore.session.get_session()


@pytest.fixture()
@pytest.fixture
async def s3_client(
moto_server: URL, aws_config: AWSConfig, _session: AioSession
) -> AsyncIterator[AioBaseClient]:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import aiohttp.web
import pytest
import pytest_asyncio

from platform_storage_api.config import Config
from platform_storage_api.fs.local import FileStatusType

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_api_sharing_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import aiohttp
import yarl
from platform_storage_api.fs.local import FileStatusType

from platform_storage_api.fs.local import FileStatusType
from tests.integration.conftest import ApiConfig, status_iter_response_to_list

from .conftest_auth import _User, _UserFactory
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_api_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import aiohttp
import cbor

from platform_storage_api.api import WSStorageOperation
from platform_storage_api.fs.local import FileStatusType

from tests.integration.conftest import (
ApiConfig,
get_filestatus_dict,
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
from aiobotocore.client import AioBaseClient
from aioresponses import aioresponses
from fastapi import FastAPI
from yarl import URL

from platform_storage_api.config import MetricsConfig
from platform_storage_api.metrics import create_app
from platform_storage_api.storage_usage import StorageUsageService
from yarl import URL

from .conftest import run_asgi_app


@pytest.fixture()
@pytest.fixture
def app(metrics_config: MetricsConfig) -> Iterator[FastAPI]:
with create_app(config=metrics_config) as app:
yield app


@pytest.fixture()
@pytest.fixture
async def metrics_server(
app: FastAPI, unused_tcp_port_factory: Callable[[], int]
) -> AsyncIterator[URL]:
Expand All @@ -33,7 +34,7 @@ async def metrics_server(
yield URL(f"http://{host}:{port}")


@pytest.fixture()
@pytest.fixture
async def client(metrics_server: URL) -> AsyncIterator[aiohttp.ClientSession]:
async with aiohttp.ClientSession(base_url=metrics_server) as client:
yield client
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_storage_usage_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import pytest
from aioresponses import aioresponses

from platform_storage_api.s3_storage import StorageMetricsAsyncS3Storage
from platform_storage_api.storage_usage import StorageUsage, StorageUsageService


@pytest.fixture()
@pytest.fixture
def aiohttp_mock() -> Iterator[aioresponses]:
with aioresponses(passthrough=["http://0.0.0.0", "http://127.0.0.1"]) as mocked:
yield mocked
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest import mock

from aioresponses import aioresponses

from platform_storage_api.config import Config
from platform_storage_api.s3_storage import StorageMetricsAsyncS3Storage
from platform_storage_api.storage_usage import StorageUsage
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from aioresponses import aioresponses


@pytest.fixture()
@pytest.fixture
def aiohttp_mock() -> Iterator[aioresponses]:
with aioresponses() as mocked:
yield mocked
13 changes: 7 additions & 6 deletions tests/unit/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aiohttp_security.api import IDENTITY_KEY
from neuro_auth_client.client import ClientAccessSubTreeView
from neuro_auth_client.security import IdentityPolicy

from platform_storage_api.cache import (
AbstractPermissionChecker,
PermissionsCache,
Expand Down Expand Up @@ -65,7 +66,7 @@ async def check_user_permissions(
raise HTTPNotFound


@pytest.fixture()
@pytest.fixture
def permission_tree() -> ClientAccessSubTreeView:
return ClientAccessSubTreeView(
action="deny",
Expand All @@ -86,12 +87,12 @@ def permission_tree() -> ClientAccessSubTreeView:
)


@pytest.fixture()
@pytest.fixture
def call_log() -> list[Any]:
return []


@pytest.fixture()
@pytest.fixture
def mock_time() -> TimeFactory:
def mock_time() -> float:
return mock_time.time # type: ignore
Expand All @@ -100,7 +101,7 @@ def mock_time() -> float:
return mock_time


@pytest.fixture()
@pytest.fixture
def cache(
call_log: list[Any],
permission_tree: ClientAccessSubTreeView,
Expand All @@ -114,7 +115,7 @@ def cache(
)


@pytest.fixture()
@pytest.fixture
def slow_cache(
call_log: list[Any],
permission_tree: ClientAccessSubTreeView,
Expand All @@ -128,7 +129,7 @@ def slow_cache(
)


@pytest.fixture()
@pytest.fixture
def webrequest() -> Request:
webrequest = make_mocked_request(
"GET", "/", headers={"Authorization": "Bearer authorization"}
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from pathlib import PurePath

import pytest
from yarl import URL

from platform_storage_api.config import (
Config,
StorageConfig,
StorageMode,
StorageServerConfig,
)
from yarl import URL


class TestServerConfig:
Expand Down
Loading