Ejemplo n.º 1
0
    def test_not_obsolete(self):
        u1 = UniversityFactory.create(detail_page_enabled=True, is_obsolete=False)
        u2 = UniversityFactory.create(detail_page_enabled=True, is_obsolete=True)

        not_obsolete = models.University.objects.not_obsolete()
        self.assertIn(u1, not_obsolete)
        self.assertNotIn(u2, not_obsolete)
Ejemplo n.º 2
0
 def setUp(self):
     self.u1 = UniversityFactory.create(detail_page_enabled=True,
                                        is_obsolete=False,
                                        score=1)
     self.u2 = UniversityFactory.create(detail_page_enabled=True,
                                        is_obsolete=False,
                                        score=1)
Ejemplo n.º 3
0
    def test_landing_view(self):
        u1 = UniversityFactory.create(detail_page_enabled=True, is_obsolete=False)
        u2 = UniversityFactory.create(detail_page_enabled=False, is_obsolete=False)
        u3 = UniversityFactory.create(detail_page_enabled=False, is_obsolete=True)
        u4 = UniversityFactory.create(detail_page_enabled=True, is_obsolete=True)

        listed_universities = list(views.UniversityLandingView().get_queryset())

        self.assertTrue(u1 in listed_universities)
        self.assertFalse(u2 in listed_universities)
        self.assertFalse(u3 in listed_universities)
        self.assertFalse(u4 in listed_universities)
Ejemplo n.º 4
0
    def test_featured(self):
        u1 = UniversityFactory.create(detail_page_enabled=True, is_obsolete=False, score=1)
        u2 = UniversityFactory.create(detail_page_enabled=False, is_obsolete=False, score=2)
        u3 = UniversityFactory.create(detail_page_enabled=False, is_obsolete=True, score=3)
        u4 = UniversityFactory.create(detail_page_enabled=True, is_obsolete=True, score=4)

        featured_universities = list(models.University.objects.featured(4))

        self.assertTrue(u1 in featured_universities)
        self.assertFalse(u2 in featured_universities)
        self.assertFalse(u3 in featured_universities)
        self.assertFalse(u4 in featured_universities)
        self.assertEqual(1, len(featured_universities))
Ejemplo n.º 5
0
 def test_only_display_courses_for_a_specific_university(self):
     university = UniversityFactory(code='test-university')
     UniversityFactory(code='another-university')
     CourseUniversityRelation.objects.create(course=self.active_1,
                                             university=university)
     filter_data = {'university': 'test-university'}
     response = self.client.get(self.api_url, filter_data)
     self.assertContains(response, self.active_1.title)
     self.assertNotContains(response, self.active_2.title)
     filter_data = {'university': 'another-university'}
     response = self.client.get(self.api_url, filter_data)
     self.assertNotContains(response, self.active_1.title)
     self.assertNotContains(response, self.active_2.title)
Ejemplo n.º 6
0
    def setUp(self):
        super(FeedTest, self).setUp()
        date = timezone.now()
        endate = date + datetime.timedelta(days=15)

        self.url = reverse('fun-courses:feed')
        CourseFactory(org='fun',
                      course='course1',
                      name='item1',
                      display_name=u"unpublished",
                      ispublic=False)
        CourseFactory(org='fun',
                      course='course2',
                      name='item2',
                      display_name=u"published",
                      ispublic=True,
                      start=date,
                      end=endate)
        CourseFactory(org='fun',
                      course='course3',
                      name='item3',
                      display_name=u"published",
                      ispublic=True,
                      start=date,
                      end=endate)

        university1 = UniversityFactory(
            name=u"Université Paris Descartes",
            short_name=u"Université Paris Descartes")
        university2 = UniversityFactory(name=u"FÛN", short_name=u"FÛN")
        self.item1 = FunCourseFactory(key='fun/course1/item1',
                                      title='item1',
                                      show_in_catalog=False)
        self.item2 = FunCourseFactory(key='fun/course2/item2',
                                      title='item2',
                                      is_active=True,
                                      show_in_catalog=True,
                                      start_date=date,
                                      end_date=endate)
        self.item3 = FunCourseFactory(key='fun/course3/item3',
                                      title='item3',
                                      is_active=True,
                                      show_in_catalog=True,
                                      start_date=date,
                                      end_date=endate)
        CourseUniversityRelation.objects.create(university=university1,
                                                course=self.item2)
        CourseUniversityRelation.objects.create(university=university2,
                                                course=self.item3)
        CourseUniversityRelation.objects.create(university=university1,
                                                course=self.item3)
