コード例 #1
0
    def test_workflow_creation(self):
        from invenio_deposit.loader import \
            deposition_metadata
        from invenio.modules.workflows.models import Workflow
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_latest_or_new_workflow, \
            get_workflow, delete_workflow, InvenioWebDepositNoDepositionType

        user_id = self.login_user()

        number_of_dep_types = len(deposition_metadata)
        # Test for every deposition type
        for deposition_type in deposition_metadata.keys():
            # New workflow is created
            workflow = get_latest_or_new_workflow(deposition_type,
                                                  user_id=user_id)
            self.assertTrue(workflow is not None)
            # The just created workflow is retrieved as latest
            workflow2 = get_latest_or_new_workflow(deposition_type,
                                                   user_id=user_id)
            self.assertTrue(workflow2 is not None)

            self.assertEqual(str(workflow2.uuid), str(workflow.uuid))

            # and also retrieved with its uuid
            workflow = get_workflow(workflow.uuid, deposition_type)
            self.assertTrue(workflow is not None)

        # Test get_workflow function with random arguments
        deposition_type = deposition_metadata.keys()[-1]
        workflow = get_workflow('some_uuid_that_doesnt_exist', deposition_type)
        self.assertTrue(workflow is None)

        # Create workflow without using webdeposit_utils
        workflow = DepositionWorkflow(deposition_type=deposition_type,
                                      user_id=1)

        self.assertRaises(InvenioWebDepositNoDepositionType,
                          get_workflow, workflow.get_uuid(),
                          'deposition_type_that_doesnt_exist')

        # Test that the retrieved workflow is the same and not None
        workflow2 = get_workflow(workflow.get_uuid(), deposition_type)
        self.assertTrue(workflow2 is not None)
        self.assertEqual(workflow2.get_uuid(), workflow.get_uuid())

        # Check the number of created workflows
        count_workflows = Workflow.get(
            Workflow.module_name == "webdeposit"
        ).count()
        self.assertEqual(count_workflows, number_of_dep_types + 1)

        uuid = workflow.get_uuid()
        delete_workflow(1, uuid)

        workflow = get_workflow(uuid, deposition_type)
        self.assertTrue(workflow is None)
コード例 #2
0
    def test_workflow_creation(self):
        from invenio_deposit.loader import \
            deposition_metadata
        from invenio.modules.workflows.models import Workflow
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_latest_or_new_workflow, \
            get_workflow, delete_workflow, InvenioWebDepositNoDepositionType

        user_id = self.login_user()

        number_of_dep_types = len(deposition_metadata)
        # Test for every deposition type
        for deposition_type in deposition_metadata.keys():
            # New workflow is created
            workflow = get_latest_or_new_workflow(deposition_type,
                                                  user_id=user_id)
            self.assertTrue(workflow is not None)
            # The just created workflow is retrieved as latest
            workflow2 = get_latest_or_new_workflow(deposition_type,
                                                   user_id=user_id)
            self.assertTrue(workflow2 is not None)

            self.assertEqual(str(workflow2.uuid), str(workflow.uuid))

            # and also retrieved with its uuid
            workflow = get_workflow(workflow.uuid, deposition_type)
            self.assertTrue(workflow is not None)

        # Test get_workflow function with random arguments
        deposition_type = deposition_metadata.keys()[-1]
        workflow = get_workflow('some_uuid_that_doesnt_exist', deposition_type)
        self.assertTrue(workflow is None)

        # Create workflow without using webdeposit_utils
        workflow = DepositionWorkflow(deposition_type=deposition_type,
                                      user_id=1)

        self.assertRaises(InvenioWebDepositNoDepositionType, get_workflow,
                          workflow.get_uuid(),
                          'deposition_type_that_doesnt_exist')

        # Test that the retrieved workflow is the same and not None
        workflow2 = get_workflow(workflow.get_uuid(), deposition_type)
        self.assertTrue(workflow2 is not None)
        self.assertEqual(workflow2.get_uuid(), workflow.get_uuid())

        # Check the number of created workflows
        count_workflows = Workflow.get(
            Workflow.module_name == "webdeposit").count()
        self.assertEqual(count_workflows, number_of_dep_types + 1)

        uuid = workflow.get_uuid()
        delete_workflow(1, uuid)

        workflow = get_workflow(uuid, deposition_type)
        self.assertTrue(workflow is None)
