Ejemplo n.º 1
0
    def _bulk_action_setup(self):
        metadata_schema = ckanext_factories.MetadataSchema()
        self.workflow_transition_1 = ckanext_factories.WorkflowTransition(
            from_state_id='')
        self.workflow_transition_2 = ckanext_factories.WorkflowTransition(
            from_state_id=self.workflow_transition_1['to_state_id'])
        self.metadata_collection = ckanext_factories.MetadataCollection()
        self.metadata_records = [
            ckanext_factories.MetadataRecord(
                owner_org=self.metadata_collection['organization_id'],
                metadata_collection_id=self.metadata_collection['id'],
                metadata_standard_id=metadata_schema['metadata_standard_id'])
            for _ in range(3)
        ]

        # modify the middle record; this should not affect processing of the surrounding records
        self.test_action('metadata_record_validate',
                         id=self.metadata_records[1]['id'])
        self.test_action(
            'metadata_record_workflow_state_override',
            id=self.metadata_records[1]['id'],
            workflow_state_id=self.workflow_transition_1['to_state_id'])
        assert_package_has_extra(self.metadata_records[1]['id'], 'validated',
                                 True)
        assert_package_has_extra(self.metadata_records[1]['id'],
                                 'workflow_state_id',
                                 self.workflow_transition_1['to_state_id'])
    def test_create_invalid_duplicate(self):
        workflow_transition = ckanext_factories.WorkflowTransition()
        result, obj = self.test_action(
            'workflow_transition_create',
            should_error=True,
            from_state_id=workflow_transition['from_state_id'],
            to_state_id=workflow_transition['to_state_id'])
        assert_error(result, '__after', 'Unique constraint violation')

        workflow_transition = ckanext_factories.WorkflowTransition(
            from_state_id='')
        result, obj = self.test_action(
            'workflow_transition_create',
            should_error=True,
            from_state_id='',
            to_state_id=workflow_transition['to_state_id'])
        assert_error(result, '__after', 'Unique constraint violation')
 def test_update_invalid(self):
     workflow_transition = ckanext_factories.WorkflowTransition()
     result, obj = self.test_action('workflow_transition_update',
                                    should_error=True,
                                    id=workflow_transition['id'])
     assert_error(
         result, 'message',
         'A workflow transition cannot be updated. Delete it and create a new one instead.'
     )
Ejemplo n.º 4
0
    def test_delete_with_transition_references(self):
        workflow_state = ckanext_factories.WorkflowState()
        workflow_transition = ckanext_factories.WorkflowTransition(
            from_state_id=workflow_state['id'])
        self.test_action('workflow_state_delete', id=workflow_state['id'])
        assert ckanext_model.WorkflowTransition.get(
            workflow_transition['id']).state == 'deleted'

        workflow_state = ckanext_factories.WorkflowState()
        workflow_transition = ckanext_factories.WorkflowTransition(
            to_state_id=workflow_state['id'])
        self.test_action('workflow_state_delete', id=workflow_state['id'])
        assert ckanext_model.WorkflowTransition.get(
            workflow_transition['id']).state == 'deleted'

        workflow_state = ckanext_factories.WorkflowState()
        workflow_transition = ckanext_factories.WorkflowTransition(
            from_state_id=None, to_state_id=workflow_state['id'])
        self.test_action('workflow_state_delete', id=workflow_state['id'])
        assert ckanext_model.WorkflowTransition.get(
            workflow_transition['id']).state == 'deleted'
Ejemplo n.º 5
0
 def test_update_valid_change_revert_3(self):
     workflow_state1 = ckanext_factories.WorkflowState()
     workflow_state2 = ckanext_factories.WorkflowState(
         revert_state_id=workflow_state1['id'])
     workflow_state3 = ckanext_factories.WorkflowState(
         revert_state_id=workflow_state2['id'])
     ckanext_factories.WorkflowTransition(
         from_state_id=workflow_state1['id'],
         to_state_id=workflow_state2['id'])
     ckanext_factories.WorkflowTransition(
         from_state_id=workflow_state2['id'],
         to_state_id=workflow_state3['id'])
     input_dict = {
         'id': workflow_state3['id'],
         'name': workflow_state3['name'],
         'revert_state_id': workflow_state1['id'],
         'metadata_records_private': True,
         'workflow_rules_json': '{}',
     }
     result, obj = self.test_action('workflow_state_update', **input_dict)
     assert_object_matches_dict(obj, input_dict)
Ejemplo n.º 6
0
    def test_update_invalid_forward_revert(self):
        workflow_state1 = ckanext_factories.WorkflowState()
        workflow_state2 = ckanext_factories.WorkflowState()
        workflow_state3 = ckanext_factories.WorkflowState()
        ckanext_factories.WorkflowTransition(
            from_state_id=workflow_state1['id'],
            to_state_id=workflow_state2['id'])
        ckanext_factories.WorkflowTransition(
            from_state_id=workflow_state2['id'],
            to_state_id=workflow_state3['id'])

        result, obj = self.test_action('workflow_state_update',
                                       should_error=True,
                                       id=workflow_state1['id'],
                                       revert_state_id=workflow_state2['id'])
        assert_error(result, 'revert_state_id',
                     'Forward revert in workflow state graph')

        result, obj = self.test_action('workflow_state_update',
                                       should_error=True,
                                       id=workflow_state1['id'],
                                       revert_state_id=workflow_state3['id'])
        assert_error(result, 'revert_state_id',
                     'Forward revert in workflow state graph')
    def test_create_invalid_circular_transition(self):
        workflow_state1 = ckanext_factories.WorkflowState()
        workflow_state2 = ckanext_factories.WorkflowState()
        workflow_state3 = ckanext_factories.WorkflowState()
        ckanext_factories.WorkflowTransition(
            from_state_id=workflow_state1['id'],
            to_state_id=workflow_state2['id'])
        ckanext_factories.WorkflowTransition(
            from_state_id=workflow_state2['id'],
            to_state_id=workflow_state3['id'])

        result, obj = self.test_action('workflow_transition_create',
                                       should_error=True,
                                       from_state_id=workflow_state2['id'],
                                       to_state_id=workflow_state1['id'])
        assert_error(result, '__after',
                     'Transition loop in workflow state graph')

        result, obj = self.test_action('workflow_transition_create',
                                       should_error=True,
                                       from_state_id=workflow_state3['id'],
                                       to_state_id=workflow_state1['id'])
        assert_error(result, '__after',
                     'Transition loop in workflow state graph')
 def test_delete_valid(self):
     workflow_transition = ckanext_factories.WorkflowTransition()
     self.test_action('workflow_transition_delete',
                      id=workflow_transition['id'])