Replace all clean_course_id form methods with common method.
This commit is contained in:
@@ -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'})
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user