예제 #1
0
def create(method: str, params: MultiDict, session: Session, *args,
           **kwargs) -> Response:
    """Create a new submission, and redirect to workflow."""
    submitter, client = user_and_client_from_session(session)
    response_data = {}
    if method == 'GET':     # Display a splash page.
        response_data['user_submissions'] \
            = _load_submissions_for_user(session.user.user_id)
        params = MultiDict()

    # We're using a form here for CSRF protection.
    form = CreateSubmissionForm(params)
    response_data['form'] = form

    if method == 'POST':
        if not form.validate():
            raise BadRequest(response_data)

        command = CreateSubmission(creator=submitter, client=client)
        if not validate_command(form, command):
            raise BadRequest(response_data)

        try:
            submission, _ = save(command)
        except SaveError as e:
            logger.error('Could not save command: %s', e)
            raise InternalServerError(response_data) from e

        loc = url_for('ui.verify_user', submission_id=submission.submission_id)
        return {}, status.SEE_OTHER, {'Location': loc}
    return response_data, status.OK, {}
예제 #2
0
    def test_update_submission_with_valid_data(self, mock_events, url_for):
        """Update a submission with valid data."""
        preserve_exceptions_and_events(mock_events)
        url_for.return_value = '/foo/'
        user = User(1234, '*****@*****.**')
        mock_events.save.return_value = (Submission(creator=user,
                                                    owner=user,
                                                    created=datetime.now(UTC)),
                                         [
                                             CreateSubmission(creator=user),
                                             SetTitle(creator=user,
                                                      title='foo title')
                                         ])
        data = {
            'metadata': {
                'title':
                'foo title',
                'authors': [{
                    'forename': 'Jane',
                    'surname': 'Doe',
                    'email': '*****@*****.**'
                }]
            }
        }
        resp, stat, head = submission.update_submission(
            data, self.headers, self.agents, self.token, 1)
        self.assertEqual(
            stat, status.OK, "Should return 200 OK when submission is"
            " successfully updated.")
        self.assertIn('Location', head, "Should include a Location header.")
        call_args, call_kwargs = mock_events.save.call_args

        self.assertIsInstance(call_args[0], SetTitle, "Should pass a SetTitle")
        self.assertIsInstance(call_args[1], SetAuthors,
                              "Should pass an SetAuthors")
예제 #3
0
 def test_get_submission(self, mock_events):
     """Should return a JSON-serializable dict if submisison exists."""
     preserve_exceptions_and_events(mock_events)
     user = User(1234, '*****@*****.**')
     mock_events.load.return_value = (Submission(creator=user,
                                                 owner=user,
                                                 created=datetime.now(UTC)),
                                      [CreateSubmission(creator=user)])
     content, status_code, headers = submission.get_submission(1)
     self.assertEqual(mock_events.load.call_count, 1,
                      "Should call load() in the events core package")
     self.assertEqual(status_code, status.OK, "Should return 200 OK")
     self.assertIsInstance(content, dict, "Should return a dict")
     try:
         json.dumps(content)
     except Exception:
         self.fail("Content should be JSON-serializable.")
예제 #4
0
    def test_create_submission_with_valid_data(self, mock_events, url_for):
        """Create a submission with valid data."""
        preserve_exceptions_and_events(mock_events)
        url_for.return_value = '/foo/'
        user = User(1234, '*****@*****.**')
        mock_events.save.return_value = (Submission(creator=user,
                                                    owner=user,
                                                    created=datetime.now(UTC)),
                                         [CreateSubmission(creator=user)])
        data = {'primary_classification': {'category': 'astro-ph.GA'}}
        resp, stat, head = submission.create_submission(
            data, self.headers, self.agents, self.token)
        call_args, call_kwargs = mock_events.save.call_args

        self.assertIsInstance(call_args[0], CreateSubmission,
                              "Should pass a CreateSubmission first")
        self.assertIsInstance(call_args[1], SetPrimaryClassification,
                              "Should pass a SetPrimaryClassification")
        self.assertEqual(
            stat, status.CREATED,
            "Should return 201 Created when submission is"
            " successfully created.")
        self.assertIn('Location', head, "Should include a Location header.")
예제 #5
0
 def raise_invalid_event(*events, **kwargs):
     raise InvalidEvent(
         CreateSubmission(creator=self.agents['creator']), 'foo')
예제 #6
0
def process_submission(s):
    """Process a submission from a tsvfile row."""
    # TODO: Make sure forename surname separation are better
    try:
        forename, surname = s['submitter_name'].rsplit(maxsplit=1)
    except ValueError:
        forename = ''
        surname = s['submitter_name']
    submitter = domain.User(s['submitter_id'], email=s['submitter_email'],
                            forename=forename, surname=surname,
                            endorsements=[s['category']])

    metadata = dict([
        ('title', s['title']),
        ('abstract', s['abstract']),
        ('comments', s['comments']),
        ('report_num', s['report_num']),
        ('doi', s['doi']),
        ('journal_ref', s['journal_ref'])
    ])

    submission, stack = save(
        CreateSubmission(creator=submitter)
    )

    if s.get('is_author') == '1':
        submission, stack = save(
            ConfirmAuthorship(
                creator=submitter,
                submitter_is_author=True
            ),
            submission_id=submission.submission_id
        )
    else:
        submission, stack = save(
            ConfirmAuthorship(
                creator=submitter,
                submitter_is_author=False
            ),
            submission_id=submission.submission_id
        )

    if s.get('agree_policy') == '1':
        submission, stack = save(
            ConfirmPolicy(creator=submitter),
            submission_id=submission.submission_id
        )

    if s.get('userinfo') == '1':
        submission, stack = save(
            ConfirmContactInformation(creator=submitter),
            submission_id=submission.submission_id
        )

    submission, stack = save(
        SetAuthors(
            authors_display=s['authors'],
            creator=submitter
        ),
        SetPrimaryClassification(creator=submitter, category=s['category']),
        submission_id=submission.submission_id
    )
    if s['title']:
        submission, stack = save(
            SetTitle(creator=submitter, title=metadata['title']),
            submission_id=submission.submission_id
        )
    if s['abstract']:
        submission, stack = save(
            SetAbstract(creator=submitter, abstract=metadata['abstract']),
            submission_id=submission.submission_id
        )
    if metadata['comments']:
        submission, stack = save(
            SetComments(creator=submitter, comments=metadata['comments']),
            submission_id=submission.submission_id
        )

    if metadata['journal_ref']:
        submission, stack = save(
            SetJournalReference(creator=submitter,
                                journal_ref=metadata['journal_ref']),
            submission_id=submission.submission_id
        )

    if metadata['doi']:
        submission, stack = save(
            SetDOI(creator=submitter, doi=metadata['doi']),
            submission_id=submission.submission_id
        )

    if metadata['report_num']:
        submission, stack = save(
            SetReportNumber(creator=submitter,
                            report_num=metadata['report_num']),
            submission_id=submission.submission_id
        )

    # Parse the license
    license_uri = s.get('license')
    if license_uri:
        submission, stack = save(
            SetLicense(creator=submitter, license_uri=license_uri),
            submission_id=submission.submission_id
        )

    if s.get('package'):
        submission, stack = save(
            SetUploadPackage(
                format=s['source_format'],
                checksum='0',
                identifier=1,
                creator=submitter
            ),
            submission_id=submission.submission_id
        )

    if s.get('status') not in INVALID_STATUSES:
        submission, stack = save(
            FinalizeSubmission(creator=submitter),
            submission_id=submission.submission_id
        )

    return submission.submission_id