예제 #1
0
 def setUp(self):
     """We have a submission."""
     self.creator = User(native_id=1234, email='*****@*****.**')
     self.submission = Submission(
         submission_id=2347441,
         creator=self.creator,
         owner=self.creator,
         created=datetime.now(UTC),
         source_content=SubmissionContent(
             identifier='5678',
             source_format=SubmissionContent.Format('pdf'),
             checksum='a1b2c3d4',
             uncompressed_size=58493,
             compressed_size=58493
         )
     )
     self.submission.submitter_contact_verified = True
     self.submission.submitter_accepts_policy = True
     self.submission.license = License(name='foo', uri='http://foo.foo')
     self.submission.metadata = SubmissionMetadata(
         title='foo',
         abstract='oof',
         authors_display='Bloggs, J'
     )
     self.process = \
         ProposeCrossListFromPrimaryCategory(self.submission.submission_id)
예제 #2
0
 def setUp(self):
     """We have a submission."""
     self.creator = User(native_id=1234, email='*****@*****.**')
     self.submission = Submission(
         submission_id=2347441,
         creator=self.creator,
         owner=self.creator,
         created=datetime.now(UTC),
         source_content=SubmissionContent(
             identifier='5678',
             source_format=SubmissionContent.Format('pdf'),
             checksum='a1b2c3d4',
             uncompressed_size=58493,
             compressed_size=58493))
     self.process = CheckPDFSize(self.submission.submission_id)
예제 #3
0
    def _parse_upload_status(self, data: dict) -> Upload:
        file_errors = defaultdict(list)
        non_file_errors = []
        for etype, filename, message in data['errors']:
            if filename:
                file_errors[filename].append(FileError(etype.upper(), message))
            else:
                non_file_errors.append(FileError(etype.upper(), message))

        return Upload(
            started=dateutil.parser.parse(data['start_datetime']),
            completed=dateutil.parser.parse(data['completion_datetime']),
            created=dateutil.parser.parse(data['created_datetime']),
            modified=dateutil.parser.parse(data['modified_datetime']),
            status=Upload.Status(data['upload_status']),
            lifecycle=Upload.LifecycleStates(data['workspace_state']),
            locked=bool(data['lock_state'] == 'LOCKED'),
            identifier=data['upload_id'],
            files=[
                FileStatus(name=fdata['name'],
                           path=fdata['public_filepath'],
                           size=fdata['size'],
                           file_type=fdata['type'],
                           modified=dateutil.parser.parse(
                               fdata['modified_datetime']),
                           errors=file_errors[fdata['public_filepath']])
                for fdata in data['files']
            ],
            errors=non_file_errors,
            compressed_size=data['upload_compressed_size'],
            size=data['upload_total_size'],
            checksum=data['checksum'],
            source_format=SubmissionContent.Format(data['source_format']))
예제 #4
0
 def test_small_source(self):
     """The submission source content is quite small."""
     self.submission.source_content = SubmissionContent(
         identifier='5678',
         source_format=SubmissionContent.Format('pdf'),
         checksum='a1b2c3d4',
         uncompressed_size=593,
         compressed_size=53)
     trigger = Trigger(before=self.submission,
                       after=self.submission,
                       params={
                           'UNCOMPRESSED_PACKAGE_MAX_BYTES': 40_003_932,
                           'COMPRESSED_PACKAGE_MAX_BYTES': 3_039_303
                       })
     events = []
     self.process.check(None, trigger, events.append)
     self.assertEqual(len(events), 0, 'No events generated')
예제 #5
0
 def test_huge_uncompressed_size(self):
     """The submission source is huge uncompressed."""
     self.submission.source_content = SubmissionContent(
         identifier='5678',
         source_format=SubmissionContent.Format('pdf'),
         checksum='a1b2c3d4',
         uncompressed_size=593_032_039,
         compressed_size=53)
     trigger = Trigger(before=self.submission,
                       after=self.submission,
                       params={
                           'UNCOMPRESSED_PACKAGE_MAX_BYTES': 40_003_932,
                           'COMPRESSED_PACKAGE_MAX_BYTES': 3_039_303
                       })
     events = []
     self.process.check(None, trigger, events.append)
     self.assertIsInstance(events[0], AddHold, 'Adds a hold')
     self.assertEqual(events[0].hold_type, Hold.Type.SOURCE_OVERSIZE)
