def do_GET(self): # get the query string variables self.urlparser = urlparse.urlparse(self.path) self.query_string = self.urlparser.query self.query_dict = urlparse.parse_qs(self.query_string) # get the url and output_file self.url = self.query_dict.get('url', [None, ])[0] self.output_file = self.query_dict.get('output_file', [None, ])[0] # return error if url or output_file are missing if not self.url or not self.output_file: self.handle_404("url and output_file params are required") return None # convert all query objects from list to single items options_dict = {} for k, v in self.query_dict.items(): options_dict[k] = v[0] wkhtp = WKhtmlToPdf(self.url, self.output_file, **options_dict) output_file = wkhtp.render() # send json response if output_file[0]: self.handle_200("the file has been saved", output_file[1]) else: self.handle_500("%s - the file could not be created" % output_file[1])
def do_GET(self): # get the query string variables self.urlparser = urlparse.urlparse(self.path) self.query_string = self.urlparser.query self.query_dict = urlparse.parse_qs(self.query_string) # get the url and output_file self.url = self.query_dict.get('url', [ None, ])[0] self.output_file = self.query_dict.get('output_file', [ None, ])[0] # return error if url or output_file are missing if not self.url or not self.output_file: self.handle_404("url and output_file params are required") return None # convert all query objects from list to single items options_dict = {} for k, v in self.query_dict.items(): options_dict[k] = v[0] wkhtp = WKhtmlToPdf(self.url, self.output_file, **options_dict) output_file = wkhtp.render() # send json response if output_file[0]: self.handle_200("the file has been saved", output_file[1]) else: self.handle_500("%s - the file could not be created" % output_file[1])
class MainTestCase(unittest.TestCase): def setUp(self): self.url = "http://www.example.com" self.output_file = "/tmp/example.pdf" self.wkhtmltopdf = WKhtmlToPdf(self.url, self.output_file) def test_wkhtmltopdf_options(self): # test default options self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--enable-plugins', '--orientation Portrait', '--dpi 100']) # test flash_plugin option self.wkhtmltopdf.flash_plugin = False self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--orientation Portrait', '--dpi 100']) # test orientation option self.wkhtmltopdf.orientation = 'Landscape' self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--orientation Landscape', '--dpi 100']) # test dpi option self.wkhtmltopdf.dpi = 300 self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--orientation Landscape', '--dpi 300']) # test disable_javascript option self.wkhtmltopdf.disable_javascript = True self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--disable-javascript', '--orientation Landscape', '--dpi 300']) # test delay option self.wkhtmltopdf.delay = 1 self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--disable-javascript', '--redirect-delay 1', '--orientation Landscape', '--dpi 300']) # test no_background option self.wkhtmltopdf.no_background = True self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--disable-javascript', '--no-background', '--redirect-delay 1', '--orientation Landscape', '--dpi 300']) # test grayscale option self.wkhtmltopdf.grayscale = True self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--disable-javascript', '--no-background', '--grayscale', '--redirect-delay 1', '--orientation Landscape', '--dpi 300']) def test_wkhtmltopdf_callable(self): wkhtmltopdf(self.url, self.output_file) self.assertTrue(os.path.exists(self.output_file)) def tearDown(self): try: os.remove(self.output_file) except OSError: pass
def setUp(self): self.url = "http://www.example.com" self.output_file = "/tmp/example.pdf" self.wkhtmltopdf = WKhtmlToPdf(self.url, self.output_file)
class MainTestCase(unittest.TestCase): def setUp(self): self.url = "http://www.example.com" self.output_file = "/tmp/example.pdf" self.wkhtmltopdf = WKhtmlToPdf(self.url, self.output_file) def test_wkhtmltopdf_options(self): # test default options self.assertEqual( self.wkhtmltopdf._create_option_list(), ['--enable-plugins', '--orientation Portrait', '--dpi 100']) # test flash_plugin option self.wkhtmltopdf.flash_plugin = False self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--orientation Portrait', '--dpi 100']) # test orientation option self.wkhtmltopdf.orientation = 'Landscape' self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--orientation Landscape', '--dpi 100']) # test dpi option self.wkhtmltopdf.dpi = 300 self.assertEqual(self.wkhtmltopdf._create_option_list(), ['--orientation Landscape', '--dpi 300']) # test disable_javascript option self.wkhtmltopdf.disable_javascript = True self.assertEqual( self.wkhtmltopdf._create_option_list(), ['--disable-javascript', '--orientation Landscape', '--dpi 300']) # test delay option self.wkhtmltopdf.delay = 1 self.assertEqual(self.wkhtmltopdf._create_option_list(), [ '--disable-javascript', '--redirect-delay 1', '--orientation Landscape', '--dpi 300' ]) # test no_background option self.wkhtmltopdf.no_background = True self.assertEqual(self.wkhtmltopdf._create_option_list(), [ '--disable-javascript', '--no-background', '--redirect-delay 1', '--orientation Landscape', '--dpi 300' ]) # test grayscale option self.wkhtmltopdf.grayscale = True self.assertEqual(self.wkhtmltopdf._create_option_list(), [ '--disable-javascript', '--no-background', '--grayscale', '--redirect-delay 1', '--orientation Landscape', '--dpi 300' ]) def test_wkhtmltopdf_callable(self): wkhtmltopdf(self.url, self.output_file) self.assertTrue(os.path.exists(self.output_file)) def tearDown(self): try: os.remove(self.output_file) except OSError: pass