-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(http-tools): update HttpTools methods to avoid overriding #67
base: main
Are you sure you want to change the base?
Conversation
… *_without_session methods Replaced all usages of do_get, do_post, do_put, do_delete with the *_with_session and *_without_session in the HttpsTools interface Replaced all usages of do_get and do_post in aas_service.py with do_get_with_session and do_post_with_session equivalents to match the updated HttpTools interface This change prevents accidental method overrides in python and ensures clear intent of session usage
Co-authored-by: Carlos Diez <[email protected]>
Co-authored-by: Carlos Diez <[email protected]>
Co-authored-by: Carlos Diez <[email protected]>
Co-authored-by: Carlos Diez <[email protected]>
@@ -146,7 +146,7 @@ def get_all_asset_administration_shell_descriptors( | |||
|
|||
# Make the request | |||
url = f"{self.aas_url}/shell-descriptors" | |||
response = HttpTools.do_get( | |||
response = HttpTools.do_get_with_session( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_get_with_session( | |
response = HttpTools.do_get( |
@@ -194,7 +194,7 @@ def get_asset_administration_shell_descriptor_by_id( | |||
|
|||
# Make the request | |||
url = f"{self.aas_url}/shell-descriptors/{encoded_identifier}" | |||
response = HttpTools.do_get(url=url, headers=headers, verify=self.verify_ssl) | |||
response = HttpTools.do_get_with_session(url=url, headers=headers, verify=self.verify_ssl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_get_with_session(url=url, headers=headers, verify=self.verify_ssl) | |
response = HttpTools.do_get(url=url, headers=headers, verify=self.verify_ssl) |
@@ -265,7 +265,7 @@ def get_submodel_descriptors_by_aas_id( | |||
|
|||
# Make the request | |||
url = f"{self.aas_url}/shell-descriptors/{encoded_identifier}/submodel-descriptors" | |||
response = HttpTools.do_get( | |||
response = HttpTools.do_get_with_session( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_get_with_session( | |
response = HttpTools.do_get( |
@@ -316,7 +316,7 @@ def get_submodel_descriptor_by_ass_and_submodel_id( | |||
|
|||
# Make the request | |||
url = f"{self.aas_url}/shell-descriptors/{encoded_aas_identifier}/submodel-descriptors/{encoded_submodel_identifier}" | |||
response = HttpTools.do_get(url=url, headers=headers, verify=self.verify_ssl) | |||
response = HttpTools.do_get_with_session(url=url, headers=headers, verify=self.verify_ssl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_get_with_session(url=url, headers=headers, verify=self.verify_ssl) | |
response = HttpTools.do_get(url=url, headers=headers, verify=self.verify_ssl) |
@@ -356,7 +356,7 @@ def create_asset_administration_shell_descriptor( | |||
|
|||
# Make the request | |||
url = f"{self.aas_url}/shell-descriptors" | |||
response = HttpTools.do_post( | |||
response = HttpTools.do_post_with_session( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_post_with_session( | |
response = HttpTools.do_post( |
@@ -39,28 +39,32 @@ | |||
class HttpTools: | |||
|
|||
# do get request without session | |||
def do_get(url,verify=True,headers=None,timeout=None,params=None,allow_redirects=False): | |||
@staticmethod | |||
def do_get_without_session(url,verify=True,headers=None,timeout=None,params=None,allow_redirects=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def do_get_without_session(url,verify=True,headers=None,timeout=None,params=None,allow_redirects=False): | |
def do_get(url,verify=True,headers=None,timeout=None,params=None,allow_redirects=False): |
As discussed in the issue, we are only going to change *_with_session
.
if session is None: | ||
session = requests.Session() | ||
return session.get(url=url,verify=verify, | ||
timeout=timeout,headers=headers, | ||
params=params,allow_redirects=allow_redirects) | ||
|
||
# do post request without session | ||
def do_post(url,data=None,verify=True,headers=None,timeout=None,json=None,allow_redirects=False): | ||
@staticmethod | ||
def do_post_without_session(url,data=None,verify=True,headers=None,timeout=None,json=None,allow_redirects=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def do_post_without_session(url,data=None,verify=True,headers=None,timeout=None,json=None,allow_redirects=False): | |
def do_post(url,data=None,verify=True,headers=None,timeout=None,json=None,allow_redirects=False): |
@@ -70,15 +74,15 @@ def do_post(url,session=None,data=None,verify=True,headers=None,timeout=None,jso | |||
|
|||
# do put request without session | |||
@staticmethod | |||
def do_put(url, data=None, verify=True, headers=None, timeout=None, json=None, allow_redirects=False): | |||
def do_put_without_session(url, data=None, verify=True, headers=None, timeout=None, json=None, allow_redirects=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def do_put_without_session(url, data=None, verify=True, headers=None, timeout=None, json=None, allow_redirects=False): | |
def do_put(url, data=None, verify=True, headers=None, timeout=None, json=None, allow_redirects=False): |
@@ -88,14 +92,14 @@ def do_put(url, session=None, data=None, verify=True, headers=None, timeout=None | |||
|
|||
# do delete request without session | |||
@staticmethod | |||
def do_delete(url, verify=True, headers=None, timeout=None, params=None, allow_redirects=False): | |||
def do_delete_without_session(url, verify=True, headers=None, timeout=None, params=None, allow_redirects=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def do_delete_without_session(url, verify=True, headers=None, timeout=None, params=None, allow_redirects=False): | |
def do_delete(url, verify=True, headers=None, timeout=None, params=None, allow_redirects=False): |
"""Test a successful GET request.""" | ||
mock_get.return_value = Mock(status_code=200, json=lambda: {"message": "success"}) | ||
|
||
response = HttpTools.do_get(self.test_url) | ||
response = HttpTools.do_get_without_session(self.test_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_get_without_session(self.test_url) | |
response = HttpTools.do_get(self.test_url) |
"""Test POST request with bad request response.""" | ||
mock_post.return_value = Mock(status_code=400, json=lambda: {"error": "Bad Request"}) | ||
|
||
response = HttpTools.do_post_without_session(self.test_url, json=self.payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_post_without_session(self.test_url, json=self.payload) | |
response = HttpTools.do_post(self.test_url, json=self.payload) |
"""Test a successful PUT request.""" | ||
mock_put.return_value = Mock(status_code=200, json=lambda: {"message": "updated"}) | ||
|
||
response = HttpTools.do_put(self.test_url, json=self.payload) | ||
response = HttpTools.do_put_without_session(self.test_url, json=self.payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_put_without_session(self.test_url, json=self.payload) | |
response = HttpTools.do_put(self.test_url, json=self.payload) |
"""Test PUT request with bad request response.""" | ||
mock_put.return_value = Mock(status_code=400, json=lambda: {"error": "Bad Request"}) | ||
|
||
response = HttpTools.do_put(self.test_url, json=self.payload) | ||
response = HttpTools.do_put_without_session(self.test_url, json=self.payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_put_without_session(self.test_url, json=self.payload) | |
response = HttpTools.do_put(self.test_url, json=self.payload) |
"""Test a successful DELETE request.""" | ||
mock_delete.return_value = Mock(status_code=204, json=lambda: {"message": "deleted"}) | ||
|
||
response = HttpTools.do_delete_without_session(self.test_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_delete_without_session(self.test_url) | |
response = HttpTools.do_delete(self.test_url) |
"""Test DELETE request with not found response.""" | ||
mock_delete.return_value = Mock(status_code=404, json=lambda: {"error": "Not Found"}) | ||
|
||
response = HttpTools.do_delete_without_session(self.test_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpTools.do_delete_without_session(self.test_url) | |
response = HttpTools.do_delete(self.test_url) |
|
Description
This PR refactors the HttpTools methods to avoid overriding between session and non-session variants. Along with that this also refactors all the usages of the HttpTools method.
Replaced all usages of do_get, do_post, do_put, do_delete with the *_with_session and *_without_session in the HttpsTools interface
Replaced all usages of do_get and do_post in aas_service.py with do_get_with_session and do_post_with_session equivalents to match the updated HttpTools interface
This change prevents accidental method overrides in python and ensures clear intent of session usage
#52
Pre-review checks
Please ensure to do as many of the following checks as possible, before asking for committer review: