Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Add configuration option for approving grades automatically
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
carsongee committed Apr 14, 2015
1 parent f85ef14 commit 821558f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lmod_proxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
# certificate authentication
'LMODP_URLBASE': 'https://learning-modules.mit.edu:8443/',

# Any value other than '' or unset enables grade approval in
# Learning Modules so that instructors do no have to do it
# manually for all grades posted in this instance.
'LMODP_APPROVE_GRADES': None,

# Direct path to apache htpasswd file to use for basic auth
'LMODP_HTPASSWD_PATH': '.htpasswd',

Expand Down
1 change: 1 addition & 0 deletions lmod_proxy/edx_grades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ def index(user):
form=EdXGradesForm(),
cert=current_app.config['LMODP_CERT'],
urlbase=current_app.config['LMODP_URLBASE'],
approve_grades=bool(current_app.config['LMODP_APPROVE_GRADES'])
)
9 changes: 7 additions & 2 deletions lmod_proxy/edx_grades/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from cStringIO import StringIO

from flask import render_template
from flask import render_template, current_app
from requests.exceptions import RequestException

from pylmod.exceptions import PyLmodException
Expand All @@ -19,11 +19,16 @@ def post_grades(gradebook, form):
tuple: message(str), data(list), success(bool)
"""
error_message = ''
approve_grades = False
if current_app.config['LMODP_APPROVE_GRADES']:
approve_grades = True

fake_csv = StringIO(form.datafile.data)
results = None
try:
results, time_taken = gradebook.spreadsheet2gradebook(fake_csv)
results, time_taken = gradebook.spreadsheet2gradebook(
csv_file=fake_csv, approve_grades=approve_grades
)
except PyLmodException, ex:
error_message = unicode(ex)

Expand Down
1 change: 1 addition & 0 deletions lmod_proxy/edx_grades/templates/edx_grades/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h4 class="muted">Configuration</h4>
<ul>
<li>Client Certificate: <em>{{ cert }}</em></li>
<li>LMod URL: <em>{{ urlbase }}</em></li>
<li>Approve Grades?: <em>{{ approve_grades }}</em></li>
</ul>
</div>
<div class="p1 brdr--light-gray" id="results" style="display: none">
Expand Down
38 changes: 32 additions & 6 deletions lmod_proxy/tests/test_edx_grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,17 @@ def test_post_grades(self, mock_io):
gradebook.spreadsheet2gradebook.return_value = (gradebook_return, 1)

# Call regularly
message, data, success = post_grades(gradebook, form)
with self.app.app_context():
message, data, success = post_grades(gradebook, form)
self.assertTrue(gradebook.spreadsheet2gradebook.called)
mock_io.assert_called_with(self.FULL_FORM['datafile'])
self.assertEqual(data, [])

# Now raise an expected exception
self.assertTrue(success)
gradebook.spreadsheet2gradebook.side_effect = PyLmodException('test')
message, data, success = post_grades(gradebook, form)
with self.app.app_context():
message, data, success = post_grades(gradebook, form)
self.assertTrue(gradebook.spreadsheet2gradebook.called)
mock_io.assert_called_with(self.FULL_FORM['datafile'])
self.assertFalse(success)
Expand All @@ -254,10 +256,12 @@ def test_post_grades(self, mock_io):
gradebook_return['data']['results'] = ['completely unexpected']
gradebook.spreadsheet2gradebook.side_effect = None

with mock.patch(
'lmod_proxy.edx_grades.actions.render_template'
) as mock_template:
message, data, success = post_grades(gradebook, form)
with self.app.app_context():
with mock.patch(
'lmod_proxy.edx_grades.actions.render_template'
) as mock_template:
message, data, success = post_grades(gradebook, form)

self.assertTrue(gradebook.spreadsheet2gradebook.called)
mock_io.assert_called_with(self.FULL_FORM['datafile'])
mock_template.assert_called_with(
Expand All @@ -268,6 +272,28 @@ def test_post_grades(self, mock_io):
self.assertFalse(success)
self.assertEqual(data, [])

def test_post_grades_approve(self):
"""Validate that approve grades works"""
from lmod_proxy.edx_grades.forms import EdXGradesForm
from lmod_proxy.edx_grades.actions import post_grades

form = EdXGradesForm(**self.FULL_FORM)
gradebook = mock.MagicMock()
gradebook_return = {'data': {'test': 'foo'}}
gradebook.spreadsheet2gradebook.return_value = (gradebook_return, 1)

with self.app.app_context():
with mock.patch.dict(
'lmod_proxy.edx_grades.actions.current_app.config',
{'LMODP_APPROVE_GRADES': 'a'}
):
_, data, _ = post_grades(gradebook, form)
self.assertTrue(gradebook.spreadsheet2gradebook.called)
self.assertTrue(
gradebook.spreadsheet2gradebook.call_args[1]['approve_grades']
)
self.assertEqual(data, [])

def test_template_existence(self):
"""Just an OS test that the templates we need exist"""
template_list = [
Expand Down

0 comments on commit 821558f

Please sign in to comment.