예제 #1
0
 def test_post_request_with_unchanged_data(self, mock_load, mock_save):
     """POST request with valid but unchanged data."""
     submission_id = 2
     mock_submission = mock.MagicMock(
         submission_id=submission_id,
         is_finalized=False,
         metadata=mock.MagicMock(**{
             'doi': '10.0001/123456',
             'journal_ref': 'foo journal 10 2010: 12-345',
             'report_num': 'foo report 12',
             'acm_class': 'F.2.2; I.2.7',
             'msc_class': '14J26'
         })
     )
     mock_load.return_value = (mock_submission, [])
     mock_save.return_value = (mock_submission, [])
     params = MultiDict({
         'doi': '10.0001/123456',
         'journal_ref': 'foo journal 10 2010: 12-345',
         'report_num': 'foo report 12',
         'acm_class': 'F.2.2; I.2.7',
         'msc_class': '14J26'
     })
     _, code, _ = metadata.optional('POST', params, self.session,
                                    submission_id)
     self.assertEqual(code, status.OK, "Returns 200 OK")
     self.assertEqual(mock_save.call_count, 0, "No events are generated")
예제 #2
0
    def test_post_request_with_some_changes(self, mock_load, mock_save):
        """POST request with only some changed data."""
        submission_id = 2
        mock_submission = mock.MagicMock(
            submission_id=submission_id,
            is_finalized=False,
            metadata=mock.MagicMock(**{
                'doi': '10.0001/123456',
                'journal_ref': 'foo journal 10 2010: 12-345',
                'report_num': 'foo report 12',
                'acm_class': 'F.2.2; I.2.7',
                'msc_class': '14J26'
            })
        )
        mock_load.return_value = (mock_submission, [])
        mock_save.return_value = (mock_submission, [])
        params = MultiDict({
            'doi': '10.0001/123456',
            'journal_ref': 'foo journal 10 2010: 12-345',
            'report_num': 'foo report 13',
            'acm_class': 'F.2.2; I.2.7',
            'msc_class': '14J27'
        })
        _, code, _ = metadata.optional('POST', params, self.session,
                                       submission_id)
        self.assertEqual(code, status.OK, "Returns 200 OK")
        self.assertEqual(mock_save.call_count, 1, "Events are generated")

        event_types = [type(ev) for ev in mock_save.call_args[0]]
        self.assertIn(events.SetReportNumber, event_types, "Sets report_num")
        self.assertIn(events.SetMSCClassification, event_types, "Sets msc")
        self.assertEqual(len(event_types), 2, "Only two events are generated")
예제 #3
0
 def test_post_request_with_required_data(self, mock_load, mock_save):
     """POST request with all fields."""
     submission_id = 2
     mock_submission = mock.MagicMock(submission_id=submission_id,
                                      is_finalized=False,
                                      metadata=mock.MagicMock())
     mock_load.return_value = (mock_submission, [])
     mock_save.return_value = (mock_submission, [])
     params = MultiDict({
         'doi': '10.0001/123456',
         'journal_ref': 'foo journal 10 2010: 12-345',
         'report_num': 'foo report 12',
         'acm_class': 'F.2.2; I.2.7',
         'msc_class': '14J26'
     })
     data, code, headers = metadata.optional('POST', params, self.session,
                                             submission_id)
     self.assertEqual(code, status.OK, "Returns 200 OK")
     event_types = [type(ev) for ev in mock_save.call_args[0]]
     self.assertIn(events.SetDOI, event_types, "Sets submission DOI")
     self.assertIn(events.SetJournalReference, event_types,
                   "Sets journal references")
     self.assertIn(events.SetReportNumber, event_types,
                   "Sets report number")
     self.assertIn(events.SetACMClassification, event_types,
                   "Sets ACM classification")
     self.assertIn(events.SetMSCClassification, event_types,
                   "Sets MSC classification")
예제 #4
0
 def test_get_request_with_submission(self, mock_load):
     """GET request with a submission ID."""
     submission_id = 2
     mock_load.return_value = (
         mock.MagicMock(submission_id=submission_id), []
     )
     data, code, headers = metadata.optional(
         'GET', MultiDict(), self.session, submission_id)
     self.assertEqual(code, status.OK, "Returns 200 OK")
     self.assertIsInstance(data['form'], Form,
                           "Response data includes a form")
예제 #5
0
    def test_save_error_is_raised(self, mock_load, mock_save):
        """POST request results in an SaveError exception."""
        submission_id = 2
        mock_submission = mock.MagicMock(
            submission_id=submission_id,
            is_finalized=False,
            metadata=mock.MagicMock()
        )
        mock_load.return_value = (mock_submission, [])

        def raise_save_error(*args, **kwargs):
            raise events.SaveError('nope')

        mock_save.side_effect = raise_save_error
        params = MultiDict({
            'doi': '10.0001/123456',
            'journal_ref': 'foo journal 10 2010: 12-345',
            'report_num': 'foo report 12',
            'acm_class': 'F.2.2; I.2.7',
            'msc_class': '14J26'
        })
        with self.assertRaises(InternalServerError):
            metadata.optional('POST', params, self.session, submission_id)