Ejemplo n.º 7
0
    def test_courses_manager_university_courses_public(self):
        """
        The "public" query appended to the query to get a university's courses
        should return only public courses for this university.
        """
        # Create 2 universities
        university1, university2 = UniversityFactory.create_batch(
            2, detail_page_enabled=True, is_obsolete=False, score=1)

        # Create public courses for each university and both
        course_u1, course_u2, course_u1u2 = CourseFactory.create_batch(
            3, show_in_catalog=True)
        # ... and link courses to university 1
        CourseUniversityRelationFactory(course=course_u1, university=university1)
        CourseUniversityRelationFactory(course=course_u2, university=university2)
        CourseUniversityRelationFactory(course=course_u1u2, university=university1)
        CourseUniversityRelationFactory(course=course_u1u2, university=university2)

        # Create private courses for each university and both
        course_pu1, course_pu2, course_pu1u2 = CourseFactory.create_batch(
            3, show_in_catalog=False)
        # ... and link courses to university 2
        CourseUniversityRelationFactory(course=course_pu1, university=university1)
        CourseUniversityRelationFactory(course=course_pu2, university=university2)
        CourseUniversityRelationFactory(course=course_pu1u2, university=university1)
        CourseUniversityRelationFactory(course=course_pu1u2, university=university2)

        self.assertEqual(set(university1.courses.all()), {
            course_u1, course_u1u2, course_pu1, course_pu1u2})
        self.assertEqual(set(university2.courses.all()), {
            course_u2, course_u1u2, course_pu2, course_pu1u2})

        self.assertEqual(set(university1.courses.public()), {course_u1, course_u1u2})
        self.assertEqual(set(university2.courses.public()), {course_u2, course_u1u2})
Ejemplo n.º 8
0
 def create_credentials(self):
     university = UniversityFactory(code="org")
     YoutubeAuth.objects.create(university=university,
                                client_id="clientid",
                                client_secret="clientsecret",
                                access_token="accesstoken",
                                refresh_token="refreshtoken")
Ejemplo n.º 9
0
    def setUp(self):
        super(BaseCourseList, self).setUp(create_user=False)
        self.user = User.objects.create(username='******', is_staff=True)
        self.user.set_password('password')
        self.user.save()
        self.backoffice_group, _created = Group.objects.get_or_create(
            name='fun_backoffice')
        self.user.groups.add(self.backoffice_group)
        UserProfile.objects.create(user=self.user)
        self.client.login(username=self.user.username, password='******')

        self.university = UniversityFactory.create()
        self.course1 = CourseFactory.create(number='001',
                                            display_name=u"unpublished",
                                            ispublic=False,
                                            org=self.university.code)

        CourseAboutFactory.create(course_id=self.course1.id,
                                  course_runtime=self.course1.runtime)

        self.course2 = CourseFactory.create(org=self.university.code,
                                            number='002',
                                            display_name=u"published",
                                            ispublic=True)
        self.list_url = reverse('backoffice:courses-list')
Ejemplo n.º 10
0
 def configure_course(self):
     """
     Make sure that all the right course models exist for generating the certificate.
     """
     fun_course = FunCourseFactory(key=unicode(self.course.id))
     fun_university = UniversityFactory.create()
     CourseUniversityRelationFactory(course=fun_course, university=fun_university)
Ejemplo n.º 11
0
 def configure_course(self):
     """
     Make sure that all the right course models exist for generating the certificate.
     """
     fun_course = FunCourseFactory(key=unicode(self.course.id))
     fun_university = UniversityFactory.create()
     CourseUniversityRelationFactory(course=fun_course, university=fun_university)
