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
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
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)
Exemple #5
0
 def get_queryset(self):
     return list(Course.iterator())
Exemple #6
0
    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
Exemple #7
0
 def get_queryset(self):
     return list(Course.iterator())
Exemple #8
0
 def setUp(self):
     super(CourseTests, self).setUp()
     self.course = Course('a/b/c', [])
 def setUp(self):
     super(CourseTests, self).setUp()
     self.course = Course('a/b/c', [])