Пример #1
0
    def test_add_user_to_org(self):
        user = User.objects.create(username='******',
                                   email='*****@*****.**',
                                   last_name='One',
                                   first_name='User')
        userprofile = UserProfile.objects.create(user=user,
                                                 mnemonic='user1',
                                                 created_by='user1',
                                                 updated_by='user1')
        org = Organization.objects.create(name='org1',
                                          mnemonic='org1',
                                          created_by='user1',
                                          updated_by='user1')

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)

        add_user_to_org(userprofile, org)

        self.assertEquals(1, userprofile.orgs)
        self.assertEquals(1, org.num_members)

        self.assertEquals(org.id, userprofile.organizations[0])
        self.assertEquals(userprofile.id, org.members[0])

        remove_user_from_org(userprofile, org)

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)
Пример #2
0
    def test_add_user_to_org(self):
        user = User.objects.create(
            username='******',
            email='*****@*****.**',
            last_name='One',
            first_name='User'
        )
        userprofile = UserProfile.objects.create(user=user, mnemonic='user1', created_by='user1', updated_by='user1')
        org = Organization.objects.create(name='org1', mnemonic='org1', created_by='user1', updated_by='user1')

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)

        add_user_to_org(userprofile, org)

        self.assertEquals(1, userprofile.orgs)
        self.assertEquals(1, org.num_members)

        self.assertEquals(org.id, userprofile.organizations[0])
        self.assertEquals(userprofile.id, org.members[0])

        remove_user_from_org(userprofile, org)

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)
Пример #3
0
 def delete(self, request, *args, **kwargs):
     if not request.user.is_staff and not self.user_in_org:
         return HttpResponse(status=status.HTTP_403_FORBIDDEN)
     remove_user_from_org(self.userprofile, self.organization)
     return HttpResponse(status=status.HTTP_204_NO_CONTENT)
Пример #4
0
 def delete(self, request, *args, **kwargs):
     if not request.user.is_staff and not self.user_in_org:
         return HttpResponse(status=status.HTTP_403_FORBIDDEN)
     remove_user_from_org(self.userprofile, self.organization)
     return HttpResponse(status=status.HTTP_204_NO_CONTENT)