Ejemplo n.º 12
0
class UniversityAPITest(TestCase):
    def setUp(self):
        self.api_url = reverse('fun-universities-api:universities-list')
        self.user = UserFactory(username='******',
                                password='******')  # user with profile
        self.univ_1 = UniversityFactory(code='test-university-1')
        self.univ_2 = UniversityFactory(code='test-university-2')

    def login_as_admin(self):
        self.user.is_staff = True
        self.user.save()
        self.client.login(username='******', password='******')

    def test_course_list_api_response_loads(self):
        self.login_as_admin()
        response = self.client.get(self.api_url)
        data = json.loads(response.content)
        self.assertIn('results', data)

    def test_can_update_university_score_as_admin(self):
        self.login_as_admin()
        self.univ_1.score = 0
        self.univ_1.save()
        data = json.dumps({'score': 100})
        url = reverse('fun-universities-api:universities-detail',
                      args=[self.univ_1.id])
        response = self.client.put(url, data, content_type='application/json')
        response_data = json.loads(response.content)
        self.assertEqual(100, response_data['score'])

    def test_cannot_update_university_if_set_as_prevent_auto_update(self):
        self.login_as_admin()
        self.univ_1.prevent_auto_update = True
        self.univ_1.save()
        data = {'score': 100}
        url = reverse('fun-universities-api:universities-detail',
                      args=[self.univ_1.id])
        response = self.client.put(url, data)
        self.assertNotEqual(response.status_code, 200)

    def test_cannot_update_course_score_if_not_logged_in(self):
        self.client.logout()
        data = {'score': 100}
        url = reverse('fun-universities-api:universities-detail',
                      args=[self.univ_1.id])
        response = self.client.put(url, data)
        self.assertNotEqual(response.status_code, 200)
Ejemplo n.º 13
0
 def test_only_display_courses_for_a_specific_subject(self):
     subject = CourseSubjectFactory(slug='test-subject')
     UniversityFactory(slug='another-subject')
     self.active_1.subjects.add(subject)
     filter_data = {'subject': 'test-subject'}
     response = self.client.get(self.api_url, filter_data)
     self.assertContains(response, self.active_1.title)
     self.assertNotContains(response, self.active_2.title)
     filter_data = {'subject': 'another-subject'}
     response = self.client.get(self.api_url, filter_data)
     self.assertNotContains(response, self.active_1.title)
     self.assertNotContains(response, self.active_2.title)
Ejemplo n.º 14
0
    def init(self, is_superuser, university_code=None):
        self.backoffice_group, _created = Group.objects.get_or_create(name='fun_backoffice')
        self.user.is_staff = False
        self.user.is_superuser = is_superuser
        self.user.save()
        UserProfile.objects.create(user=self.user)
        self.course = CourseFactory.create(org=university_code)

        self.fun_course = FunCourseFactory.create(key=unicode(self.course.scope_ids.usage_id.course_key))
        if university_code:
            self.university = UniversityFactory.create(slug=university_code, code=university_code)
            CourseUniversityRelationFactory(course=self.fun_course, university=self.university)
Ejemplo n.º 15
0
 def test_subjet_score_only_available_if_logged_in_as_admin(self):
     subject = CourseSubjectFactory(slug='test-subject')
     UniversityFactory(slug='another-subject')
     self.active_1.subjects.add(subject)
     filter_data = {'subject': 'test-subject'}
     self.login_as_admin()
     response = self.client.get(self.api_url, filter_data)
     response_data = json.loads(response.content)
     self.assertIn('score', response_data['results'][0]['subjects'][0])
     self.client.logout()
     response = self.client.get(self.api_url, filter_data)
     response_data = json.loads(response.content)
     self.assertNotIn('score', response_data['results'][0]['subjects'][0])
Ejemplo n.º 16
0
 def test_university_score_available_only_if_logged_in_as_admin(self):
     university = UniversityFactory(code='test-university', score=10)
     CourseUniversityRelation.objects.create(
         course=self.active_1, university=university
     )
     filter_data = {'university': 'test-university'}
     self.login_as_admin()
     response = self.client.get(self.api_url, filter_data)
     response_data = json.loads(response.content)
     self.assertIn('score', response_data['results'][0]['universities'][0])
     self.client.logout()
     response = self.client.get(self.api_url, filter_data)
     response_data = json.loads(response.content)
     self.assertNotIn('score', response_data['results'][0]['universities'][0])
