Beispiel #1
0
    def test_upload(self):
        from ..upload import upload

        # Make request with test client instead of requests library
        factory = partial(tclient_request_factory, self.client)

        metadata = dict(
            upload_type="software",
            title="Test title",
            creators=[
                dict(name="Doe, John", affiliation="Atlantis"),
                dict(name="Smith, Jane", affiliation="Atlantis")
            ],
            description="Test Description",
            publication_date="2013-05-08",
        )
        files = [make_pdf_fixture('test.pdf', "upload test")]

        metadata = upload(
            self.accesstoken[self.user.id],
            metadata,
            files,
            publish=True,
            request_factory=factory
        )
        assert 'record_id' in metadata
        assert 'doi' in metadata
Beispiel #2
0
    def test_upload(self):
        from ..upload import upload

        # Make request with test client instead of requests library
        factory = partial(tclient_request_factory, self.client)

        metadata = dict(
            upload_type="software",
            title="Test title",
            creators=[
                dict(name="Doe, John", affiliation="Atlantis"),
                dict(name="Smith, Jane", affiliation="Atlantis")
            ],
            description="Test Description",
            publication_date="2013-05-08",
        )
        files = [make_pdf_fixture('test.pdf', "upload test")]

        metadata = upload(self.accesstoken[self.user.id],
                          metadata,
                          files,
                          publish=True,
                          request_factory=factory)
        assert 'record_id' in metadata
        assert 'doi' in metadata
    def test_deposit_files(self):
        from flask import current_app, url_for
        from invenio_deposit.loader import \
            deposition_metadata
        from invenio.modules.workflows.models import Workflow
        from invenio.webdeposit_utils import create_workflow, deposit_files, \
            get_latest_or_new_workflow

        user_id = self.login_user()

        # Test for every deposition type
        for deposition_type in deposition_metadata.keys():
            workflow = create_workflow(deposition_type, user_id)
            uuid = workflow.get_uuid()

            pdffile = make_pdf_fixture("test.pdf")

            with current_app.test_request_context(
                url_for(
                    'webdeposit.upload_file', deposition_type=deposition_type,
                    uuid=uuid
                ),
                method='POST',
                data={
                    'file': pdffile,
                    'name': 'test.pdf', }):

                deposit_files(user_id, deposition_type, uuid, preingest=True)

            workflow = get_latest_or_new_workflow(deposition_type, user_id)
            workflow.run()

            draft = Workflow.get(
                Workflow.id_user == user_id, Workflow.uuid == uuid
            ).one().extra_data['drafts'][0]

            assert len(draft['form_values']['files']) == 1
            filemeta = draft['form_values']['files'][0]
            assert filemeta['name'] == 'test.pdf'
            assert filemeta['content_type'] == 'application/pdf'
Beispiel #4
0
    def test_deposit_files(self):
        from flask import current_app, url_for
        from invenio_deposit.loader import \
            deposition_metadata
        from invenio.modules.workflows.models import Workflow
        from invenio.webdeposit_utils import create_workflow, deposit_files, \
            get_latest_or_new_workflow

        user_id = self.login_user()

        # Test for every deposition type
        for deposition_type in deposition_metadata.keys():
            workflow = create_workflow(deposition_type, user_id)
            uuid = workflow.get_uuid()

            pdffile = make_pdf_fixture("test.pdf")

            with current_app.test_request_context(url_for(
                    'webdeposit.upload_file',
                    deposition_type=deposition_type,
                    uuid=uuid),
                                                  method='POST',
                                                  data={
                                                      'file': pdffile,
                                                      'name': 'test.pdf',
                                                  }):

                deposit_files(user_id, deposition_type, uuid, preingest=True)

            workflow = get_latest_or_new_workflow(deposition_type, user_id)
            workflow.run()

            draft = Workflow.get(
                Workflow.id_user == user_id,
                Workflow.uuid == uuid).one().extra_data['drafts'][0]

            assert len(draft['form_values']['files']) == 1
            filemeta = draft['form_values']['files'][0]
            assert filemeta['name'] == 'test.pdf'
            assert filemeta['content_type'] == 'application/pdf'
Beispiel #5
0
 def test_make_make_pdf_fixture(self):
     res = make_pdf_fixture("test.pdf", text="Content")
     assert isinstance(res, tuple)
     assert res[1] == "test.pdf"
     assert hasattr(res[0], 'read')
Beispiel #6
0
 def test_make_make_pdf_fixture(self):
     res = make_pdf_fixture("test.pdf", text="Content")
     assert isinstance(res, tuple)
     assert res[1] == "test.pdf"
     assert hasattr(res[0], "read")