Skip to content

Commit

Permalink
feat: remove audited methods from api client and add them directly to…
Browse files Browse the repository at this point in the history
… the pipeline
  • Loading branch information
andrey-canon committed Jun 21, 2024
1 parent 5e47905 commit e87da42
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 109 deletions.
136 changes: 59 additions & 77 deletions eox_nelp/api_clients/pearson_rti.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
from eox_nelp.api_clients import AbstractSOAPClient
from eox_nelp.api_clients.authenticators import PKCS12Authenticator

try:
from eox_audit_model.decorators import audit_method
except ImportError:
def audit_method(action): # pylint: disable=unused-argument
"""Identity audit_method"""
return lambda x: x


LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -72,45 +64,40 @@ def import_candidate_demographics(self, payload):
Returns:
<Dict>: Parsed xml response to Dict format.
"""
@audit_method(action="Import Candidate Demographics")
def import_candidate_demographics_request(payload):
"""This is a wrapper that allows to make audit-able the import_candidate_demographics method."""
xml_response = BeautifulSoup(
self.make_post("cxfws2/services/CDDService", payload),
"xml",
)
fault = xml_response.find("soapenv:Fault")

# There are multiple kind of errors, some of them generates a soapenv:Fault section and others
# generates an status error section, the following condition handles the first case.
if fault:
return {
"status": "error",
"fault_code": xml_response.find("faultcode").text,
"message": xml_response.find("faultstring").text,
}

status = xml_response.find("status")

if status:
return {
"status": status.text.lower(),
"message": xml_response.find("message").text,
"candidate_id": xml_response.find("cdd:cddResponse").attrs.get("candidateID"),
"client_candidate_id": xml_response.find("cdd:cddResponse").attrs.get("clientCandidateID"),
}

LOGGER.error(
"An unexpected error has occurred trying to make a CDD request getting the following response: %s",
xml_response,
)
xml_response = BeautifulSoup(
self.make_post("cxfws2/services/CDDService", payload),
"xml",
)
fault = xml_response.find("soapenv:Fault")

# There are multiple kind of errors, some of them generates a soapenv:Fault section and others
# generates an status error section, the following condition handles the first case.
if fault:
return {
"status": "unexpected error",
"response": xml_response,
"status": "error",
"fault_code": xml_response.find("faultcode").text,
"message": xml_response.find("faultstring").text,
}

return import_candidate_demographics_request(payload)
status = xml_response.find("status")

if status:
return {
"status": status.text.lower(),
"message": xml_response.find("message").text,
"candidate_id": xml_response.find("cdd:cddResponse").attrs.get("candidateID"),
"client_candidate_id": xml_response.find("cdd:cddResponse").attrs.get("clientCandidateID"),
}

LOGGER.error(
"An unexpected error has occurred trying to make a CDD request getting the following response: %s",
xml_response,
)

return {
"status": "unexpected error",
"response": xml_response,
}

def import_exam_authorization(self, payload):
"""The EAD service imports exam authorization data into the Pearson VUE system. This
Expand All @@ -122,41 +109,36 @@ def import_exam_authorization(self, payload):
Returns:
<Dict>: Parsed xml response to Dict format.
"""
@audit_method(action="Import Exam Authorization")
def import_exam_authorization_request(payload):
"""This is a wrapper that allows to make audit-able the import_exam_authorization method."""
xml_response = BeautifulSoup(
self.make_post("cxfws2/services/EADService", payload),
"xml",
)
fault = xml_response.find("soapenv:Fault")

# There are multiple kind of errors, some of them generates a soapenv:Fault section and others
# generates an status error section, the following condition handles the first case.
if fault:
return {
"status": "error",
"fault_code": xml_response.find("faultcode").text,
"message": xml_response.find("faultstring").text,
}

status = xml_response.find("status")

if status:
return {
"status": status.text.lower(),
"message": xml_response.find("message").text if xml_response.find("message") else "",
"client_candidate_id": xml_response.find("clientCandidateID").text,
}

LOGGER.error(
"An unexpected error has occurred trying to make a EAD request getting the following response: %s",
xml_response,
)
xml_response = BeautifulSoup(
self.make_post("cxfws2/services/EADService", payload),
"xml",
)
fault = xml_response.find("soapenv:Fault")

# There are multiple kind of errors, some of them generates a soapenv:Fault section and others
# generates an status error section, the following condition handles the first case.
if fault:
return {
"status": "unexpected error",
"response": xml_response,
"status": "error",
"fault_code": xml_response.find("faultcode").text,
"message": xml_response.find("faultstring").text,
}

return import_exam_authorization_request(payload)
status = xml_response.find("status")

if status:
return {
"status": status.text.lower(),
"message": xml_response.find("message").text if xml_response.find("message") else "",
"client_candidate_id": xml_response.find("clientCandidateID").text,
}

LOGGER.error(
"An unexpected error has occurred trying to make a EAD request getting the following response: %s",
xml_response,
)

return {
"status": "unexpected error",
"response": xml_response,
}
82 changes: 50 additions & 32 deletions eox_nelp/pearson_vue/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
from eox_nelp.pearson_vue.utils import generate_client_authorization_id, update_xml_with_dict
from eox_nelp.signals.utils import get_completed_and_graded

try:
from eox_audit_model.decorators import audit_method
except ImportError:
def audit_method(action): # pylint: disable=unused-argument
"""Identity audit_method"""
return lambda x: x

logger = logging.getLogger(__name__)

User = get_user_model()
Expand Down Expand Up @@ -179,26 +186,32 @@ def import_candidate_demographics(cdd_request, **kwargs): # pylint: disable=unu
Raises:
Exception: If the Pearson VUE RTI service does not accept the import request.
"""
api_client = PearsonRTIApiClient()
payload = {
"soapenv:Envelope": {
"soapenv:Header": {
"wsse:Security": {
"wsse:UsernameToken": {
"wsse:Username": getattr(settings, "PEARSON_RTI_WSDL_USERNAME"),
"wsse:Password": {
"#text": getattr(settings, "PEARSON_RTI_WSDL_PASSWORD")
@audit_method(action="Import Candidate Demographics")
def import_candidate_demographics_request(cdd_request):
"""This is a wrapper that allows to make audit-able the import_candidate_demographics method."""
api_client = PearsonRTIApiClient()
payload = {
"soapenv:Envelope": {
"soapenv:Header": {
"wsse:Security": {
"wsse:UsernameToken": {
"wsse:Username": getattr(settings, "PEARSON_RTI_WSDL_USERNAME"),
"wsse:Password": {
"#text": getattr(settings, "PEARSON_RTI_WSDL_PASSWORD")
},
},
},
},
"soapenv:Body": {
"sch:cddRequest": cdd_request
},
},
"soapenv:Body": {
"sch:cddRequest": cdd_request
},
},
}
payload = update_xml_with_dict(PAYLOAD_CDD, payload)
response = api_client.import_candidate_demographics(payload)
}
payload = update_xml_with_dict(PAYLOAD_CDD, payload)

return api_client.import_candidate_demographics(payload)

response = import_candidate_demographics_request(cdd_request)

if response.get("status", "error") != "accepted":
# pylint: disable=broad-exception-raised
Expand All @@ -224,26 +237,31 @@ def import_exam_authorization(ead_request, **kwargs): # pylint: disable=unused-
Raises:
Exception: If the Pearson VUE RTI service does not accept the import request.
"""
api_client = PearsonRTIApiClient()
payload = {
"soapenv:Envelope": {
"soapenv:Header": {
"wsse:Security": {
"wsse:UsernameToken": {
"wsse:Username": getattr(settings, "PEARSON_RTI_WSDL_USERNAME"),
"wsse:Password": {
"#text": getattr(settings, "PEARSON_RTI_WSDL_PASSWORD")
@audit_method(action="Import Exam Authorization")
def import_exam_authorization_request(ead_request):
"""This is a wrapper that allows to make audit-able the import_exam_authorization method."""
api_client = PearsonRTIApiClient()
payload = {
"soapenv:Envelope": {
"soapenv:Header": {
"wsse:Security": {
"wsse:UsernameToken": {
"wsse:Username": getattr(settings, "PEARSON_RTI_WSDL_USERNAME"),
"wsse:Password": {
"#text": getattr(settings, "PEARSON_RTI_WSDL_PASSWORD")
},
},
},
},
"soapenv:Body": {
"sch:eadRequest": ead_request
},
},
"soapenv:Body": {
"sch:eadRequest": ead_request
},
},
}
payload = update_xml_with_dict(PAYLOAD_EAD, payload)
response = api_client.import_exam_authorization(payload)
}
payload = update_xml_with_dict(PAYLOAD_EAD, payload)
return api_client.import_exam_authorization(payload)

response = import_exam_authorization_request(ead_request)

if response.get("status", "error") != "accepted":
# pylint: disable=broad-exception-raised
Expand Down

0 comments on commit e87da42

Please sign in to comment.