コード例 #1
0
    def members(self, request, *args, **kwargs):
        organization = self.get_object()
        data = merge_dicts(request.data, request.query_params.dict(),
                           {'organization': organization.pk})

        if request.method == 'POST' and 'username' not in data:
            data['username'] = None

        if request.method == 'DELETE':
            data['remove'] = True

        if request.method == 'PUT' and 'role' not in data:
            data['role'] = None

        serializer = OrganizationMemberSerializer(data=data)

        username = kwargs.get('user')
        if serializer.is_valid():
            serializer.save()
            organization = serializer.validated_data.get('organization')
            data = OrganizationSerializer(organization,
                                          context={
                                              'request': request
                                          }).data
            cache.set(f'{ORG_PROFILE_CACHE}{username}', data)

        else:
            return Response(data=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)

        self.etag_data = json.dumps(data)
        resp_status = status.HTTP_201_CREATED if request.method == 'POST' \
            else status.HTTP_200_OK

        return Response(status=resp_status, data=serializer.data())
class TestOrganizationSerializer(TransactionTestCase):
    def setUp(self):
        self.serializer = OrganizationSerializer()

    def test_get_org_permissions_none(self):
        perms = self.serializer.get_org_permissions(None)
        self.assertEqual(perms, [])
コード例 #3
0
class TestOrganizationSerializer(TransactionTestCase):

    def setUp(self):
        self.serializer = OrganizationSerializer()

    def test_get_org_permissions_none(self):
        perms = self.serializer.get_org_permissions(None)
        self.assertEqual(perms, [])
コード例 #4
0
 def setUp(self):
     self.serializer = OrganizationSerializer()
 def setUp(self):
     self.serializer = OrganizationSerializer()