コード例 #3
0
    def test_workflow_creation(self):
        from invenio.webdeposit_load_deposition_types import \
            deposition_metadata
        from invenio.bibworkflow_model import Workflow
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_latest_or_new_workflow, \
            get_workflow, delete_workflow
        from invenio.sqlalchemyutils import db
        from invenio.webuser_flask import login_user

        login_user(1)

        number_of_dep_types = len(deposition_metadata)
        # Test for every deposition type
        for deposition_type in deposition_metadata.keys():
            # New workflow is created
            workflow = get_latest_or_new_workflow(deposition_type, user_id=1)
            assert workflow is not None

            # The just created workflow is retrieved as latest
            workflow2 = get_latest_or_new_workflow(deposition_type, user_id=1)
            assert workflow2 is not None
            assert str(workflow2.uuid) == str(workflow.uuid)

            # and also retrieved with its uuid
            workflow = get_workflow(deposition_type, workflow.uuid)
            assert workflow is not None

        # Test get_workflow function with random arguments
        workflow = get_workflow('deposition_type_that_doesnt_exist',
                                'some_uuid')
        assert workflow is None

        deposition_type = deposition_metadata.keys()[-1]
        workflow = get_workflow(deposition_type, 'some_uuid_that_doesnt_exist')
        assert workflow is None

        # Create workflow without using webdeposit_utils
        wf = deposition_metadata[deposition_type]["workflow"]
        workflow = DepositionWorkflow(deposition_type=deposition_type,
                                      workflow=wf,
                                      user_id=1)

        # Test that the retrieved workflow is the same and not None
        workflow2 = get_workflow(deposition_type, workflow.get_uuid())
        assert workflow2 is not None
        assert workflow2.get_uuid() == workflow.get_uuid()

        # Check the number of created workflows
        workflows = db.session.query(Workflow).all()
        assert len(workflows) == number_of_dep_types + 1

        uuid = workflow.get_uuid()
        delete_workflow(1, uuid)
        workflow = get_workflow(deposition_type, uuid)
        assert workflow is None
コード例 #4
0
    def test_form_functions(self):
        from invenio_deposit.loader import \
            deposition_metadata
        from invenio_deposit import forms
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_form, \
            get_form_status, set_form_status, CFG_DRAFT_STATUS
        from invenio.modules.workflows.models import Workflow

        for metadata in deposition_metadata.values():
            for wf_function in metadata['workflow']:
                if 'render_form' == wf_function.func_name:
                    break

        user_id = self.login_user()

        deposition_workflow = DepositionWorkflow(deposition_type='Article',
                                                 user_id=user_id)

        uuid = deposition_workflow.get_uuid()

        # Run the workflow to insert a form in the db
        deposition_workflow.run()

        # There is only one form in the db
        workflows = Workflow.get(module_name='webdeposit')
        assert len(workflows.all()) == 1
        assert len(workflows[0].extra_data['drafts']) == 1

        # Test that guest user doesn't have access to the form
        form = get_form(0, uuid=uuid)
        assert form is None

        # Test that the current form has the right type
        form = get_form(user_id, uuid=deposition_workflow.get_uuid())
        assert isinstance(form, forms['ArticleForm'])
        assert str(uuid) == str(deposition_workflow.get_uuid())

        # Test that form is returned with get_form function
        form = get_form(user_id, deposition_workflow.get_uuid())
        assert form is not None

        form = get_form(user_id, deposition_workflow.get_uuid(), step=0)
        assert form is not None

        # Second step doesn't have a form
        form = get_form(user_id, deposition_workflow.get_uuid(), step=1)
        assert form is None

        form_status = get_form_status(user_id, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['unfinished']

        form_status = get_form_status(user_id,
                                      deposition_workflow.get_uuid(),
                                      step=2)
        assert form_status is None

        set_form_status(user_id, uuid, CFG_DRAFT_STATUS['finished'])
        form_status = get_form_status(user_id, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['finished']
コード例 #5
0
    def test_form_functions(self):
        from invenio_deposit.loader import \
            deposition_metadata
        from invenio_deposit import forms
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_form, \
            get_form_status, set_form_status, CFG_DRAFT_STATUS
        from invenio.modules.workflows.models import Workflow

        for metadata in deposition_metadata.values():
            for wf_function in metadata['workflow']:
                if 'render_form' == wf_function.func_name:
                    break

        user_id = self.login_user()

        deposition_workflow = DepositionWorkflow(deposition_type='Article',
                                                 user_id=user_id)

        uuid = deposition_workflow.get_uuid()

        # Run the workflow to insert a form in the db
        deposition_workflow.run()

        # There is only one form in the db
        workflows = Workflow.get(module_name='webdeposit')
        assert len(workflows.all()) == 1
        assert len(workflows[0].extra_data['drafts']) == 1

        # Test that guest user doesn't have access to the form
        form = get_form(0, uuid=uuid)
        assert form is None

        # Test that the current form has the right type
        form = get_form(user_id, uuid=deposition_workflow.get_uuid())
        assert isinstance(form, forms['ArticleForm'])
        assert str(uuid) == str(deposition_workflow.get_uuid())

        # Test that form is returned with get_form function
        form = get_form(user_id, deposition_workflow.get_uuid())
        assert form is not None

        form = get_form(user_id, deposition_workflow.get_uuid(), step=0)
        assert form is not None

        # Second step doesn't have a form
        form = get_form(user_id, deposition_workflow.get_uuid(), step=1)
        assert form is None

        form_status = get_form_status(user_id, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['unfinished']

        form_status = get_form_status(user_id, deposition_workflow.get_uuid(),
                                      step=2)
        assert form_status is None

        set_form_status(user_id, uuid, CFG_DRAFT_STATUS['finished'])
        form_status = get_form_status(user_id, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['finished']
コード例 #6
0
    def test_field_functions(self):
        from datetime import datetime
        from invenio.sqlalchemyutils import db
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_model import WebDepositDraft
        from invenio.webdeposit_workflow_utils import render_form
        from invenio.webdeposit_utils import draft_field_get
        from invenio.webdeposit_deposition_forms.article_form import ArticleForm
        from invenio.cache import cache

        wf = [render_form(ArticleForm)]
        user_id = 1

        workflow = DepositionWorkflow(workflow=wf,
                                      deposition_type='TestWorkflow',
                                      user_id=user_id)

        cache.delete_many("1:current_deposition_type", "1:current_uuid")
        cache.add("1:current_deposition_type", 'TestWorkflow')
        cache.add("1:current_uuid", workflow.get_uuid())

        workflow.run()  # Insert a form
        uuid = workflow.get_uuid()

        # Test for a field that's not there
        value = draft_field_get(user_id, uuid, 'field_that_doesnt_exist')
        assert value is None

        # Test for a field that hasn't been inserted in db yet
        value = draft_field_get(user_id, uuid, 'publisher')
        assert value is None

        values = {'publisher': 'Test Publishers Association'}

        db.session.query(WebDepositDraft).\
            filter(WebDepositDraft.uuid == uuid,
                   WebDepositDraft.step == 0).\
            update({"form_values": values,
                    "timestamp": datetime.now()})
コード例 #7
0
    def test_field_functions(self):
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import draft_field_get, draft_field_set

        user_id = self.login_user()
        workflow = DepositionWorkflow(deposition_type='Article',
                                      user_id=user_id)

        workflow.run()  # Insert a form
        uuid = workflow.get_uuid()

        # Test for a field that's not there
        value = draft_field_get(user_id, uuid, 'field_that_doesnt_exist')
        self.assertTrue(value is None)

        # Test for a field that hasn't been inserted in db yet
        value = draft_field_get(user_id, uuid, 'publisher')
        self.assertTrue(value is None)

        draft_field_set(user_id, uuid, 'publisher',
                        'Test Publishers Association')

        value = draft_field_get(user_id, uuid, 'publisher')
        self.assertTrue(value is 'Test Publishers Association')
コード例 #8
0
    def test_field_functions(self):
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import draft_field_get, draft_field_set

        user_id = 1
        workflow = DepositionWorkflow(deposition_type='TestWorkflow',
                                      user_id=user_id)

        workflow.run()  # Insert a form
        uuid = workflow.get_uuid()

        # Test for a field that's not there
        value = draft_field_get(user_id, uuid, 'field_that_doesnt_exist')
        self.assertTrue(value is None)

        # Test for a field that hasn't been inserted in db yet
        value = draft_field_get(user_id, uuid, 'publisher')
        self.assertTrue(value is None)

        draft_field_set(user_id, uuid, 'publisher',
                        'Test Publishers Association')

        value = draft_field_get(user_id, uuid, 'publisher')
        self.assertTrue(value is 'Test Publishers Association')
コード例 #9
0
    def test_form_functions(self):
        from invenio.webdeposit_load_deposition_types import \
            deposition_metadata
        from invenio.webdeposit_load_forms import forms
        from invenio.webdeposit_model import WebDepositDraft
        from invenio.webdeposit_workflow import DepositionWorkflow
        from invenio.webdeposit_utils import get_current_form, get_form, \
            get_form_status, CFG_DRAFT_STATUS
        from invenio.sqlalchemyutils import db
        from invenio.webdeposit_workflow_utils import render_form, \
            wait_for_submission
        from invenio.cache import cache

        for metadata in deposition_metadata.values():
            for wf_function in metadata['workflow']:
                if 'render_form' == wf_function.func_name:
                    break

        from invenio.webuser_flask import login_user
        login_user(1)

        wf = [render_form(forms.values()[0]), wait_for_submission()]
        deposition_workflow = DepositionWorkflow(
            deposition_type='TestWorkflow', workflow=wf, user_id=1)

        uuid = deposition_workflow.get_uuid()
        cache.delete_many("1:current_deposition_type", "1:current_uuid")
        cache.add("1:current_deposition_type", 'TestWorkflow')
        cache.add("1:current_uuid", uuid)

        # Run the workflow to insert a form to the db
        deposition_workflow.run()

        # There is only one form in the db
        drafts = db.session.query(WebDepositDraft)
        assert len(drafts.all()) == 1

        # Test that guest user doesn't have access to the form
        uuid, form = get_current_form(0,
                                      deposition_type='TestWorkflow',
                                      uuid=uuid)
        assert form is None

        # Test that the current form has the right type
        uuid, form = get_current_form(1,
                                      deposition_type='TestWorkflow',
                                      uuid=deposition_workflow.get_uuid())
        assert isinstance(form, forms.values()[0])
        assert str(uuid) == str(deposition_workflow.get_uuid())

        # Test that form is returned with get_form function
        form = get_form(1, deposition_workflow.get_uuid())
        assert form is not None

        form = get_form(1, deposition_workflow.get_uuid(), step=0)
        assert form is not None

        # Second step doesn't have a form
        form = get_form(1, deposition_workflow.get_uuid(), step=1)
        assert form is None

        form_status = get_form_status(1, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['unfinished']

        form_status = get_form_status(1,
                                      deposition_workflow.get_uuid(),
                                      step=2)
        assert form_status is None

        db.session.query(WebDepositDraft).\
            update({'status': CFG_DRAFT_STATUS['finished']})

        form_status = get_form_status(1, deposition_workflow.get_uuid())
        assert form_status == CFG_DRAFT_STATUS['finished']