Example #1
0
    def test_successful_recipe_creation(self):
        '''Tests successfully processing a parse that triggers recipe creation.'''

        # Set up data
        configuration = {
            'version': '1.0',
            'trigger': {
                'media_type': 'text/plain',
            },
            '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 = ParseTriggerRule(configuration)
        rule.save_to_db()

        # Call method to test
        rule.process_parse(self.source_file)

        # Check results...ensure first job is queued
        queue_1 = Queue.objects.get(job_type=self.job_type_2.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)
        self.assertEqual(job_1.data['output_data'][0]['name'], self.output_name)
        self.assertEqual(job_1.data['output_data'][0]['workspace_id'], self.workspace.id)
Example #2
0
    def test_valid_feature_with_parse_rule(self):
        '''Tests calling save_parse_results with valid arguments and parse rules in place'''

        # Setup parse rule
        configuration = {u'version': u'1.0',
                         u'trigger': {u'media_type': u'text/plain', u'data_types': [u'type']},
                         u'create': {u'jobs': []}}
        rule = ParseTriggerRule(configuration)
        rule.save_to_db()

        # Call method to test
        SourceFile.objects.save_parse_results(self.src_file.id, FEATURE_GEOJSON, self.started, self.ended, [], None, None)
        
        # Ensure there's an event for the parse
        evt = TriggerEvent.objects.first()
        self.assertEqual(evt.description[u'version'], u'1.0')
        self.assertEqual(evt.description[u'file_name'], u'text.txt')