コード例 #1
0
 def test_update_nonexistant_submission(self, mock_events, url_for):
     """Trying to update a nonexistant submission throws exception."""
     preserve_exceptions_and_events(mock_events)
     mock_events.save.side_effect = NoSuchSubmission
     url_for.return_value = '/foo/'
     data = {'metadata': {'title': 'foo title'}}
     with self.assertRaises(NotFound):
         submission.update_submission(data, self.headers, self.user_data,
                                      self.client_data, self.token, 1)
コード例 #2
0
 def test_update_submission_with_db_down(self, mock_events, url_for):
     """An internal server error is raised when the database is down."""
     url_for.return_value = '/foo/'
     mock_events.save.side_effect = SaveError
     preserve_exceptions_and_events(mock_events)
     data = {'primary_classification': {'category': 'astro-ph'}}
     with self.assertRaises(InternalServerError):
         submission.update_submission(data, self.headers, self.user_data,
                                      self.client_data, self.token, 1)
コード例 #3
0
 def test_update_submission_with_invalid_data(self, mock_events, url_for):
     """Trying to update a submission with invalid data throws exception."""
     preserve_exceptions_and_events(mock_events)
     url_for.return_value = '/foo/'
     data = {
         'metadata': 'bad value',
     }
     with self.assertRaises(BadRequest):
         submission.update_submission(data, self.headers, self.user_data,
                                      self.client_data, self.token, 1)
コード例 #4
0
ファイル: tests.py プロジェクト: arXiv/arxiv-submission-api
    def test_update_submission_with_invalid_event(self, mock_events, url_for):
        """A Bad Request is raised on an invalid event."""
        url_for.return_value = '/foo/'
        preserve_exceptions_and_events(mock_events)

        def raise_invalid_event(*events, **kwargs):
            raise InvalidEvent(
                CreateSubmission(creator=self.agents['creator']), 'foo')

        mock_events.save.side_effect = raise_invalid_event
        data = {'primary_classification': {'category': 'astro-ph'}}
        with self.assertRaises(BadRequest):
            submission.update_submission(data, self.headers, self.agents,
                                         self.token, 1)
コード例 #5
0
    def test_update_submission_with_invalid_event(self, mock_events, url_for):
        """A Bad Request is raised on an invalid event."""
        url_for.return_value = '/foo/'
        preserve_exceptions_and_events(mock_events)

        def raise_invalid_event(*events, **kwargs):
            user = dict(**self.user_data)
            user['native_id'] = user['user_id']
            user.pop('user_id')
            raise InvalidEvent(CreateSubmission(creator=User(**user)), 'foo')

        mock_events.save.side_effect = raise_invalid_event
        data = {'primary_classification': {'category': 'astro-ph'}}
        with self.assertRaises(BadRequest):
            submission.update_submission(data, self.headers, self.user_data,
                                         self.client_data, self.token, 1)
コード例 #6
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()), [
                CreateSubmission(creator=user),
                UpdateMetadata(creator=user, metadata=[('title', 'foo title')])
            ])
        data = {
            'metadata': {
                'title':
                'foo title',
                'authors': [{
                    'forename': 'Jane',
                    'surname': 'Doe',
                    'email': '*****@*****.**'
                }]
            }
        }
        resp, stat, head = submission.update_submission(
            data, self.headers, self.user_data, self.client_data, self.token,
            1)
        self.assertEqual(
            stat, status.HTTP_200_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], UpdateMetadata,
                              "Should pass an UpdateMetadata")
        self.assertIsInstance(call_args[1], UpdateAuthors,
                              "Should pass an UpdateAuthors")
コード例 #7
0
def update_submission(submission_id: str) -> tuple:
    """Update the submission."""
    return submission.update_submission(request.get_json(),
                                        dict(request.headers),
                                        user_data=g.user,
                                        client_data=g.client,
                                        token=g.token,
                                        submission_id=submission_id)
コード例 #8
0
def update_submission(submission_id: int) -> tuple:
    """Update the submission."""
    data = request.get_json()
    if data is None:
        raise BadRequest('No data in request')
    return submission.update_submission(data,
                                        dict(request.headers),
                                        agents=request.agents,
                                        token=request.environ.get('token'),
                                        submission_id=submission_id)