Replace all clean_course_id form methods with common method.

This commit is contained in:
John Eskew
2018-01-18 14:25:57 -05:00
committed by Troy Sankey
parent 875a127f84
commit 27edca3c5e
12 changed files with 42 additions and 126 deletions

View File

@@ -87,7 +87,7 @@ class RefundTests(ModuleStoreTestCase):
def test_bad_courseid(self):
response = self.client.post('/support/refund/', {'course_id': 'foo', 'user': self.student.email})
self.assertContains(response, 'Invalid course id')
self.assertContains(response, 'Course id invalid')
def test_bad_user(self):
response = self.client.post('/support/refund/', {'course_id': str(self.course_id), 'user': 'unknown@foo.com'})

View File

@@ -22,6 +22,7 @@ from django.views.generic.edit import FormView
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from openedx.core.lib.courses import clean_course_id
from student.models import CourseEnrollment
from support.decorators import require_support_permission
@@ -49,17 +50,9 @@ class RefundForm(forms.Form):
def clean_course_id(self):
"""
validate course id field
Validate the course id
"""
course_id = self.cleaned_data['course_id']
try:
course_key = CourseKey.from_string(course_id)
except InvalidKeyError:
try:
course_key = CourseKey.from_string(course_id)
except InvalidKeyError:
raise forms.ValidationError(_("Invalid course id"))
return course_key
return clean_course_id(self)
def clean(self):
"""