Files
edx-platform/lms/djangoapps/grades/tests/utils.py
Eric Fischer 13687e4753 Grades cleanup
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
2016-08-25 11:43:49 -04:00

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