-
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-19902] Add MySQL API schema (#126)
- Loading branch information
1 parent
9a03779
commit af13e94
Showing
15 changed files
with
239 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ List of currently supported connections: | |
* Postgres | ||
* Oracle | ||
* MSSQL | ||
* MySQL | ||
* HDFS | ||
* S3 | ||
|
||
|
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 MySQL 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
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 MYSQL_TYPE | ||
|
||
|
||
class MySQLBaseSchema(BaseModel): | ||
type: MYSQL_TYPE | ||
|
||
class Config: | ||
from_attributes = True | ||
|
||
|
||
class ReadMySQLConnectionSchema(MySQLBaseSchema): | ||
host: str | ||
port: int | ||
database_name: str | ||
additional_params: dict = Field(default_factory=dict) | ||
|
||
|
||
class ReadMySQLAuthSchema(MySQLBaseSchema): | ||
user: str | ||
|
||
|
||
class UpdateMySQLConnectionSchema(MySQLBaseSchema): | ||
host: str | None = None | ||
port: int | None = None | ||
database_name: str | None = None | ||
additional_params: dict | None = Field(default_factory=dict) | ||
|
||
|
||
class UpdateMySQLAuthSchema(MySQLBaseSchema): | ||
user: str | None = None # noqa: F722 | ||
password: SecretStr | None = None | ||
|
||
|
||
class CreateMySQLConnectionSchema(MySQLBaseSchema): | ||
host: str | ||
port: int | ||
database_name: str | ||
additional_params: dict = Field(default_factory=dict) | ||
|
||
|
||
class CreateMySQLAuthSchema(MySQLBaseSchema): | ||
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
80 changes: 80 additions & 0 deletions
80
tests/test_unit/test_connections/test_db_connection/test_create_mysql_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.mysql] | ||
|
||
|
||
async def test_developer_plus_can_create_mysql_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": "mysql", | ||
"host": "127.0.0.1", | ||
"port": 3306, | ||
"database_name": "database", | ||
}, | ||
"auth_data": { | ||
"type": "mysql", | ||
"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_name": connection.data["database_name"], | ||
"additional_params": connection.data["additional_params"], | ||
}, | ||
"auth_data": { | ||
"type": decrypted["type"], | ||
"user": decrypted["user"], | ||
}, | ||
} |
Oops, something went wrong.