예제 #6
0
 def test_post_upload(self, mock_load, mock_save, mock_filemanager):
     """POST request for submission with an existing upload package."""
     submission_id = 2
     mock_submission = mock.MagicMock(
         submission_id=submission_id,
         source_content=SubmissionContent(
             identifier='5433',
             checksum='a1s2d3f4',
             uncompressed_size=593920,
             compressed_size=1000,
             source_format=SubmissionContent.Format.TEX),
         is_finalized=False,
         is_announced=False,
         arxiv_id=None,
         version=1)
     mock_load.return_value = (mock_submission, [])
     mock_save.return_value = (mock_submission, [])
     mock_fm = mock.MagicMock()
     mock_fm.add_file.return_value = Upload(
         identifier=25,
         checksum='a1s2d3f4',
         size=593920,
         started=datetime.now(),
         completed=datetime.now(),
         created=datetime.now(),
         modified=datetime.now(),
         status=Upload.Status.READY,
         lifecycle=Upload.LifecycleStates.ACTIVE,
         locked=False,
         files=[
             FileStatus(path='',
                        name='thebestfile.pdf',
                        file_type='PDF',
                        modified=datetime.now(),
                        size=20505,
                        ancillary=False,
                        errors=[])
         ],
         errors=[])
     mock_filemanager.current_session.return_value = mock_fm
     params = MultiDict({})
     mock_file = mock.MagicMock()
     files = MultiDict({'file': mock_file})
     _, code, _ = upload.upload_files('POST',
                                      params,
                                      self.session,
                                      submission_id,
                                      files=files,
                                      token='footoken')
     self.assertEqual(code, status.SEE_OTHER, 'Returns 303')
     self.assertEqual(mock_fm.add_file.call_count, 1,
                      'Calls the file management service')
     self.assertTrue(mock_filemanager.add_file.called_with(mock_file))
예제 #7
0
 def test_huge_previous_holds(self):
     """The submission has a hold, and this source content is too big."""
     self.submission.source_content = SubmissionContent(
         identifier='5678',
         source_format=SubmissionContent.Format('pdf'),
         checksum='a1b2c3d4',
         uncompressed_size=593_032_039,
         compressed_size=593_032_039)
     self.submission.holds['asdf1234'] = Hold(
         event_id='asdf1234',
         creator=self.creator,
         hold_type=Hold.Type.SOURCE_OVERSIZE)
     trigger = Trigger(before=self.submission,
                       after=self.submission,
                       params={
                           'UNCOMPRESSED_PACKAGE_MAX_BYTES': 40_003_932,
                           'COMPRESSED_PACKAGE_MAX_BYTES': 3_039_303
                       })
     events = []
     self.process.check(None, trigger, events.append)
     self.assertEqual(len(events), 0, 'Generates no holds')
예제 #8
0
 def test_post_delete_confirmed(self, mock_load, mock_save,
                                mock_filemanager, mock_url_for):
     """POST request to delete a file without confirmation."""
     redirect_uri = '/foo'
     mock_url_for.return_value = redirect_uri
     upload_id = '5433'
     submission_id = 2
     mock_load.return_value = (mock.MagicMock(
         submission_id=submission_id,
         source_content=SubmissionContent(
             identifier=upload_id,
             checksum='a1s2d3f4',
             uncompressed_size=593920,
             compressed_size=1000,
             source_format=SubmissionContent.Format.TEX),
         is_finalized=False,
         is_announced=False,
         arxiv_id=None,
         version=1), [])
     mock_save.return_value = (mock.MagicMock(
         submission_id=submission_id,
         source_content=SubmissionContent(
             identifier=upload_id,
             checksum='a1s2d3f4',
             uncompressed_size=593920,
             compressed_size=1000,
             source_format=SubmissionContent.Format.TEX),
         is_finalized=False,
         is_announced=False,
         arxiv_id=None,
         version=1), [])
     file_path = 'anc/foo.jpeg'
     params = MultiDict({'file_path': file_path, 'confirmed': True})
     _, code, _ = upload.delete('POST', params, self.session, submission_id,
                                'footoken')
     self.assertTrue(
         mock_filemanager.delete_file.called_with(upload_id, file_path),
         "Delete file method of file manager service is called")
     self.assertEqual(code, status.SEE_OTHER, "Returns See Other")
