def test_should_convert_single_file_using_file_path(
         self, mock_server: MockServer,
         api_end_to_end_test_helper: ApiEndToEndTestHelper):
     api_url = mock_server.add_response('/api/convert',
                                        XML_CONTENT_1,
                                        mimetype=MimeTypes.JATS_XML,
                                        methods=('POST', ))
     LOGGER.debug('api_url: %s', api_url)
     api_end_to_end_test_helper.write_source_file_bytes()
     output_file = api_end_to_end_test_helper.get_output_file()
     main(
         dict_to_args({
             **api_end_to_end_test_helper.get_args(api_url=api_url,
                                                   source_file_list=None), 'source-path':
             '*.pdf'
         }))
     assert output_file.read_bytes() == XML_CONTENT_1
 def test_should_retry_convert_api_call(
         self, mock_server: MockServer,
         api_end_to_end_test_helper: ApiEndToEndTestHelper):
     callbacks = [
         lambda: flask.Response('error', status=500),
         lambda: flask.Response(XML_CONTENT_1, mimetype=MimeTypes.JATS_XML),
     ]
     api_url = mock_server.add_multiple_callbacks_response(
         '/api/convert', callbacks, methods=('POST', ))
     LOGGER.debug('api_url: %s', api_url)
     api_end_to_end_test_helper.write_default_source_files()
     output_file = api_end_to_end_test_helper.get_output_file()
     main(
         dict_to_args({
             **api_end_to_end_test_helper.get_args(api_url=api_url), 'fail-on-error':
             True
         }))
     assert output_file.read_bytes() == XML_CONTENT_1
 def test_should_skip_existing_file(
         self, mock_server: MockServer,
         api_end_to_end_test_helper: ApiEndToEndTestHelper):
     api_url = mock_server.add_response('/api/convert',
                                        XML_CONTENT_2,
                                        mimetype=MimeTypes.JATS_XML,
                                        methods=('POST', ))
     LOGGER.debug('api_url: %s', api_url)
     api_end_to_end_test_helper.write_default_source_files()
     api_end_to_end_test_helper.output_path.mkdir(parents=True,
                                                  exist_ok=True)
     output_file = api_end_to_end_test_helper.get_output_file()
     output_file.write_bytes(XML_CONTENT_1)
     main(
         dict_to_args({
             **api_end_to_end_test_helper.get_args(api_url=api_url), 'resume':
             True
         }))
     assert output_file.read_bytes() == XML_CONTENT_1
 def test_should_convert_single_file_using_file_list(
         self, mock_server: MockServer,
         api_end_to_end_test_helper: ApiEndToEndTestHelper):
     api_url = mock_server.add_response('/api/convert',
                                        XML_CONTENT_1,
                                        mimetype=MimeTypes.JATS_XML,
                                        methods=('POST', ))
     LOGGER.debug('api_url: %s', api_url)
     api_end_to_end_test_helper.write_source_file_bytes()
     api_end_to_end_test_helper.write_source_file_list(
         filename=FILE_LIST_FILENAME_1,
         file_list=[INPUT_FILE_1],
         column='source_url')
     output_file = api_end_to_end_test_helper.get_output_file()
     main(
         dict_to_args(
             api_end_to_end_test_helper.get_args(
                 api_url=api_url, source_file_list=FILE_LIST_FILENAME_1)))
     assert output_file.read_bytes() == XML_CONTENT_1
    def test_should_pass_request_args(
            self, mock_server: MockServer,
            api_end_to_end_test_helper: ApiEndToEndTestHelper):
        received_request_args = {}

        def _callback():
            received_request_args.update(flask.request.args.to_dict())
            return flask.Response(XML_CONTENT_1, mimetype=MimeTypes.JATS_XML)

        api_url = mock_server.add_callback_response('/api/convert',
                                                    _callback,
                                                    methods=('POST', ))
        LOGGER.debug('api_url: %s', api_url)
        api_end_to_end_test_helper.write_default_source_files()
        api_end_to_end_test_helper.output_path.mkdir(parents=True,
                                                     exist_ok=True)
        main(
            dict_to_args({
                **api_end_to_end_test_helper.get_args(api_url=api_url), 'request-args':
                'remove_line_no=n'
            }))
        assert received_request_args.get('remove_line_no') == 'n'