|
1 | 1 | import uuid |
2 | | - |
3 | 2 | from eventsourcingdb.client import Client |
4 | | - |
5 | | -from .containerized_testing_database import ContainerizedTestingDatabase |
6 | | -from .docker.image import Image |
| 3 | +from eventsourcingdb.container import Container |
7 | 4 | from .testing_database import TestingDatabase |
8 | 5 |
|
9 | | - |
10 | 6 | class Database: |
11 | 7 | __create_key = object() |
12 | 8 |
|
13 | 9 | def __init__( |
14 | 10 | self, |
15 | 11 | create_key, |
16 | | - with_authorization: ContainerizedTestingDatabase, |
| 12 | + with_authorization: TestingDatabase, |
17 | 13 | with_invalid_url: TestingDatabase |
18 | 14 | ): |
19 | 15 | assert create_key == Database.__create_key, \ |
20 | 16 | 'Database objects must be created using Database.create.' |
21 | 17 |
|
22 | | - self.with_authorization: ContainerizedTestingDatabase = with_authorization |
| 18 | + self.with_authorization: TestingDatabase = with_authorization |
23 | 19 | self.with_invalid_url: TestingDatabase = with_invalid_url |
24 | 20 |
|
25 | 21 | @classmethod |
26 | 22 | async def create(cls) -> 'Database': |
27 | | - image = Image('eventsourcingdb', 'latest') |
28 | | - |
29 | 23 | api_token = str(uuid.uuid4()) |
30 | | - with_authorization = await ContainerizedTestingDatabase.create( |
31 | | - image, |
32 | | - ['run', '--api-token', f'{api_token}', '--data-directory-temporary'], |
33 | | - api_token, |
| 24 | + |
| 25 | + # Erstellen und Starten des Containers mit der zentralen Container-Klasse |
| 26 | + container = Container( |
| 27 | + api_token=api_token |
| 28 | + ) |
| 29 | + container.start() |
| 30 | + |
| 31 | + # Client mit Autorisierung erstellen |
| 32 | + with_authorization_client = container.get_client() |
| 33 | + await with_authorization_client.initialize() |
| 34 | + with_authorization = TestingDatabase( |
| 35 | + with_authorization_client, |
| 36 | + container # Container an TestingDatabase übergeben für cleanup |
34 | 37 | ) |
35 | 38 |
|
| 39 | + # Client mit ungültiger URL erstellen - api_token statt auth_token verwenden |
36 | 40 | with_invalid_url_client = Client( |
37 | | - base_url='http://localhost.invalid', api_token=api_token |
| 41 | + base_url='http://localhost.invalid', |
| 42 | + api_token=api_token |
38 | 43 | ) |
39 | 44 | await with_invalid_url_client.initialize() |
40 | 45 | with_invalid_url = TestingDatabase( |
|
0 commit comments