Esempio n. 1
0
    def test_unsuccessful_recipe_creation_with_bad_data_type(self):
        '''Tests successfully processing an ingest that triggers recipe creation.'''

        # Set up data
        configuration = {
            'version': '1.0',
            'trigger': {
                'media_type': 'text/plain',
                'data_types': ['test_file_type', 'bad_data_type'],
            },
            'create': {
                'recipes': [{
                    'recipe_type': {
                        'name': self.recipe_type_1.name,
                        'version': self.recipe_type_1.version,
                    },
                    'file_input_name': self.input_name,
                    'workspace_name': self.workspace.name,
                }],
            },
        }
        rule = IngestTriggerRule(configuration)
        rule.save_to_db()

        # Call method to test
        rule.process_ingest(self.ingest, self.source_file.id)

        # Check results...ensure job is not queued
        queue_1 = Queue.objects.filter(job_type=self.job_type_2.id)
        self.assertEqual(len(queue_1), 0)
Esempio n. 2
0
    def test_successful_job_creation(self):
        '''Tests successfully processing an ingest that triggers job creation.'''

        # Set up data
        configuration = {
            'version': '1.0',
            'trigger': {
                'media_type': 'text/plain',
            },
            'create': {
                'jobs': [{
                    'job_type': {
                        'name': self.job_type_1.name,
                        'version': self.job_type_1.version,
                    },
                    'file_input_name': self.input_name,
                }, {
                    'job_type': {
                        'name': self.job_type_2.name,
                        'version': self.job_type_2.version,
                    },
                    'file_input_name': self.input_name,
                    'workspace_name': self.workspace.name,
                }],
            },
        }
        rule = IngestTriggerRule(configuration)
        rule.save_to_db()

        # Call method to test
        rule.process_ingest(self.ingest, self.source_file.id)

        # Check results
        queue_1 = Queue.objects.get(job_type=self.job_type_1.id)
        job_exe_1 = JobExecution.objects.select_related().get(pk=queue_1.job_exe_id)
        job_1 = job_exe_1.job
        self.assertEqual(job_1.data['input_data'][0]['name'], self.input_name)
        self.assertEqual(job_1.data['input_data'][0]['file_id'], self.source_file.id)
        event_1 = TriggerEvent.objects.get(pk=job_1.event.id)
        self.assertEqual(event_1.occurred, self.when_ingested)

        queue_2 = Queue.objects.get(job_type=self.job_type_2.id)
        job_exe_2 = JobExecution.objects.select_related().get(pk=queue_2.job_exe_id)
        job_2 = job_exe_2.job
        self.assertEqual(job_2.data['input_data'][0]['name'], self.input_name)
        self.assertEqual(job_2.data['input_data'][0]['file_id'], self.source_file.id)
        self.assertEqual(job_2.data['output_data'][0]['name'], self.output_name)
        self.assertEqual(job_2.data['output_data'][0]['workspace_id'], self.workspace.id)
        event_2 = TriggerEvent.objects.get(pk=job_2.event.id)
        self.assertEqual(event_2.occurred, self.when_ingested)