-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-19896] Add Clickhouse API schema (#124)
- Loading branch information
1 parent
2260466
commit 2470590
Showing
20 changed files
with
262 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add Clickhouse API schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from pydantic import BaseModel, Field, SecretStr | ||
|
||
from syncmaster.schemas.v1.connection_types import CLICKHOUSE_TYPE | ||
|
||
|
||
class ClickhouseBaseSchema(BaseModel): | ||
type: CLICKHOUSE_TYPE | ||
|
||
class Config: | ||
from_attributes = True | ||
|
||
|
||
class ReadClickhouseConnectionSchema(ClickhouseBaseSchema): | ||
host: str | ||
port: int | ||
database: str | None = None | ||
additional_params: dict = Field(default_factory=dict) | ||
|
||
|
||
class ReadClickhouseAuthSchema(ClickhouseBaseSchema): | ||
user: str | ||
|
||
|
||
class UpdateClickhouseConnectionSchema(ClickhouseBaseSchema): | ||
host: str | None = None | ||
port: int | None = None | ||
database: str | None = None | ||
additional_params: dict | None = Field(default_factory=dict) | ||
|
||
|
||
class UpdateClickhouseAuthSchema(ClickhouseBaseSchema): | ||
user: str | None = None # noqa: F722 | ||
password: SecretStr | None = None | ||
|
||
|
||
class CreateClickhouseConnectionSchema(ClickhouseBaseSchema): | ||
host: str | ||
port: int | ||
database: str | None = None | ||
additional_params: dict = Field(default_factory=dict) | ||
|
||
|
||
class CreateClickhouseAuthSchema(ClickhouseBaseSchema): | ||
user: str | ||
password: SecretStr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
80 changes: 80 additions & 0 deletions
80
tests/test_unit/test_connections/test_db_connection/test_create_clickhouse_connection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
from httpx import AsyncClient | ||
from sqlalchemy import select | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from syncmaster.db.models import AuthData, Connection | ||
from syncmaster.db.repositories.utils import decrypt_auth_data | ||
from syncmaster.settings import Settings | ||
from tests.mocks import MockGroup, UserTestRoles | ||
|
||
pytestmark = [pytest.mark.asyncio, pytest.mark.backend, pytest.mark.clickhouse] | ||
|
||
|
||
async def test_developer_plus_can_create_clickhouse_connection( | ||
client: AsyncClient, | ||
group: MockGroup, | ||
session: AsyncSession, | ||
settings: Settings, | ||
role_developer_plus: UserTestRoles, | ||
): | ||
# Arrange | ||
user = group.get_member_of_role(role_developer_plus) | ||
|
||
# Act | ||
result = await client.post( | ||
"v1/connections", | ||
headers={"Authorization": f"Bearer {user.token}"}, | ||
json={ | ||
"group_id": group.id, | ||
"name": "New connection", | ||
"description": "", | ||
"connection_data": { | ||
"type": "clickhouse", | ||
"host": "127.0.0.1", | ||
"port": 8123, | ||
"database": "database_name", | ||
}, | ||
"auth_data": { | ||
"type": "clickhouse", | ||
"user": "user", | ||
"password": "secret", | ||
}, | ||
}, | ||
) | ||
connection = ( | ||
await session.scalars( | ||
select(Connection).filter_by( | ||
name="New connection", | ||
), | ||
) | ||
).first() | ||
|
||
creds = ( | ||
await session.scalars( | ||
select(AuthData).filter_by( | ||
connection_id=connection.id, | ||
), | ||
) | ||
).one() | ||
|
||
# Assert | ||
decrypted = decrypt_auth_data(creds.value, settings=settings) | ||
assert result.status_code == 200 | ||
assert result.json() == { | ||
"id": connection.id, | ||
"name": connection.name, | ||
"description": connection.description, | ||
"group_id": connection.group_id, | ||
"connection_data": { | ||
"type": connection.data["type"], | ||
"host": connection.data["host"], | ||
"port": connection.data["port"], | ||
"database": connection.data["database"], | ||
"additional_params": connection.data["additional_params"], | ||
}, | ||
"auth_data": { | ||
"type": decrypted["type"], | ||
"user": decrypted["user"], | ||
}, | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.