Small changes to the grades djangoapp
-sets up mock_get_score context handler
-fixes an issue with not invalidating lazy scores property
-code quality fixes
-query count optimization in PersistentSubscetionGrade.create
-adds atomic blocks to avoid IntegrityErrors corrupting an entire request
26 lines
724 B
Python
26 lines
724 B
Python
"""
|
|
Utilities for grades related tests
|
|
"""
|
|
from contextlib import contextmanager
|
|
from mock import patch
|
|
|
|
|
|
@contextmanager
|
|
def mock_passing_grade(grade_pass='Pass', percent=0.75):
|
|
"""
|
|
Mock the grading function to always return a passing grade.
|
|
"""
|
|
with patch('lms.djangoapps.grades.course_grades.summary') as mock_grade:
|
|
mock_grade.return_value = {'grade': grade_pass, 'percent': percent}
|
|
yield
|
|
|
|
|
|
@contextmanager
|
|
def mock_get_score(earned=0, possible=1):
|
|
"""
|
|
Mocks the get_score function to return a valid grade.
|
|
"""
|
|
with patch('lms.djangoapps.grades.new.subsection_grade.get_score') as mock_score:
|
|
mock_score.return_value = (earned, possible)
|
|
yield mock_score
|