diff --git a/eox_nelp/stats/tests/tests_metrics.py b/eox_nelp/stats/tests/tests_metrics.py index 6e6779a0..5b6cf1d7 100644 --- a/eox_nelp/stats/tests/tests_metrics.py +++ b/eox_nelp/stats/tests/tests_metrics.py @@ -184,7 +184,7 @@ def setUp(self): # pylint: disable=invalid-name self.modulestore = self.patch.start() # Prepare verticals - verticals = generate_list_mock_data([ + self.verticals = generate_list_mock_data([ { "children": [ { @@ -227,16 +227,16 @@ def setUp(self): # pylint: disable=invalid-name ]) # Prepare sequentials sequential = Mock() - sequential.get_children.return_value = verticals - sequentials = [ + sequential.get_children.return_value = self.verticals + self.sequentials = [ sequential, sequential, sequential, ] # Prepare chapters chapter = Mock() - chapter.get_children.return_value = sequentials - chapters = [ + chapter.get_children.return_value = self.sequentials + self.chapters = [ chapter, chapter, chapter, @@ -245,21 +245,23 @@ def setUp(self): # pylint: disable=invalid-name # Prepare course course = Mock() course.display_name = "testing" - course.get_children.return_value = chapters + course.get_children.return_value = self.chapters # Set course self.modulestore.return_value.get_course.return_value = course + self.expected_returned_enrollments = 5874 + self.expected_returned_roles = 5 # this block set the CourseEnrollment mock and its returned values. filter_result = CourseEnrollment.objects.filter.return_value values_result = filter_result.values.return_value distinct_result = values_result.distinct.return_value - distinct_result.count.return_value = 5874 + distinct_result.count.return_value = self.expected_returned_enrollments # this block set the CourseAccessRole mock and its returned values. filter_result = CourseAccessRole.objects.filter.return_value values_result = filter_result.values.return_value distinct_result = values_result.distinct.return_value - distinct_result.count.return_value = 5 + distinct_result.count.return_value = self.expected_returned_roles def tearDown(self): """Clean cache and restarts mocks""" @@ -301,7 +303,7 @@ def test_get_right_learners_metric(self): """ course = get_course_metrics(self.course_key) - self.assertEqual(5874, course["learners"]) + self.assertEqual(self.expected_returned_enrollments, course["learners"]) def test_get_right_instructors_metric(self): """Based on the initial conditions, this check that the course metrics has the expected instructors value. @@ -311,7 +313,7 @@ def test_get_right_instructors_metric(self): """ course = get_course_metrics(self.course_key) - self.assertEqual(5, course["instructors"]) + self.assertEqual(self.expected_returned_roles, course["instructors"]) def test_get_right_sections_metric(self): """Based on the initial conditions, this check that the course metrics has the expected sections value. @@ -321,7 +323,7 @@ def test_get_right_sections_metric(self): """ course = get_course_metrics(self.course_key) - self.assertEqual(4, course["sections"]) + self.assertEqual(len(self.chapters), course["sections"]) def test_get_right_sub_sections_metric(self): """Based on the initial conditions, this check that the course metrics has the expected sub_sections value. @@ -331,7 +333,7 @@ def test_get_right_sub_sections_metric(self): """ course = get_course_metrics(self.course_key) - self.assertEqual(12, course["sub_sections"]) + self.assertEqual(len(self.chapters) * len(self.sequentials), course["sub_sections"]) def test_get_right_units_metric(self): """Based on the initial conditions, this check that the course metrics has the expected units value. @@ -341,7 +343,7 @@ def test_get_right_units_metric(self): """ course = get_course_metrics(self.course_key) - self.assertEqual(36, course["units"]) + self.assertEqual(len(self.chapters) * len(self.sequentials) * len(self.verticals), course["units"]) def test_set_empty_allowed_components(self): """Based on the initial conditions, this check that the course metrics has the expected components value. @@ -363,9 +365,16 @@ def test_set_allowed_components(self): - 'problem' value is the expected - 'video' value is the expected """ + expected_components = {} + + for vertical in self.verticals: + for child in vertical.children: + expected_components[child.block_type] = expected_components.get(child.block_type, 0) + 1 + + expected_components = { + k: (v * len(self.chapters) * len(self.sequentials)) for k, v in expected_components.items() + } + course = get_course_metrics(self.course_key) - components = course["components"] - self.assertEqual(48, components["html"]) - self.assertEqual(36, components["problem"]) - self.assertEqual(24, components["video"]) + self.assertEqual(expected_components, course["components"]) diff --git a/eox_nelp/tests/utils.py b/eox_nelp/tests/utils.py index ee8091d4..da7b8410 100644 --- a/eox_nelp/tests/utils.py +++ b/eox_nelp/tests/utils.py @@ -20,6 +20,20 @@ def generate_list_mock_data(data): "due": "due_date", "location": "location" }, + { + "due" : "due_date", + "components": [ + { + "block_type": "problem", + }, + { + "block_type": "video", + }, + { + "block_type": "html", + }, + ] + }, ] Every dictionary should be direct key values.No way if there is nested dict the model