def test_with_course_descriptor(self):
        """
        Test when CourseDescriptorWithMixins is passed instead of CourseOverview.

        Warning: This is a somewhat complex test case due to the inherent complexity with CourseDescriptorWithMixins
                 class in Open edX. If it breaks and it took a lot of time to fix, please consider removing it
                 and relying on manual testing instead.
        """
        PublicCourseFactory.create(course=self.my_course)
        course_descriptor = Mock()  # Anything other than CourseOverview
        course_descriptor.id = self.my_course.id

        with patch('django.db.models.sql.query.check_rel_lookup_compatibility', return_value=False):
            assert is_course_with_public_access(course=course_descriptor)
Exemple #2
0
    def test_allow_public_courses(self, default_has_access):
        """
        Public courses should be allowed to non-members.

        Via the `PublicCourse` model.
        """
        org = OrganizationFactory.create()
        OrganizationCourse.objects.create(course_id=str(self.course.id),
                                          organization=org)
        UserOrganizationMapping.objects.create(
            user=self.user,
            organization=org,
        )
        PublicCourseFactory.create(course=self.course)
        assert user_has_access(self.user, self.course, default_has_access,
                               {}) == default_has_access
Exemple #3
0
 def test_one_course_full_info(self, client):
     """
     Test JSON format for course with course access groups info.
     """
     public_course = PublicCourseFactory.create()
     course = public_course.course
     OrganizationCourse.objects.create(
         course_id=text_type(course.id),
         organization=self.my_org,
     )
     group_course = GroupCourseFactory.create(
         course=course, group__organization=self.my_org)
     response = client.get('{}{}/'.format(self.url, course.id))
     assert response.status_code == HTTP_200_OK, response.content
     result = response.json()
     assert result == {
         'id':
         text_type(course.id),
         'name':
         course.display_name,
         'public_status': {
             'id': public_course.id,
             'is_public': True,
         },
         'group_links': [{
             'id': group_course.id,
             'group': {
                 'id': group_course.group.id,
                 'name': group_course.group.name,
             }
         }],
     }, 'Verify the serializer results.'
Exemple #4
0
 def users_setup(self):
     public = PublicCourseFactory.create(course__display_name=self.public_course).course
     private = CourseOverviewFactory.create(display_name=self.private_course)
     link = GroupCourseFactory.create(
         course__display_name=self.group_course,
         group__organization=self.my_org,
     )
     in_group = link.course
     OrganizationCourseFactory.create_for(self.my_org, courses=[public, private, in_group])
Exemple #5
0
 def test_delete_flag(self, client, org_name, status_code, expected_post_delete_count):
     """
     Ensure PublicCourse flag deletion is possible via the API.
     """
     org = Organization.objects.get(name=org_name)
     flag = PublicCourseFactory.create()
     OrganizationCourse.objects.create(
         course_id=str(flag.course.id),
         organization=org,
     )
     response = client.delete('/public-courses/{}/'.format(flag.id))
     assert response.status_code == status_code, response.content
     assert PublicCourse.objects.count() == expected_post_delete_count
Exemple #6
0
 def test_list_courses(self, client, org_name, expected_count):
     org = Organization.objects.get(name=org_name)
     private_courses = CourseOverviewFactory.create_batch(2)
     GroupCourseFactory.create_batch(2, course=private_courses[0], group__organization=org)
     public_courses = [p.course for p in PublicCourseFactory.create_batch(3)]
     OrganizationCourseFactory.create_for(
         org,
         courses=private_courses + public_courses,
     )
     response = client.get(self.url)
     results = response.json()['results']
     assert response.status_code == HTTP_200_OK, response.content
     assert len(results) == expected_count
Exemple #7
0
 def test_list_flags(self, client, org_name, status_code, expected_count):
     """
     List flags correctly with permissions checks.
     """
     org = Organization.objects.get(name=org_name)
     courses = [flag.course for flag in PublicCourseFactory.create_batch(3)]
     _course_org_links = [  # noqa: F841
         OrganizationCourse.objects.create(course_id=str(course.id), organization=org)
         for course in courses
     ]
     response = client.get(self.url)
     assert response.status_code == HTTP_200_OK, response.content
     results = response.json()['results']
     assert len(results) == expected_count
Exemple #8
0
 def test_one_flag(self, client, org_name, status_code, skip_response_check):
     """
     Check serialized PublicCourse flag.
     """
     org = Organization.objects.get(name=org_name)
     flag = PublicCourseFactory.create()
     OrganizationCourse.objects.create(course_id=str(flag.course.id), organization=org)
     response = client.get('/public-courses/{}/'.format(flag.id))
     assert response.status_code == status_code, response.content
     result = response.json()
     assert skip_response_check or (result == {
         'id': flag.id,
         'course': {
             'id': str(flag.course.id),
             'name': flag.course.display_name_with_default,
         },
     }), 'Verify the serializer results.'
Exemple #9
0
 def test_access_for_public_courses(self):
     PublicCourseFactory.create(course=self.my_course)
     assert is_course_with_public_access(self.my_course)