Exemple #1
0
 def users_setup(self):
     omar = UserFactory.create(email=self.non_member_email)
     user1 = MembershipFactory.create(user__email=self.member_email).user
     user2 = MembershipFactory.create().user
     UserOrganizationMappingFactory.create_for(
         self.my_org,
         users=[omar, user1, user2],
     )
Exemple #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
Exemple #3
0
 def test_one_user_with_membership(self, client):
     """
     Test JSON format for a user with membership.
     """
     user = UserFactory.create()
     UserOrganizationMappingFactory.create(user=user,
                                           organization=self.my_org)
     membership = MembershipFactory.create(group__organization=self.my_org,
                                           user=user)
     response = client.get('{}{}/'.format(self.url, user.id))
     assert response.status_code == HTTP_200_OK, response.content
     result = response.json()
     assert result == {
         'id': user.id,
         'email': user.email,
         'name': user.profile.name,
         'username': user.username,
         'membership': {
             'id': membership.id,
             'group': {
                 'id': membership.group.id,
                 'name': membership.group.name,
             }
         },
     }, 'Verify the serializer results.'
Exemple #4
0
 def test_delete_membership(self, client, org_name, status_code, expected_post_delete_count):
     """
     Ensure membership deletion is possible via the API.
     """
     org = Organization.objects.get(name=org_name)
     membership = MembershipFactory.create(group__organization=org)
     UserOrganizationMapping.objects.create(user=membership.user, organization=org)
     response = client.delete('/memberships/{}/'.format(membership.id))
     assert response.status_code == status_code, response.content
     assert Membership.objects.count() == expected_post_delete_count
Exemple #5
0
 def test_one_membership(self, client, group_org, status_code, skip_response_check):
     org = Organization.objects.get(name=group_org)
     membership = MembershipFactory.create(group__organization=org)
     response = client.get('/memberships/{}/'.format(membership.id))
     assert response.status_code == status_code, response.content
     result = response.json()
     assert skip_response_check or (result == {
         'id': membership.id,
         'user': {
             'id': membership.user.id,
             'email': membership.user.email,
             'username': membership.user.username,
         },
         'group': {
             'id': membership.group.id,
             'name': membership.group.name,
         },
     }), 'Verify the serializer results.'