コード例 #1
0
    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)
コード例 #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
コード例 #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.'
コード例 #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])
コード例 #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
コード例 #6
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.'
コード例 #7
0
 def test_access_for_public_courses(self):
     PublicCourseFactory.create(course=self.my_course)
     assert is_course_with_public_access(self.my_course)