-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDUCATOR-4618 | Prevent csv processor objects from having duplicate c…
…olumns.
- Loading branch information
1 parent
f961862
commit 11d3a96
Showing
4 changed files
with
142 additions
and
79 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 |
---|---|---|
|
@@ -3,9 +3,10 @@ | |
""" | ||
Tests for the `edx-bulk-grades` api module. | ||
""" | ||
|
||
from __future__ import absolute_import, unicode_literals | ||
|
||
from copy import deepcopy | ||
|
||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from mock import MagicMock, Mock, patch | ||
|
@@ -19,19 +20,22 @@ class BaseTests(TestCase): | |
""" | ||
Common setup functionality for all test cases | ||
""" | ||
def setUp(self): | ||
super(BaseTests, self).setUp() | ||
self.learner = User.objects.create(username='[email protected]') | ||
self.staff = User.objects.create(username='[email protected]') | ||
self.block_id_in_module_id = '85bb02dbd2c14ba5bc31a0264b140dda' | ||
self.block_id = 'block-v1:testX+sg101+2019+type@test+block@%s' % self.block_id_in_module_id | ||
self.course_id = 'course-v1:testX+sg101+2019' | ||
|
||
def _make_enrollments(self): | ||
@classmethod | ||
def setUpTestData(cls): | ||
super(BaseTests, cls).setUpTestData() | ||
cls.learner = User.objects.create(username='[email protected]') | ||
cls.staff = User.objects.create(username='[email protected]') | ||
cls.block_id_in_module_id = '85bb02dbd2c14ba5bc31a0264b140dda' | ||
cls.block_id = 'block-v1:testX+sg101+2019+type@test+block@%s' % cls.block_id_in_module_id | ||
cls.course_id = 'course-v1:testX+sg101+2019' | ||
cls._make_enrollments() | ||
|
||
@classmethod | ||
def _make_enrollments(cls): | ||
for name in ['audit', 'verified', 'masters']: | ||
user = User.objects.create(username='%[email protected]' % name) | ||
Profile.objects.create(user=user, name=name) | ||
enroll = CourseEnrollment.objects.create(course_id=self.course_id, user=user, mode=name) | ||
enroll = CourseEnrollment.objects.create(course_id=cls.course_id, user=user, mode=name) | ||
if name == 'masters': | ||
ProgramCourseEnrollment.objects.create(course_enrollment=enroll) | ||
|
||
|
@@ -73,7 +77,6 @@ def _get_row(self, **kwargs): | |
return row | ||
|
||
def test_export(self): | ||
self._make_enrollments() | ||
processor = api.ScoreCSVProcessor(block_id=self.block_id) | ||
rows = list(processor.get_iterator()) | ||
assert len(rows) == 4 | ||
|
@@ -128,17 +131,27 @@ class TestGradeProcessor(BaseTests): | |
""" | ||
NUM_USERS = 3 | ||
|
||
@patch('lms.djangoapps.grades.api.CourseGradeFactory.read') | ||
def test_export(self, course_grade_factory_mock): | ||
self._make_enrollments() | ||
course_grade_factory_mock.return_value = Mock(percent=0.50) | ||
@patch('lms.djangoapps.grades.api.CourseGradeFactory.read', return_value=Mock(percent=0.50)) | ||
def test_export(self, course_grade_factory_mock): # pylint: disable=unused-argument | ||
processor = api.GradeCSVProcessor(course_id=self.course_id) | ||
rows = list(processor.get_iterator()) | ||
assert len(rows) == self.NUM_USERS + 1 | ||
|
||
def test_columns_not_duplicated_during_init(self): | ||
""" | ||
Tests that GradeCSVProcessor.__init__() does not cause | ||
column names to be duplicated. | ||
""" | ||
processor_1 = api.GradeCSVProcessor(course_id=self.course_id) | ||
|
||
# pretend that we serialize the processor data to some "state" | ||
state = deepcopy(processor_1.__dict__) | ||
processor_2 = api.GradeCSVProcessor(**state) | ||
|
||
assert processor_1.columns == processor_2.columns | ||
|
||
@patch('lms.djangoapps.grades.api.graded_subsections_for_course_id') | ||
def test_subsection_max_min(self, mock_graded_subsections): | ||
self._make_enrollments() | ||
subsection = MagicMock() | ||
subsection.location = MagicMock() | ||
subsection.display_name = 'asdf' | ||
|
@@ -155,8 +168,6 @@ def test_subsection_max_min(self, mock_graded_subsections): | |
|
||
@patch('lms.djangoapps.grades.api.CourseGradeFactory.read') | ||
def test_course_grade_filters(self, course_grade_factory_mock): | ||
self._make_enrollments() | ||
|
||
course_grade_factory_mock.return_value = Mock(percent=0.50) | ||
|
||
processor = api.GradeCSVProcessor(course_id=self.course_id, max_points=100, course_grade_min=60) | ||
|
@@ -169,8 +180,6 @@ def test_course_grade_filters(self, course_grade_factory_mock): | |
|
||
@patch('lms.djangoapps.grades.api.CourseGradeFactory.read') | ||
def test_less_than_zero(self, course_grade_factory_mock): | ||
self._make_enrollments() | ||
|
||
course_grade_factory_mock.return_value = Mock(percent=0.50) | ||
processor = api.GradeCSVProcessor(course_id=self.course_id) | ||
|
||
|
@@ -193,7 +202,6 @@ class TestInterventionProcessor(BaseTests): | |
@patch('lms.djangoapps.grades.api.CourseGradeFactory.read') | ||
@patch('bulk_grades.api.LearnerAPIClient') | ||
def test_export(self, mocked_api, mocked_course_grade_factory): | ||
self._make_enrollments() | ||
data = { | ||
'[email protected]': {'videos_overall': 2, 'videos_last_week': 0, 'problems_overall': 10, | ||
'problems_last_week': 5, | ||
|
@@ -216,3 +224,16 @@ def test_export(self, mocked_api, mocked_course_grade_factory): | |
processor = api.InterventionCSVProcessor(course_id=self.course_id) | ||
rows = list(processor.get_iterator()) | ||
assert len(rows) == 2 | ||
|
||
def test_columns_not_duplicated_during_init(self): | ||
""" | ||
Tests that InterventionCSVProcessor.__init__() does not cause | ||
column names to be duplicated. | ||
""" | ||
processor_1 = api.InterventionCSVProcessor(course_id=self.course_id) | ||
|
||
# pretend that we serialize the processor data to some "state" | ||
state = deepcopy(processor_1.__dict__) | ||
processor_2 = api.InterventionCSVProcessor(**state) | ||
|
||
assert processor_1.columns == processor_2.columns |