-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add audit for succesfull imports #192
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Module to add decorators related Pearson Vue Integration | ||
""" | ||
import logging | ||
|
||
from eox_nelp.utils import camel_to_snake | ||
|
||
try: | ||
from eox_audit_model.decorators import audit_method, rename_function | ||
except ImportError: | ||
def rename_function(name): # pylint: disable=unused-argument | ||
"""Identity rename_function""" | ||
return lambda x: x | ||
|
||
def audit_method(action): # pylint: disable=unused-argument | ||
"""Identity audit_method""" | ||
return lambda x: x | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def audit_backend(func): | ||
"""Decorator that wraps a class method with a try-finally block. | ||
|
||
Args: | ||
func: The method to be decorated. | ||
|
||
Returns: | ||
A wrapper function that executes the decorated method with a try-finally block. | ||
Finally if there is backend_data, is logged after the execution. | ||
""" | ||
def wrapper(self, *args, **kwargs): | ||
|
||
backend_name = self.__class__.__name__ | ||
|
||
@audit_method(action=f"Backend Execution: {backend_name}") | ||
@rename_function(name=f"audit_backend_{camel_to_snake(backend_name)}") | ||
def audit_backend_manager(backend_data, **kwargs): # pylint: disable=unused-argument | ||
logger.info( | ||
"Backend %s executed. \n backend_data: %s", | ||
backend_name, | ||
backend_data, | ||
) | ||
|
||
try: | ||
return func(self, *args, **kwargs) | ||
finally: | ||
if self.use_audit_backend and not self.backend_data.get("catched_pearson_error"): | ||
audit_backend_manager(backend_data=self.backend_data, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,7 +227,7 @@ def import_candidate_demographics(cdd_request, **kwargs): # pylint: disable=unu | |
response = api_client.import_candidate_demographics(payload) | ||
|
||
if response.get("status", "error") == "accepted": | ||
return response | ||
return {"cdd_import": response} | ||
|
||
raise PearsonImportError( | ||
exception_reason=f"Import candidate demographics pipeline has failed with the following response: {response}", | ||
|
@@ -276,7 +276,7 @@ def import_exam_authorization(ead_request, **kwargs): # pylint: disable=unused- | |
response = api_client.import_exam_authorization(payload) | ||
|
||
if response.get("status", "error") == "accepted": | ||
return response | ||
return {"ead_import": response} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as above |
||
|
||
raise PearsonImportError( | ||
exception_reason=f"Import exam authorization pipeline has failed with the following response: {response}", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
do you think we will need this ?