Skip to content

Commit 0e96cf4

Browse files
committed
added function to do authenticated calls
1 parent 90b2104 commit 0e96cf4

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tests/performance/common/base_user.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ def __init__(self, *args, **kwargs):
2323
"Using deployment auth with username: %s", self.deploy_auth.SC_USER_NAME
2424
)
2525

26+
def authenticated_get(self, url, **kwargs):
27+
"""Make GET request with deployment auth"""
28+
kwargs.setdefault("auth", self.deploy_auth.to_auth())
29+
return self.client.get(url, **kwargs)
30+
31+
def authenticated_post(self, url, **kwargs):
32+
"""Make POST request with deployment auth"""
33+
kwargs.setdefault("auth", self.deploy_auth.to_auth())
34+
return self.client.post(url, **kwargs)
35+
36+
def authenticated_put(self, url, **kwargs):
37+
"""Make PUT request with deployment auth"""
38+
kwargs.setdefault("auth", self.deploy_auth.to_auth())
39+
return self.client.put(url, **kwargs)
40+
41+
def authenticated_delete(self, url, **kwargs):
42+
"""Make DELETE request with deployment auth"""
43+
kwargs.setdefault("auth", self.deploy_auth.to_auth())
44+
return self.client.delete(url, **kwargs)
45+
46+
def authenticated_patch(self, url, **kwargs):
47+
"""Make PATCH request with deployment auth"""
48+
kwargs.setdefault("auth", self.deploy_auth.to_auth())
49+
return self.client.patch(url, **kwargs)
50+
2651

2752
class OsparcWebUserBase(OsparcUserBase):
2853
"""
@@ -64,20 +89,19 @@ def _login(self) -> None:
6489
"Logging in user with email: %s",
6590
self.osparc_auth.OSPARC_USER_NAME,
6691
)
67-
response = self.client.post(
92+
response = self.authenticated_post(
6893
"/v0/auth/login",
6994
json={
7095
"email": self.osparc_auth.OSPARC_USER_NAME,
7196
"password": self.osparc_auth.OSPARC_PASSWORD.get_secret_value(),
7297
},
73-
auth=self.deploy_auth.to_auth(),
7498
)
7599
response.raise_for_status()
76100
logging.info("Logged in user with email: %s", self.osparc_auth.OSPARC_USER_NAME)
77101

78102
def _logout(self) -> None:
79103
# Implement logout logic here
80-
self.client.post("/v0/auth/logout", auth=self.deploy_auth.to_auth())
104+
self.authenticated_post("/v0/auth/logout")
81105
logging.info(
82106
"Logged out user with email: %s", self.osparc_auth.OSPARC_USER_NAME
83107
)

0 commit comments

Comments
 (0)