Ejemplo n.º 1
0
 def test_upload_single_sdc_data_handle_sdc_formatting_error(self):
     self.mock_format_sdc_payload.side_effect = ValueError('mock error', '')
     with self.assertRaises(SdcException) as se:
         upload_single_sdc_data(self.mock_file_page, self.base_sdc)
     self.assertTrue('mock error' in se.exception.log)
     self.mock__submit_data.assert_not_called()
     self.mock_pwb_touch.assert_not_called()
Ejemplo n.º 2
0
 def test_upload_single_sdc_data_handle_upload_error(self):
     self.mock__submit_data.side_effect = pywikibot.data.api.APIError(
         'mock error', '')  # noqa:E501
     with self.assertRaises(SdcException) as se:
         upload_single_sdc_data(self.mock_file_page, self.base_sdc)
     self.assertTrue('mock error' in se.exception.log)
     self.mock_pwb_touch.assert_not_called()
Ejemplo n.º 3
0
 def test_upload_single_sdc_data_null_edit_T275981_adds_explanation(self):
     self.mock_pwb_touch.side_effect = pywikibot.i18n.TranslationError('Fo')
     with self.assertRaises(pywikibot.i18n.TranslationError):
         upload_single_sdc_data(self.mock_file_page,
                                self.base_sdc,
                                null_edit=True)
     self.mock__submit_data.assert_called_once()
     self.mock_pwb_touch.assert_called()
Ejemplo n.º 4
0
 def test_upload_single_sdc_data_nuke_triggers_clear(self):
     upload_single_sdc_data(self.mock_file_page,
                            self.base_sdc,
                            strategy="Nuke")
     self.mock__submit_data.assert_called_once()
     payload = self.mock__submit_data.call_args[0][1]
     self.assertEqual(payload.get('clear', 0), 1)
     self.mock_pwb_touch.assert_not_called()
Ejemplo n.º 5
0
 def test_upload_single_sdc_data_any_non_nuke_does_not_trigger_clear(self):
     strategies = (None, 'new', 'blind', 'add', 'foo')
     for strategy in strategies:
         upload_single_sdc_data(self.mock_file_page,
                                self.base_sdc,
                                strategy=strategy)
     self.assertEqual(self.mock__submit_data.call_count, len(strategies))
     for num, call in enumerate(self.mock__submit_data.call_args_list):
         payload = call[0][1]
         self.assertEqual(payload.get('clear', 0), 0, msg=strategies[num])
Ejemplo n.º 6
0
def main():
    """Run main process."""
    args = handle_args()
    sdc_data = _load_file(args.data)
    site = _load_site(args.beta)

    # run
    if args.filename:
        try:
            num = sdc_upload.upload_single_sdc_data(args.filename,
                                                    sdc_data,
                                                    target_site=site,
                                                    strategy=args.strategy,
                                                    summary=args.summary,
                                                    null_edit=args.null_edit)
        except SdcException as se:
            pywikibot.output('{0} - {1}'.format(args.filename, se.log))
        else:
            pywikibot.output(
                '{0} - Successfully uploaded with {1} statements'.format(
                    args.filename, num))
    else:
        total = {'files': 0, 'num': 0}
        for filename, data in sdc_data.items():
            try:
                num = sdc_upload.upload_single_sdc_data(
                    filename,
                    data,
                    target_site=site,
                    strategy=args.strategy,
                    summary=args.summary,
                    null_edit=args.null_edit)
            except SdcException as se:
                pywikibot.output('{0} - {1}'.format(filename, se.log))
            else:
                total['files'] += 1
                total['num'] += num
                pywikibot.output(
                    '{0} - Successfully uploaded with {1} statements'.format(
                        filename, num))
        pywikibot.output(
            'Successfully uploaded {num} statements to {files} files'.format(
                **total))
Ejemplo n.º 7
0
 def test_upload_single_sdc_data_no_null_edit_no_touch(self):
     upload_single_sdc_data(self.mock_file_page,
                            self.base_sdc,
                            null_edit=False)
     self.mock__submit_data.assert_called_once()
     self.mock_pwb_touch.assert_not_called()