Skip to content

Commit

Permalink
fix: pipeline starts with wrong pipeline_index
Browse files Browse the repository at this point in the history
this removes the keys ["pipeline_index", "launch_validation_error_pipeline"] to dont finish the next
pipeline error_validation_task.
  • Loading branch information
johanseto committed Jun 19, 2024
1 parent ceecfd2 commit b7d98ef
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
9 changes: 8 additions & 1 deletion eox_nelp/pearson_vue/rti_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
validate_cdd_request,
validate_ead_request,
)
from eox_nelp.utils import remove_keys_from_dict


class RealTimeImport:
Expand Down Expand Up @@ -60,8 +61,14 @@ def run_pipeline(self):
break
if result.get("launch_validation_error_pipeline"):
self.backend_data["pipeline_index"] = len(pipeline) - 1
# clean kwargs to dont finish next pipeline.
error_validation_kwargs = remove_keys_from_dict(
self.backend_data,
["pipeline_index", "launch_validation_error_pipeline"]
)

tasks = importlib.import_module("eox_nelp.pearson_vue.tasks")
tasks.error_validation_task.delay(**self.backend_data)
tasks.error_validation_task.delay(**error_validation_kwargs)
break

def get_pipeline(self):
Expand Down
13 changes: 9 additions & 4 deletions eox_nelp/pearson_vue/tests/test_rti_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ExamAuthorizationDataImport,
RealTimeImport,
)
from eox_nelp.utils import remove_keys_from_dict


class TestRealTimeImport(unittest.TestCase):
Expand Down Expand Up @@ -153,7 +154,7 @@ def test_launch_validation_error_pipeline(self, error_validation_task_mock):
- Pipeline method 4 is not called.
- backend_data attribute is the expected value.
Without func3,func4 data and pipeline index in the last.
- error_validation_task is called with updated backend_data kwargs.
- error_validation_task is called with error_validation_kwargs.
"""
# Mock pipeline functions
func1 = MagicMock(return_value={"updated_key": "value1"})
Expand All @@ -166,7 +167,6 @@ def test_launch_validation_error_pipeline(self, error_validation_task_mock):
func4 = MagicMock(return_value={"additional_key": "value4"})

self.rti.get_pipeline = MagicMock(return_value=[func1, func2, func2])

self.rti.run_pipeline()

func1.assert_called_once_with(**self.backend_data)
Expand All @@ -178,10 +178,15 @@ def test_launch_validation_error_pipeline(self, error_validation_task_mock):
{
"pipeline_index": len(self.rti.get_pipeline()) - 1, # includes total of pipeline methods
**func1(), # Include data from func1 ()
**func2(), # Include data from func2 (with safely_pipeline_termination)
**func2(), # Include data from func2 (with launch_validation_error_pipeline)
},
)
error_validation_task_mock.delay.assert_called_with(**self.rti.backend_data)

error_validation_kwargs = remove_keys_from_dict(
self.rti.backend_data,
["pipeline_index", "launch_validation_error_pipeline"]
)
error_validation_task_mock.delay.assert_called_with(**error_validation_kwargs)

def test_get_pipeline(self):
"""
Expand Down
49 changes: 48 additions & 1 deletion eox_nelp/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from mock import Mock, patch
from opaque_keys.edx.keys import CourseKey

from eox_nelp.utils import camel_to_snake, extract_course_id_from_string, get_course_from_id, get_item_label
from eox_nelp.utils import (
camel_to_snake,
extract_course_id_from_string,
get_course_from_id,
get_item_label,
remove_keys_from_dict,
)


@ddt
Expand Down Expand Up @@ -222,3 +228,44 @@ def test_invalid_input(self, input_value):
- TypeError is raised
"""
self.assertRaises(TypeError, camel_to_snake, input_value)


@ddt
class RemoveKeysFromDict(TestCase):
"""Test class for the remove_keys_from_dict method."""

def setUp(self):
"""
Set up test environment.
"""
self.student_info = {
"name": "Alice Smith",
"id": 12345,
"grade": 10,
"math_grade": 85,
"science_grade": 92,
"history_grade": 78,
"english_grade": 90,
"has_library_fines": False,
"favorite_subject": "science",
"number_of_siblings": 2,
"email": "[email protected]"
}

@data(
["name", "id"],
["science_grade", "english_grade"],
["favorite_subject", "email"],
["favorite_subject", "math_grade"],
["history_grade"],
)
def test_remove_keys_from_dict(self, removed_keys):
""" Test right functionality.
Expected behavior:
- Returned value is the expected value.
"""
expected_result = remove_keys_from_dict(self.student_info, removed_keys)

for key in removed_keys:
self.assertNotIn(key, expected_result)
17 changes: 17 additions & 0 deletions eox_nelp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,20 @@ def camel_to_snake(string):
String in snake case.
"""
return re.sub(r'(?<!^)(?=[A-Z])', '_', string).lower()


def remove_keys_from_dict(source_dict: dict, removed_keys: list[str]):
"""Remove specific keys from a dict
Args:
source_dict (dict): dict to process
removed_keys (list[str]): keys to remove
Returns:
dict: with the keys removed
"""
return {
key: value
for key, value in source_dict.items()
if key not in removed_keys
}

0 comments on commit b7d98ef

Please sign in to comment.