test_legacy_download_csv.py 3.08 KB
Newer Older
1 2 3 4 5 6 7
"""
Unit tests for instructor dashboard

Based on (and depends on) unit tests for courseware.

Notes for running by hand:

8
./manage.py lms --settings test test lms/djangoapps/instructor
9 10 11 12 13
"""

from django.test.utils import override_settings

# Need access to internal func to put users in the right group
14
from django.contrib.auth.models import User
15 16 17

from django.core.urlresolvers import reverse

18
from courseware.tests.helpers import LoginEnrollmentTestCase
19
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
20
from student.roles import CourseStaffRole
21 22
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore, clear_existing_modulestores
23
from opaque_keys.edx.locations import SlashSeparatedCourseKey
24 25


26
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
27
class TestInstructorDashboardGradeDownloadCSV(ModuleStoreTestCase, LoginEnrollmentTestCase):
28 29 30 31 32
    '''
    Check for download of csv
    '''

    def setUp(self):
33
        clear_existing_modulestores()
34
        self.toy = modulestore().get_course(SlashSeparatedCourseKey("edX", "toy", "2012_Fall"))
35 36 37 38 39 40 41 42 43 44

        # Create two accounts
        self.student = 'view@test.com'
        self.instructor = 'view2@test.com'
        self.password = 'foo'
        self.create_account('u1', self.student, self.password)
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.student)
        self.activate_user(self.instructor)

45
        CourseStaffRole(self.toy.id).add_users(User.objects.get(email=self.instructor))
46 47 48 49 50 51 52

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.toy)

    def test_download_grades_csv(self):
        course = self.toy
Calen Pennington committed
53
        url = reverse('instructor_dashboard_legacy', kwargs={'course_id': course.id.to_deprecated_string()})
54 55 56 57 58 59 60 61
        msg = "url = {0}\n".format(url)
        response = self.client.post(url, {'action': 'Download CSV of all student grades for this course'})
        msg += "instructor dashboard download csv grades: response = '{0}'\n".format(response)

        self.assertEqual(response['Content-Type'], 'text/csv', msg)

        cdisp = response['Content-Disposition']
        msg += "Content-Disposition = '%s'\n" % cdisp
62
        self.assertEqual(cdisp, 'attachment; filename=grades_{0}.csv'.format(course.id.to_deprecated_string()), msg)
63 64 65 66 67 68 69

        body = response.content.replace('\r', '')
        msg += "body = '{0}'\n".format(body)

        # All the not-actually-in-the-course hw and labs come from the
        # default grading policy string in graders.py
        expected_body = '''"ID","Username","Full Name","edX email","External email","HW 01","HW 02","HW 03","HW 04","HW 05","HW 06","HW 07","HW 08","HW 09","HW 10","HW 11","HW 12","HW Avg","Lab 01","Lab 02","Lab 03","Lab 04","Lab 05","Lab 06","Lab 07","Lab 08","Lab 09","Lab 10","Lab 11","Lab 12","Lab Avg","Midterm","Final"
70
"2","u2","username","view2@test.com","","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"
71 72 73
'''

        self.assertEqual(body, expected_body, msg)