def test_list_memberships(self, client, org_name, expected_count): org = Organization.objects.get(name=org_name) MembershipFactory.create_batch(3, group__organization=org) response = client.get(self.url) results = response.json()['results'] assert response.status_code == HTTP_200_OK, response.content assert len(results) == expected_count
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], )
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_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.'
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
def test_list_users(self, client, org_name, expected_count): org = Organization.objects.get(name=org_name) # Two users without memberships without_memberships = UserFactory.create_batch(2) # Three additional users with memberships with_memberships = [m.user for m in MembershipFactory.create_batch(3, group__organization=org)] UserOrganizationMappingFactory.create_for( org, users=without_memberships + with_memberships, ) 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_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.'