Beispiel #1
0
    def set_quotas(self, request, **kwargs):
        if not request.user.is_staff:
            raise exceptions.PermissionDenied()

        instance = self.get_object()
        if instance.state != core_models.SynchronizationStates.IN_SYNC:
            return Response(
                {
                    'detail':
                    'Cloud project membership must be in sync state for setting quotas'
                },
                status=status.HTTP_409_CONFLICT)

        serializer = serializers.CloudProjectMembershipQuotaSerializer(
            data=request.data)
        serializer.is_valid(raise_exception=True)

        instance.schedule_syncing()
        instance.save()

        tasks.push_cloud_membership_quotas.delay(instance.pk,
                                                 quotas=serializer.data)

        return Response({'status': 'Quota update was scheduled'},
                        status=status.HTTP_202_ACCEPTED)
 def test_cloud_project_membership_quota_serializer_ignores_unsupported_fields(
         self):
     data = {
         'some_strange_quota_name': 1,
     }
     serializer = serializers.CloudProjectMembershipQuotaSerializer(
         data=data)
     self.assertTrue(serializer.is_valid())
     self.assertTrue('some_strange_quota_name' not in serializer.data)
 def test_cloud_project_membership_quota_serializer_fails_on_symbolic_values(
         self):
     data = {
         'max_instances': 'lalala',
         'vcpu': 'lalala',
         'storage': 'lalala',
         'ram': 'lalala',
     }
     serializer = serializers.CloudProjectMembershipQuotaSerializer(
         data=data)
     self.assertFalse(serializer.is_valid())
 def test_cloud_project_membership_quota_serializer_accepts_positive_values(
         self):
     data = {
         'max_instances': 12,
         'vcpu': 20,
         'storage': 40 * 1024,
         'ram': 20 * 1024,
     }
     serializer = serializers.CloudProjectMembershipQuotaSerializer(
         data=data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(data, serializer.data)