Skip to content

Commit

Permalink
chore: more pr comments that were not including at the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon committed Jun 29, 2023
1 parent 69d70f2 commit 709fd1d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
43 changes: 26 additions & 17 deletions eox_nelp/stats/tests/tests_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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,
Expand All @@ -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"""
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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"])
14 changes: 14 additions & 0 deletions eox_nelp/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 709fd1d

Please sign in to comment.