Example #1
0
 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
Example #2
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])
Example #3
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
Example #4
0
 def test_add_link(self, client, group_org, course_org, status_code, expected_count, check_new_link):
     assert not GroupCourse.objects.count()
     org = Organization.objects.get(name=group_org)
     group = CourseAccessGroupFactory.create(organization=org)
     course = CourseOverviewFactory.create()
     OrganizationCourse.objects.create(
         course_id=str(course.id),
         organization=Organization.objects.get(name=course_org),
     )
     response = client.post(self.url, {
         'group': group.id,
         'course': str(course.id),
     })
     assert GroupCourse.objects.count() == expected_count
     assert response.status_code == status_code, response.content
     if check_new_link:
         new_link = GroupCourse.objects.get()
         assert new_link.group.id == group.id
         assert new_link.course.id == course.id
Example #5
0
 def test_add_flag(self, client, org_name, status_code, expected_count, check_new_flag, message):
     """
     Check API POST to add new PublicCourse flag.
     """
     assert not PublicCourse.objects.count()
     org = Organization.objects.get(name=org_name)
     course = CourseOverviewFactory.create()
     OrganizationCourse.objects.create(
         course_id=str(course.id),
         organization=org,
     )
     response = client.post(self.url, {
         'course': str(course.id),
     })
     assert PublicCourse.objects.count() == expected_count, message
     assert response.status_code == status_code, response.content
     if check_new_flag:
         new_flag = PublicCourse.objects.get()
         assert new_flag.course.id == course.id
Example #6
0
 def test_one_course_empty_info(self, client, org_name, status_code, skip_response_check):
     """
     Test JSON format for course without course access groups info.
     """
     org = Organization.objects.get(name=org_name)
     course = CourseOverviewFactory.create()
     OrganizationCourse.objects.create(
         course_id=str(course.id),
         organization=org,
     )
     response = client.get('{}{}/'.format(self.url, course.id))
     assert response.status_code == status_code, response.content
     result = response.json()
     assert skip_response_check or (result == {
         'id': str(course.id),
         'name': course.display_name,
         'public_status': {
             'is_public': False,
         },
         'group_links': [],
     }), 'Verify the serializer results.'
Example #7
0
 def setup(self):
     """
     Create test model fixtures.
     """
     self.user = UserFactory.create()
     self.course = CourseOverviewFactory.create()
Example #8
0
 def setup(self):
     self.my_course = CourseOverviewFactory.create()