def create(self, validated_data): """Create course modes for a course. """ course = Course( validated_data["id"], self._new_course_mode_models(validated_data["modes"]), verification_deadline=validated_data["verification_deadline"] ) course.save() return course
def get_object(self, queryset=None): course_id = self.kwargs.get(self.lookup_url_kwarg) course = Course.get(course_id) if course: return course raise Http404
class CourseTests(TestCase): """ Tests for Course model. """ def setUp(self): super(CourseTests, self).setUp() self.course = Course('a/b/c', []) @ddt.unpack @ddt.data( ('credit', 'Credit'), ('professional', 'Professional Education'), ('no-id-professional', 'Professional Education'), ('verified', 'Verified Certificate'), ('honor', 'Honor Certificate'), ('audit', 'Audit'), ) def test_get_mode_display_name(self, slug, expected_display_name): """ Verify the method properly maps mode slugs to display names. """ mode = CourseMode(mode_slug=slug) self.assertEqual(self.course.get_mode_display_name(mode), expected_display_name) def test_get_mode_display_name_unknown_slug(self): """ Verify the method returns the slug if it has no known mapping. """ mode = CourseMode(mode_slug='Blah!') self.assertEqual(self.course.get_mode_display_name(mode), mode.mode_slug)
def get_queryset(self): return list(Course.iterator())
def restore_object(self, attrs, instance=None): if instance is None: return Course(attrs['id'], attrs['modes'], attrs['verification_deadline']) instance.update(attrs) return instance
def setUp(self): super(CourseTests, self).setUp() self.course = Course('a/b/c', [])