From 88a1f32e9c2af8cd68ead444ba2cdfd1b2858fc9 Mon Sep 17 00:00:00 2001 From: Anastasiia Shevchuk Date: Thu, 12 Dec 2024 16:49:27 +0100 Subject: [PATCH] testlib_refactor: extract password API requests into a separate class Jira ticket: CMK-20440 Change-Id: I14408b7bf66f97253ad293733c1047fadc14a3a9 --- tests/testlib/openapi_session.py | 51 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/tests/testlib/openapi_session.py b/tests/testlib/openapi_session.py index a4d00ae398c..68646c057a7 100644 --- a/tests/testlib/openapi_session.py +++ b/tests/testlib/openapi_session.py @@ -122,6 +122,7 @@ def __init__( self.background_jobs = BackgroundJobsAPI(self) self.dcd = DcdAPI(self) self.ldap_connection = LDAPConnectionAPI(self) + self.passwords = PasswordsAPI(self) def set_authentication_header(self, user: str, password: str) -> None: self.headers["Authorization"] = f"Bearer {user} {password}" @@ -299,30 +300,6 @@ def _handle_wait_redirect( time.sleep(0.5) - def create_password( - self, - ident: str, - title: str, - comment: str, - password: str, - owner: str = "admin", - ) -> None: - """Create a password via REST API.""" - response = self.post( - "/domain-types/password/collections/all", - json={ - "ident": ident, - "title": title, - "comment": comment, - "documentation_url": "localhost", - "password": password, - "owner": owner, - "shared": ["all"], - }, - ) - if response.status_code != 200: - raise UnexpectedResponse.from_response(response) - class BaseAPI: def __init__(self, session: CMKOpenApiSession) -> None: @@ -1136,3 +1113,29 @@ def delete(self, ldap_id: str) -> None: resp = self.session.delete(f"/objects/ldap_connection/{ldap_id}", headers={"If-Match": "*"}) if resp.status_code != 204: raise UnexpectedResponse.from_response(resp) + + +class PasswordsAPI(BaseAPI): + def create( + self, + ident: str, + title: str, + comment: str, + password: str, + owner: str = "admin", + ) -> None: + """Create a password via REST API.""" + response = self.session.post( + "/domain-types/password/collections/all", + json={ + "ident": ident, + "title": title, + "comment": comment, + "documentation_url": "localhost", + "password": password, + "owner": owner, + "shared": ["all"], + }, + ) + if response.status_code != 200: + raise UnexpectedResponse.from_response(response)