def test_list_links(self, client, org_name, status_code, expected_count): org = Organization.objects.get(name=org_name) course = CourseOverviewFactory.create() OrganizationCourse.objects.create(course_id=str(course.id), organization=org) GroupCourseFactory.create_batch(3, group__organization=org, course=course) response = client.get(self.url) assert response.status_code == HTTP_200_OK, response.content results = response.json()['results'] assert len(results) == expected_count
def test_allow_members(self, default_has_access): """ Members have access to courses. Via the `Membership` whether it's automatic via `MembershipRule` or manually assigned. """ group = CourseAccessGroupFactory.create() GroupCourseFactory.create(course=self.course, group=group) MembershipFactory.create(user=self.user, group=group) assert user_has_access(self.user, self.course, default_has_access, {}) == default_has_access
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
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.'
def test_delete_link(self, client, org_name, status_code, expected_post_delete_count): """ Ensure link deletion is possible via the API. """ org = Organization.objects.get(name=org_name) link = GroupCourseFactory.create(group__organization=org) response = client.delete('/group-courses/{}/'.format(link.id)) assert response.status_code == status_code, response.content assert GroupCourse.objects.count() == expected_post_delete_count
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])
def test_one_link(self, client, org_name, status_code, skip_response_check): org = Organization.objects.get(name=org_name) link = GroupCourseFactory.create(group__organization=org) OrganizationCourse.objects.create(course_id=str(link.course.id), organization=org) response = client.get('/group-courses/{}/'.format(link.id)) assert response.status_code == status_code, response.content result = response.json() assert skip_response_check or (result == { 'id': link.id, 'course': { 'id': str(link.course.id), 'name': link.course.display_name_with_default, }, 'group': { 'id': link.group.id, 'name': link.group.name, }, }), 'Verify the serializer results.'