|
| 1 | +import pytest |
| 2 | +from httpx import AsyncClient |
| 3 | + |
| 4 | +from tests.mocks import MockConnection, UserTestRoles |
| 5 | + |
| 6 | +pytestmark = [pytest.mark.asyncio, pytest.mark.backend, pytest.mark.clickhouse] |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "create_connection_data,create_connection_auth_data", |
| 11 | + [ |
| 12 | + ( |
| 13 | + { |
| 14 | + "type": "clickhouse", |
| 15 | + "host": "127.0.0.1", |
| 16 | + "port": 8123, |
| 17 | + }, |
| 18 | + { |
| 19 | + "type": "clickhouse", |
| 20 | + "user": "user", |
| 21 | + "password": "secret", |
| 22 | + }, |
| 23 | + ), |
| 24 | + ], |
| 25 | + indirect=True, |
| 26 | +) |
| 27 | +async def test_developer_plus_can_update_clickhouse_connection( |
| 28 | + client: AsyncClient, |
| 29 | + group_connection: MockConnection, |
| 30 | + role_developer_plus: UserTestRoles, |
| 31 | +): |
| 32 | + # Arrange |
| 33 | + user = group_connection.owner_group.get_member_of_role(role_developer_plus) |
| 34 | + group_connection.connection.group.id |
| 35 | + |
| 36 | + # Act |
| 37 | + result = await client.patch( |
| 38 | + f"v1/connections/{group_connection.id}", |
| 39 | + headers={"Authorization": f"Bearer {user.token}"}, |
| 40 | + json={ |
| 41 | + "connection_data": { |
| 42 | + "type": "clickhouse", |
| 43 | + "host": "127.0.1.1", |
| 44 | + "database": "new_name", |
| 45 | + }, |
| 46 | + "auth_data": { |
| 47 | + "type": "clickhouse", |
| 48 | + "user": "new_user", |
| 49 | + }, |
| 50 | + }, |
| 51 | + ) |
| 52 | + |
| 53 | + # Assert |
| 54 | + assert result.status_code == 200 |
| 55 | + assert result.json() == { |
| 56 | + "id": group_connection.id, |
| 57 | + "name": group_connection.name, |
| 58 | + "description": group_connection.description, |
| 59 | + "group_id": group_connection.group_id, |
| 60 | + "connection_data": { |
| 61 | + "type": group_connection.data["type"], |
| 62 | + "host": "127.0.1.1", |
| 63 | + "port": group_connection.data["port"], |
| 64 | + "database": "new_name", |
| 65 | + "additional_params": {}, |
| 66 | + }, |
| 67 | + "auth_data": { |
| 68 | + "type": group_connection.credentials.value["type"], |
| 69 | + "user": "new_user", |
| 70 | + }, |
| 71 | + } |
0 commit comments