Ejemplo n.º 1
0
    def test_get_courses(self):
        course = CourseFactory()
        student = UserFactory()
        instructor = UserFactory()

        course.group.user_set.add(student)
        course.group.user_set.add(instructor)
        course.faculty_group.user_set.add(instructor)

        # as student
        lst = get_courses_for_user(student)
        self.assertEquals(len(lst), 1)
        self.assertTrue(course in lst)

        lst = get_courses_for_instructor(student)
        self.assertEquals(len(lst), 0)

        # as instructor
        lst = get_courses_for_user(instructor)
        self.assertEquals(len(lst), 1)
        self.assertTrue(course in lst)

        lst = get_courses_for_instructor(instructor)
        self.assertEquals(len(lst), 1)
        self.assertTrue(course in lst)
Ejemplo n.º 2
0
 def test_is_course_faculty_not_in_course(self):
     context = Context({'course': self.sandbox_course})
     some_user = UserFactory(
         first_name='Random',
         last_name='User',
         email='*****@*****.**'
     )
     self.assertFalse(is_course_faculty(context, some_user))
Ejemplo n.º 3
0
    def test_post_sis_course_id(self):
        with self.settings(
                COURSEAFFILS_COURSESTRING_MAPPER=CourseStringMapper):
            user = UserFactory()
            self.client.login(username=user.username, password='******')

            data = {
                'lms_course': '1234',
                'lms_course_title': 'LTI Course',
                'sis_course_id': 'SOCWT7113_010_2017_3'
            }
            response = self.client.post(reverse('lti-course-create'), data)
            self.assertEqual(response.status_code, 302)

            c = Course.objects.get(title='LTI Course')
            self.assertEqual(
                c.group.name,
                't3.y2017.s010.ct7113.socw.st.course:columbia.edu')
            self.assertEqual(
                c.faculty_group.name,
                't3.y2017.s010.ct7113.socw.fc.course:columbia.edu')

            self.assertEqual(c.info.term, 3)
            self.assertEqual(c.info.year, 2017)

            self.assertTrue(user in c.group.user_set.all())
            self.assertTrue(user in c.faculty_group.user_set.all())

            self.assertEqual(len(mail.outbox), 2)

            self.assertEqual(mail.outbox[0].subject,
                             'Locus Tempus Course Connected')
            self.assertEqual(mail.outbox[0].from_email,
                             settings.SERVER_EMAIL)
            self.assertEqual(mail.outbox[0].to,
                             [settings.SERVER_EMAIL])

            self.assertEqual(mail.outbox[1].subject,
                             'Locus Tempus Course Connected')
            self.assertEqual(mail.outbox[1].from_email,
                             settings.SERVER_EMAIL)
            self.assertEqual(mail.outbox[1].to,
                             [user.email])

            LTICourseContext.objects.get(
                lms_course_context='1234',
                group=c.group, faculty_group=c.faculty_group)

            # try this again and make sure there is no duplication
            data['lms_course_title'] = 'LTI Course With More Detail'
            response = self.client.post(reverse('lti-course-create'), data)
            self.assertEqual(response.status_code, 302)
            Course.objects.get(title='LTI Course')
            Group.objects.get(name=c.group.name)
            Group.objects.get(name=c.faculty_group.name)
            LTICourseContext.objects.get(
                lms_course_context='1234',
                group=c.group, faculty_group=c.faculty_group)
Ejemplo n.º 4
0
 def test_send_template_email(self):
     user = UserFactory()
     with self.settings(SERVER_EMAIL='*****@*****.**'):
         send_template_email('foo', 'main/notify_lti_course_connect.txt',
                             {'user': user}, '*****@*****.**')
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].subject, 'foo')
         self.assertEquals(mail.outbox[0].from_email,
                           '*****@*****.**')
         self.assertTrue(mail.outbox[0].to, ['*****@*****.**'])
Ejemplo n.º 5
0
    def test_post_course_context_with_unicode(self):
        with self.settings(
                COURSEAFFILS_COURSESTRING_MAPPER=CourseStringMapper):

            user = UserFactory()
            self.client.login(username=user.username, password='******')

            data = {
                'lms_course': '1234',
                'lms_course_title': 'LTI Course "Película", rødgrød med fløde',
                'sis_course_id': '20170152049'
            }
            response = self.client.post(reverse('lti-course-create'), data)
            self.assertEqual(response.status_code, 302)

            c = Course.objects.get(
                title='LTI Course "Película", rødgrød med fløde')
            self.assertEqual(c.group.name, '1234')
            self.assertEqual(c.faculty_group.name, '1234_faculty')
            self.assertEqual(c.info.term, 1)
            self.assertEqual(c.info.year, 2017)

            self.assertTrue(user in c.group.user_set.all())
            self.assertTrue(user in c.faculty_group.user_set.all())

            LTICourseContext.objects.get(
                lms_course_context='1234',
                group=c.group, faculty_group=c.faculty_group)

            # try this again and make sure there is no duplication
            data['lms_course_title'] = 'LTI Course With More Detail'
            response = self.client.post(reverse('lti-course-create'), data)
            self.assertEqual(response.status_code, 302)
            Course.objects.get(
                title='LTI Course "Película", rødgrød med fløde')
            Group.objects.get(name=c.group.name)
            Group.objects.get(name=c.faculty_group.name)
            LTICourseContext.objects.get(
                lms_course_context='1234',
                group=c.group, faculty_group=c.faculty_group)
Ejemplo n.º 6
0
 def test_non_course_user(self):
     request = MagicMock(user=UserFactory())
     view = MagicMock()
     project = self.sandbox_course.projects.first()
     self.assertFalse(
         self.perm.has_object_permission(request, view, project))