Esempio n. 1
0
    def _create_v5(self, request):
        """The v5 version for creating batches

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        recipe_type_id = rest_util.parse_int(request, 'recipe_type_id')
        title = rest_util.parse_string(request, 'title', required=False)
        description = rest_util.parse_string(request,
                                             'description',
                                             required=False)

        # Make sure the recipe type exists
        try:
            recipe_type = RecipeType.objects.get(pk=recipe_type_id)
        except RecipeType.DoesNotExist:
            raise BadParameter('Unknown recipe type: %i' % recipe_type_id)

        # Validate the batch definition
        definition_dict = rest_util.parse_dict(request, 'definition')
        definition = None
        try:
            if definition_dict:
                definition = OldBatchDefinition(definition_dict)
                definition.validate(recipe_type)
        except InvalidDefinition as ex:
            raise BadParameter('Batch definition invalid: %s' % unicode(ex))

        # Create the batch
        batch = Batch.objects.create_batch_old(recipe_type,
                                               definition,
                                               title=title,
                                               description=description)

        # Fetch the full batch with details
        try:
            batch = Batch.objects.get_details_v5(batch.id)
        except Batch.DoesNotExist:
            raise Http404

        url = reverse('batch_details_view', args=[batch.id], request=request)
        serializer = BatchDetailsSerializerV5(batch)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=dict(location=url))
Esempio n. 2
0
    def test_minimum(self):
        """Tests the bare minimum schema definition"""

        definition = {
            'version': '1.0',
        }

        # No exception means success
        BatchDefinition(definition)
Esempio n. 3
0
    def test_trigger_default(self):
        """Tests defining the current recipe type trigger should be used."""

        definition = {
            'version': '1.0',
            'trigger_rule': True,
        }

        # No exception means success
        BatchDefinition(definition)
Esempio n. 4
0
    def test_priority(self):
        """Tests defining override priority."""

        definition = {
            'version': '1.0',
            'priority': 1111,
        }

        # No exception means success
        BatchDefinition(definition)
Esempio n. 5
0
    def test_all_job(self):
        """Tests defining all jobs"""

        definition = {
            'version': '1.0',
            'all_jobs': True,
        }

        # No exception means success
        BatchDefinition(definition)
Esempio n. 6
0
    def test_job_names(self):
        """Tests defining a list of job names"""

        definition = {
            'version': '1.0',
            'job_names': [
                'job1',
                'job2',
            ],
        }

        # No exception means success
        BatchDefinition(definition)
Esempio n. 7
0
    def test_date_range_ended(self):
        """Tests defining a date range with only an end date"""

        definition = {
            'version': '1.0',
            'date_range': {
                'ended': '2016-12-31T00:00:00.000Z',
            },
        }

        # No exception means success
        batch_def = BatchDefinition(definition)
        self.assertEqual(batch_def.ended, datetime.datetime(2016, 12, 31, tzinfo=utc))
Esempio n. 8
0
    def _post_v5(self, request):
        """The v5 version for validating a new batch

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        recipe_type_id = rest_util.parse_int(request, 'recipe_type_id')

        # Make sure the recipe type exists
        try:
            recipe_type = RecipeType.objects.get(pk=recipe_type_id)
        except RecipeType.DoesNotExist:
            raise BadParameter('Unknown recipe type: %i' % recipe_type_id)

        # Validate the batch definition
        definition_dict = rest_util.parse_dict(request, 'definition')
        definition = None
        warnings = []
        try:
            if definition_dict:
                definition = OldBatchDefinition(definition_dict)
                warnings = definition.validate(recipe_type)
        except InvalidDefinition as ex:
            raise BadParameter('Batch definition invalid: %s' % unicode(ex))

        # Get a rough estimate of how many recipes/files will be affected
        old_recipes = Batch.objects.get_matched_recipes(
            recipe_type, definition)
        old_files = Batch.objects.get_matched_files(recipe_type, definition)

        return Response({
            'recipe_count': old_recipes.count(),
            'file_count': old_files.count(),
            'warnings': warnings,
        })
Esempio n. 9
0
    def test_trigger_custom(self):
        """Tests defining a custom trigger to use."""

        definition = {
            'version': '1.0',
            'trigger_rule':   {
                'condition': {
                    'media_type': 'text/plain',
                    'data_types': ['foo', 'bar'],
                },
                'data': {
                    'input_data_name': 'my_file',
                    'workspace_name': 'my_workspace',
                },
            },
        }

        # No exception means success
        BatchDefinition(definition)