예제 #9
0
 def test_get_upload(self, mock_load, mock_filemanager):
     """GET request for submission with an existing upload package."""
     submission_id = 2
     mock_load.return_value = (mock.MagicMock(
         submission_id=submission_id,
         source_content=SubmissionContent(
             identifier='5433',
             checksum='a1s2d3f4',
             uncompressed_size=593920,
             compressed_size=1000,
             source_format=SubmissionContent.Format.TEX),
         is_finalized=False,
         is_announced=False,
         arxiv_id=None,
         version=1), [])
     mock_filemanager.get_upload_status.return_value = (Upload(
         identifier=25,
         checksum='a1s2d3f4',
         size=593920,
         started=datetime.now(),
         completed=datetime.now(),
         created=datetime.now(),
         modified=datetime.now(),
         status=Upload.Status.READY,
         lifecycle=Upload.LifecycleStates.ACTIVE,
         locked=False,
         files=[
             FileStatus(path='',
                        name='thebestfile.pdf',
                        file_type='PDF',
                        modified=datetime.now(),
                        size=20505,
                        ancillary=False,
                        errors=[])
         ],
         errors=[]))
     params = MultiDict({})
     files = MultiDict({})
     data, code, _ = upload.upload_files('GET',
                                         params,
                                         self.session,
                                         submission_id,
                                         files=files,
                                         token='footoken')
     self.assertEqual(code, status.OK, 'Returns 200 OK')
     self.assertEqual(mock_filemanager.get_upload_status.call_count, 1,
                      'Calls the file management service')
     self.assertIn('status', data, 'Upload status is in response')
     self.assertIn('submission', data, 'Submission is in response')
     self.assertIn('submission_id', data, 'ID is in response')
예제 #10
0
 def test_small_source_previous_hold(self):
     """The submission has a hold, but this source content is OK."""
     self.submission.source_content = SubmissionContent(
         identifier='5678',
         source_format=SubmissionContent.Format('pdf'),
         checksum='a1b2c3d4',
         uncompressed_size=593,
         compressed_size=53)
     self.submission.holds['asdf1234'] = Hold(
         event_id='asdf1234',
         creator=self.creator,
         hold_type=Hold.Type.SOURCE_OVERSIZE)
     trigger = Trigger(before=self.submission,
                       after=self.submission,
                       params={
                           'UNCOMPRESSED_PACKAGE_MAX_BYTES': 40_003_932,
                           'COMPRESSED_PACKAGE_MAX_BYTES': 3_039_303
                       })
     events = []
     self.process.check(None, trigger, events.append)
     self.assertIsInstance(events[0], RemoveHold, 'Removes a hold')
     self.assertEqual(events[0].hold_event_id, 'asdf1234')
     self.assertEqual(events[0].hold_type, Hold.Type.SOURCE_OVERSIZE)
예제 #11
0
 def from_dict(cls: type, data: dict) -> 'Upload':
     """Instantiate an :class:`Upload` from a dict."""
     if 'files' in data:
         data['files'] = [FileStatus.from_dict(f) for f in data['files']]
     if 'errors' in data:
         data['errors'] = [FileError.from_dict(e) for e in data['errors']]
     for key in ['started', 'completed', 'created', 'modified']:
         if key in data and type(data[key]) is str:
             data[key] = dateutil.parser.parse(data[key])
     if 'source_format' in data:
         data['source_format'] = \
             SubmissionContent.Format(data['source_format'])
     instance: Upload = cls(**data)
     return instance
예제 #12
0
 def test_post_delete(self, mock_load, mock_filemanager):
     """POST request to delete a file without confirmation."""
     submission_id = 2
     mock_load.return_value = (mock.MagicMock(
         submission_id=submission_id,
         source_content=SubmissionContent(
             identifier='5433',
             checksum='a1s2d3f4',
             uncompressed_size=593920,
             compressed_size=1000,
             source_format=SubmissionContent.Format.TEX),
         is_finalized=False,
         is_announced=False,
         arxiv_id=None,
         version=1), [])
     file_path = 'anc/foo.jpeg'
     params = MultiDict({'file_path': file_path})
     try:
         upload.delete('POST', params, self.session, submission_id, 'tok')
     except BadRequest as e:
         data = e.description
         self.assertIn('form', data, "Returns a form in response")
예제 #13
0
 def test_get_delete(self, mock_load, mock_filemanager):
     """GET request to delete a file."""
     submission_id = 2
     mock_load.return_value = (mock.MagicMock(
         submission_id=submission_id,
         source_content=SubmissionContent(
             identifier='5433',
             checksum='a1s2d3f4',
             uncompressed_size=593920,
             compressed_size=1000,
             source_format=SubmissionContent.Format.TEX),
         is_finalized=False,
         is_announced=False,
         arxiv_id=None,
         version=1), [])
     file_path = 'anc/foo.jpeg'
     params = MultiDict({'path': file_path})
     data, code, _ = upload.delete('GET', params, self.session,
                                   submission_id, 'footoken')
     self.assertEqual(code, status.OK, "Returns 200 OK")
     self.assertIn('form', data, "Returns a form in response")
     self.assertEqual(data['form'].file_path.data, file_path, 'Path is set')