-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoperations_client.py
48 lines (38 loc) · 1.77 KB
/
operations_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import allure
from httpx import Response
from clients.base_client import BaseClient, get_http_client
from config import Settings
from schema.operations import CreateOperationSchema, UpdateOperationSchema, OperationSchema
from tools.routes import APIRoutes
class OperationsClient(BaseClient):
@allure.step("Get list of operations")
def get_operations_api(self) -> Response:
return self.get(APIRoutes.OPERATIONS)
@allure.step("Get operation by id {operation_id}")
def get_operation_api(self, operation_id: int) -> Response:
return self.get(f"{APIRoutes.OPERATIONS}/{operation_id}")
@allure.step("Create operation")
def create_operation_api(self, operation: CreateOperationSchema) -> Response:
return self.post(
APIRoutes.OPERATIONS,
json=operation.model_dump(mode='json', by_alias=True)
)
@allure.step("Update operation by id {operation_id}")
def update_operation_api(
self,
operation_id: int,
operation: UpdateOperationSchema
) -> Response:
return self.patch(
f"{APIRoutes.OPERATIONS}/{operation_id}",
json=operation.model_dump(mode='json', by_alias=True, exclude_none=True)
)
@allure.step("Delete operation by id {operation_id}")
def delete_operation_api(self, operation_id: int) -> Response:
return self.delete(f"{APIRoutes.OPERATIONS}/{operation_id}")
def create_operation(self) -> OperationSchema:
request = CreateOperationSchema()
response = self.create_operation_api(request)
return OperationSchema.model_validate_json(response.text)
def get_operations_client(settings: Settings) -> OperationsClient:
return OperationsClient(client=get_http_client(settings.fake_bank_http_client))