Esempio n. 1
0
 def test_delete_group(self, client, org_name, status_code,
                       expected_post_delete_count):
     org = Organization.objects.get(name=org_name)
     group = CourseAccessGroupFactory.create(organization=org)
     response = client.delete('/course-access-groups/{}/'.format(group.id))
     assert response.status_code == status_code, response.content
     assert CourseAccessGroup.objects.count() == expected_post_delete_count
Esempio n. 2
0
    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
Esempio n. 3
0
 def test_one_group(self, client, org_name, status_code, skip_response_check):
     org = Organization.objects.get(name=org_name)
     group = CourseAccessGroupFactory.create(organization=org)
     response = client.get('/course-access-groups/{}/'.format(group.id))
     results = response.json()
     assert response.status_code == status_code, response.content
     assert skip_response_check or (results == {
         'id': group.id,
         'name': group.name,
         'description': group.description,
     }), 'Verify the serializer results.'
Esempio n. 4
0
    def test_edit_group(self, client, org_name, status_code, skip_response_check):
        org = Organization.objects.get(name=org_name)
        group_before = CourseAccessGroupFactory.create(organization=org)
        url = '/course-access-groups/{}/'.format(group_before.id)
        response = client.patch(url, content_type='application/json', data=json.dumps({
            'name': 'Awesome Group',
        }))
        assert response.status_code == status_code, response.content

        if not skip_response_check:
            group_after = CourseAccessGroup.objects.get()
            assert group_after.name == 'Awesome Group'
Esempio n. 5
0
 def test_add_rule(self, client, org_name, status_code, expected_count, check_new_rule):
     assert not MembershipRule.objects.count()
     org = Organization.objects.get(name=org_name)
     group = CourseAccessGroupFactory.create(organization=org)
     rule_domain = 'example.org'
     response = client.post(self.url, {
         'group': group.id,
         'name': 'Community assignment',
         'domain': rule_domain,
     })
     assert response.status_code == status_code, response.content
     assert MembershipRule.objects.count() == expected_count
     if check_new_rule:
         new_rule = MembershipRule.objects.get()
         assert new_rule.group.id == group.id
         assert new_rule.domain == rule_domain
         assert new_rule.name == 'Community assignment'
Esempio n. 6
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
    def test_simple_match(self, email, should_enroll):
        """
        Basic test for membership rules.
        """
        assert not Membership.objects.count()
        user = UserFactory.create(is_active=True, email=email)
        group = CourseAccessGroupFactory.create()
        UserOrganizationMapping.objects.create(id=500,
                                               user=user,
                                               organization=group.organization)
        MembershipRule.objects.create(name='Something',
                                      domain='known_site.com',
                                      group=group)

        on_learner_account_activated(self.__class__, user)
        membership = Membership.objects.filter(user=user).first()

        assert bool(membership) == should_enroll
        assert not membership or (membership.group == group)
Esempio n. 8
0
 def test_add_membership(self, client, group_org, user_org, status_code,
                         expected_count, check_new_membership):
     assert not Membership.objects.count()
     group = CourseAccessGroupFactory.create(
         organization=Organization.objects.get(name=group_org), )
     user = UserFactory.create()
     UserOrganizationMapping.objects.create(
         organization=Organization.objects.get(name=user_org),
         user=user,
     )
     response = client.post(self.url, {
         'group': group.id,
         'user': user.id,
     })
     assert response.status_code == status_code, response.content
     assert Membership.objects.count() == expected_count
     if check_new_membership:
         new_membership = Membership.objects.get()
         assert new_membership.group.id == group.id
         assert new_membership.user.id == user.id
Esempio n. 9
0
 def test_list_groups(self, client, org_name, status_code, expected_count):
     org = Organization.objects.get(name=org_name)
     CourseAccessGroupFactory.create_batch(3, organization=org)
     response = client.get(self.url)
     assert response.status_code == status_code, response.content
     assert response.json()['count'] == expected_count