Ejemplo n.º 17
0
    def init(self, is_superuser, university_code=None):
        self.backoffice_group, _created = Group.objects.get_or_create(
            name='fun_backoffice')
        self.user.is_staff = False
        self.user.is_superuser = is_superuser
        self.user.save()
        UserProfile.objects.create(user=self.user)
        self.course = CourseFactory.create(org=university_code)

        self.fun_course = FunCourseFactory.create(
            key=unicode(self.course.scope_ids.usage_id.course_key))
        if university_code:
            self.university = UniversityFactory.create(slug=university_code,
                                                       code=university_code)
            CourseUniversityRelationFactory(course=self.fun_course,
                                            university=self.university)
Ejemplo n.º 18
0
    def test_change_and_regenerate_grade(self):
        # Proper university and course objects need to be created in order to
        # generate the pdf files
        fun_course = FunCourseFactory(key=unicode(self.course1.id))
        fun_university = UniversityFactory.create()
        CourseUniversityRelationFactory(course=fun_course, university=fun_university)
        CourseEnrollmentFactory(course_id=self.course1.id, user=self.user2)

        generated_certificate = self._create_certificate(self.course1, 0.8)
        certificate = self._change_certificate_grade(generated_certificate, 0.9, self.user2, True)
        self.assertEqual(certificate.grade, '0.9')
        # GeneratedCertificateFactory do not create pdf certificate so download_url is blank,
        # call to _change_certificate_grade with regenerate=True create pdf and set download_url
        cert_url = certificate.download_url
        self.assertNotEqual(generated_certificate.download_url, cert_url)
        # Regenerate certificate, url should remain the same
        certificate = self._change_certificate_grade(generated_certificate, 0.99, self.user2, True)
        self.assertEqual(cert_url, certificate.download_url)
Ejemplo n.º 19
0
    def setUp(self):
        super(BaseCourseList, self).setUp(create_user=False)
        self.user = User.objects.create(username='******', is_staff=True)
        self.user.set_password('password')
        self.user.save()
        self.backoffice_group, _created = Group.objects.get_or_create(name='fun_backoffice')
        self.user.groups.add(self.backoffice_group)
        UserProfile.objects.create(user=self.user)
        self.client.login(username=self.user.username, password='******')

        self.university = UniversityFactory.create()
        self.course1 = CourseFactory.create(number='001', display_name=u"unpublished",
                                            ispublic=False, org=self.university.code)

        CourseAboutFactory.create(course_id=self.course1.id,
                                  course_runtime=self.course1.runtime)

        self.course2 = CourseFactory.create(org=self.university.code, number='002',
                             display_name=u"published", ispublic=True)
        self.list_url = reverse('backoffice:courses-list')
Ejemplo n.º 20
0
 def setUp(self):
     super(AbstractPaymentTest, self).setUp()
     self.user = User.objects.create(username='******',
                                     first_name='first_name',
                                     last_name='last_name',
                                     email='*****@*****.**',
                                     is_active=True)
     self.user.set_password('test')
     self.user.save()
     UserProfile.objects.create(user=self.user,
                                language='fr',
                                name=u"Robert Cash")
     self.client.login(username=self.user.username, password='******')
     self.course = Course.objects.create(
         key='FUN/0002/session1',
         title=u"course title",
     )
     self.university = UniversityFactory(name=u"FÛN")
     CourseUniversityRelation.objects.create(course=self.course,
                                             university=self.university)
     self.api_response = ecommerce_order_api_response(self.course.key)
Ejemplo n.º 21
0
 def setUp(self):
     self.course_key_string = "Org/Course/Run"
     UniversityFactory(code="Org")
Ejemplo n.º 22
0
 def setUp(self):
     self.course_key_string = "Org/Course/Run"
     university = UniversityFactory(code="Org")
     models.VideofrontAuth.objects.create(university=university,
                                          token="abcdefgh")
Ejemplo n.º 23
0
 def setUp(self):
     self.api_url = reverse('fun-universities-api:universities-list')
     self.user = UserFactory(username='******',
                             password='******')  # user with profile
     self.univ_1 = UniversityFactory(code='test-university-1')
     self.univ_2 = UniversityFactory(code='test-university-2')