-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validate cdd and ead pipes
Also added error_validation_pipeline
- Loading branch information
Showing
7 changed files
with
296 additions
and
164 deletions.
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
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
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 |
---|---|---|
|
@@ -10,11 +10,14 @@ | |
from django.test import override_settings | ||
from django.utils import timezone | ||
from django_countries.fields import Country | ||
from pydantic.v1.utils import deep_update | ||
from eox_nelp.pearson_vue.pipeline import validate_cdd_request, validate_ead_request | ||
|
||
from eox_nelp.edxapp_wrapper.student import CourseEnrollment, anonymous_id_for_user | ||
from eox_nelp.pearson_vue import pipeline | ||
from eox_nelp.pearson_vue.constants import PAYLOAD_CDD, PAYLOAD_EAD, PAYLOAD_PING_DATABASE | ||
from eox_nelp.pearson_vue.pipeline import ( | ||
audit_pipe_error, | ||
build_cdd_request, | ||
build_ead_request, | ||
check_service_availability, | ||
|
@@ -688,3 +691,163 @@ def test_build_ead_request(self, mock_now): | |
result = build_ead_request(**input_data) | ||
|
||
self.assertDictEqual(expected_output, result) | ||
|
||
|
||
@ddt | ||
class TestValidateCddRequest(unittest.TestCase): | ||
""" | ||
Unit tests for the validate_cdd_request method. | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Set up the test environment. | ||
""" | ||
self.cdd_request = { | ||
"@clientCandidateID": "NELC12345", | ||
"@clientID": "12345678", | ||
"candidateName": {"firstName": "John", "lastName": "Doe"}, | ||
"lastUpdate": "2023/05/20 12:00:00 GMT", | ||
"primaryAddress": { | ||
"address1": "123 Main St", | ||
"city": "Anytown", | ||
"country": "US", | ||
"mobile": {"mobileCountryCode": "1", "mobileNumber": "5551234567"}, | ||
"nativeAddress": { | ||
"address1": "123 Main St", | ||
"city": "Anytown", | ||
"firstName": "فلان الفلاني", | ||
"language": "UKN", | ||
"lastName": "فلان الفلاني", | ||
"potentialMismatch": "false", | ||
}, | ||
"phone": {"phoneCountryCode": "1", "phoneNumber": "5551234567"}, | ||
}, | ||
"webAccountInfo": {"email": "[email protected]"}, | ||
} | ||
|
||
@data( | ||
{"@clientCandidateID": ""}, | ||
{"@clientID": ""}, | ||
{"candidateName": {"firstName": ""}}, | ||
{"candidateName": {"lastName": ""}}, | ||
{"lastUpdate": ""}, | ||
{"primaryAddress": {"address1": ""}}, | ||
{"primaryAddress": {"city": ""}}, | ||
{"primaryAddress": {"country": ""}}, | ||
{"primaryAddress": {"mobile": {"mobileCountryCode": ""}}}, | ||
{"primaryAddress": {"mobile": {"mobileNumber": ""}}}, | ||
{"primaryAddress": {"nativeAddress": {"address1": ""}}}, | ||
{"primaryAddress": {"nativeAddress": {"city": ""}}}, | ||
{"primaryAddress": {"nativeAddress": {"firstName": ""}}}, | ||
{"primaryAddress": {"nativeAddress": {"language": ""}}}, | ||
{"primaryAddress": {"nativeAddress": {"lastName": ""}}}, | ||
{"primaryAddress": {"nativeAddress": {"potentialMismatch": ""}}}, | ||
{"primaryAddress": {"phone": {"phoneCountryCode": ""}}}, | ||
{"primaryAddress": {"phone": {"phoneNumber": ""}}}, | ||
{"webAccountInfo": {"email": ""}}, | ||
) | ||
def test_wrong_cdd_request(self, wrong_update): | ||
"""Test validator with a wrong cdd_request updating with empty string | ||
different keys. | ||
Expected behavior: | ||
- The result is the expected value.(with key launch_validation_error_pipeline) | ||
- launch_validation_error_pipeline key is truthy | ||
""" | ||
wrong_cdd_request = deep_update(self.cdd_request, wrong_update) | ||
|
||
result = validate_cdd_request(wrong_cdd_request) | ||
|
||
self.assertIn("launch_validation_error_pipeline", result) | ||
self.assertTrue(bool(result["launch_validation_error_pipeline"])) | ||
|
||
def test_correct_cdd_request(self): | ||
"""Test validator with correct cdd_request. | ||
Expected behavior: | ||
- The result is the expected value. | ||
""" | ||
result = validate_cdd_request(self.cdd_request) | ||
|
||
self.assertIsNone(result) | ||
|
||
|
||
@ddt | ||
class TestValidateEadRequest(unittest.TestCase): | ||
""" | ||
Unit tests for the validate_ead_request method. | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Set up the test environment. | ||
""" | ||
self.ead_request = { | ||
'@authorizationTransactionType': 'Add', | ||
'@clientAuthorizationID': '12345678954', | ||
'@clientID': '12345678', | ||
'clientCandidateID': 'NELC12345', | ||
'eligibilityApptDateFirst': '2024/07/15 11:59:59', | ||
'eligibilityApptDateLast': '2025/07/15 11:59:59', | ||
'examAuthorizationCount': 3, | ||
'examSeriesCode': 'ABC', | ||
'lastUpdate': '2023/05/20 12:00:00 GMT', | ||
} | ||
|
||
@data( | ||
{"@authorizationTransactionType": ""}, | ||
{"@clientAuthorizationID": ""}, | ||
{"@clientID": ""}, | ||
{"clientCandidateID": ""}, | ||
{"eligibilityApptDateFirst": ""}, | ||
{"eligibilityApptDateLast": ""}, | ||
{"examAuthorizationCount": ""}, | ||
{"examSeriesCode": ""}, | ||
{"lastUpdate": ""}, | ||
) | ||
def test_wrong_ead_request(self, wrong_update): | ||
"""Test validator with a wrong ead_request updating with empty string | ||
different keys. | ||
Expected behavior: | ||
- The result is the expected value.(with key launch_validation_error_pipeline) | ||
- launch_validation_error_pipeline key is truthy | ||
""" | ||
wrong_ead_request = deep_update(self.ead_request, wrong_update) | ||
|
||
result = validate_ead_request(wrong_ead_request) | ||
|
||
self.assertIn("launch_validation_error_pipeline", result) | ||
self.assertTrue(bool(result["launch_validation_error_pipeline"])) | ||
|
||
def test_correct_ead_request(self): | ||
"""Test validator with correct ead_request. | ||
Expected behavior: | ||
- The result is the expected value. | ||
""" | ||
result = validate_ead_request(self.ead_request) | ||
|
||
self.assertIsNone(result) | ||
|
||
|
||
class TestAuditPipeError(unittest.TestCase): | ||
""" | ||
Unit tests for the audit_pipe_error method. | ||
""" | ||
|
||
def test_audit_pipe_error(self): | ||
kwargs = { | ||
"validation_exception": { | ||
"error": ["String to short."] | ||
} | ||
} | ||
args = ("vaderio", 3244) | ||
with self.assertLogs(pipeline.__name__, level="ERROR") as logs: | ||
result = audit_pipe_error(*args, **kwargs) | ||
self.assertIsNone(result) | ||
log_error = [ | ||
f"ERROR:{pipeline.__name__}:Validation Error args:{args}-kwargs:{kwargs}" | ||
] | ||
self.assertListEqual(log_error, logs.output) |
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.