def test_cli_gsheet(self): with cli(argv=['-f', 'csv', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.csv'))) with cli(argv=['-f', 'html.zip', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.html.zip'))) with cli(argv=['-f', 'ods', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.ods'))) with cli(argv=['-f', 'pdf', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.pdf'))) with cli(argv=['-f', 'tsv', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.tsv'))) with cli(argv=['-f', 'xlsx', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.xlsx'))) with self.assertRaisesRegex(Exception, 'Unknown format "unsupported"'): with cli(argv=['-f', 'unsupported', '-o', self.out_dir, self.GSHEET_FILE], credentials=self.credentials) as app: app.run()
def test_cli_unsupported(self): file, filename = tempfile.mkstemp('.tmp') os.close(file) with self.assertRaisesRegex(Exception, 'Unknown Google document extension ".tmp"'): with cli(argv=['-f', 'txt', '-o', self.out_dir, filename], credentials=self.credentials) as app: app.run() os.remove(filename)
def test_cli_2pdf(self): with cli(argv=['-f', 'pdf', '-o', self.out_dir, self.FIXTURE_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.pdf'))) # check that file has correct content with open(os.path.join(self.out_dir, 'example.pdf'), 'rb') as file: PdfFileReader(file)
def test_cli_2html(self): with cli(argv=['-f', 'html', '-o', self.out_dir, self.FIXTURE_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.html'))) # check that file has correct content with open(os.path.join(self.out_dir, 'example.html'), 'r') as file: self.assertRegexpMatches(file.read(), 'gdoc_down example file')
def test_cli_gdoc_2docx(self): with cli(argv=['-f', 'docx', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.docx'))) # check that file has correct content doc = DocxDocument(os.path.join(self.out_dir, 'example.docx')) self.assertRegex(doc.paragraphs[0].text, 'gdoc_down example file')
def test_cli_2docx(self): with cli(argv=['-f', 'docx', '-o', self.out_dir, self.FIXTURE_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.docx'))) # check that file has correct content doc = DocxDocument(os.path.join(self.out_dir, 'example.docx')) self.assertRegexpMatches(doc.paragraphs[0].text, 'gdoc_down example file')
def test_cli_gdoc_2html(self): with cli(argv=['-f', 'html', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.html'))) # check that file has correct content with open(os.path.join(self.out_dir, 'example.html'), 'r') as file: self.assertRegex(file.read(), 'gdoc_down example file')
def test_cli_gdoc_2pdf(self): with cli(argv=['-f', 'pdf', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.pdf'))) # check that file has correct content with open(os.path.join(self.out_dir, 'example.pdf'), 'rb') as file: PdfFileReader(file)
def test_cli_gdoc_2odt(self): with cli(argv=['-f', 'odt', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.odt'))) # check that file has correct content doc = opendocument.load(os.path.join(self.out_dir, 'example.odt')) root = ElementTree.fromstring(doc.toXml().encode('utf-8')) self.assertRegex(GDocDown.get_element_text(root), 'gdoc_down example file')
def test_cli_2odt(self): with cli(argv=['-f', 'odt', '-o', self.out_dir, self.FIXTURE_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.odt'))) # check that file has correct content doc = opendocument.load(os.path.join(self.out_dir, 'example.odt')) root = ElementTree.fromstring(doc.toXml().encode('utf-8')) self.assertRegexpMatches(GDocDown.get_element_text(root), 'gdoc_down example file')
def test_cli_gslides(self): with cli(argv=['-f', 'odp', '-o', self.out_dir, self.GSLIDES_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.odp'))) with cli(argv=['-f', 'pdf', '-o', self.out_dir, self.GSLIDES_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.pdf'))) with cli(argv=['-f', 'pptx', '-o', self.out_dir, self.GSLIDES_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.pptx'))) with cli(argv=['-f', 'txt', '-o', self.out_dir, self.GSLIDES_FILE], credentials=self.credentials) as app: app.run() self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.txt'))) with self.assertRaisesRegex(Exception, 'Unknown format "unsupported"'): with cli(argv=['-f', 'unsupported', '-o', self.out_dir, self.GSLIDES_FILE], credentials=self.credentials) as app: app.run()
def test_cli_gdoc_2tex(self): with cli(argv=['-f', 'tex', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.tex'))) # check that file has correct content with open(os.path.join(self.out_dir, 'example.tex'), 'r') as file: content = file.read() self.assertRegex(content, 'gdoc_down example file') self.assertNotIn('[a]', content)
def test_cli_2rtf(self): with cli(argv=['-f', 'rtf', '-o', self.out_dir, self.FIXTURE_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.rtf'))) # check that file has correct content if sys.version_info < (3, 0, 0): rtf2xml.ParseRtf.ParseRtf( in_file=os.path.join(self.out_dir, 'example.rtf'), out_file=os.path.join(self.out_dir, 'example.xml'), ).parse_rtf() root = ElementTree.parse(os.path.join(self.out_dir, 'example.xml')) self.assertRegexpMatches(GDocDown.get_element_text(root.getroot()), 'gdoc_down example file')
def test_cli_gdoc_2rtf(self): with cli(argv=['-f', 'rtf', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.rtf'))) # check that file has correct content if sys.version_info < (3, 0, 0): rtf2xml.ParseRtf.ParseRtf( in_file=os.path.join(self.out_dir, 'example.rtf'), out_file=os.path.join(self.out_dir, 'example.xml'), ).parse_rtf() root = ElementTree.parse(os.path.join(self.out_dir, 'example.xml')) self.assertRegex(GDocDown.get_element_text(root.getroot()), 'gdoc_down example file')
def test_cli_provide_extension_and_output_filename(self): with self.assertRaisesRegex(Exception, 'Ouput file path and extension cannot both be specified'): with cli(argv=['-f', 'docx', '-e', 'other', '-o', os.path.join(self.out_dir, 'example.docx'), self.GDOC_FILE], credentials=self.credentials) as app: app.run()
def test_cli_gdoc_2unsupported(self): with self.assertRaisesRegex(Exception, 'Unknown format "unsupported"'): with cli(argv=['-f', 'unsupported', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run()
def test_cli_gdoc_2epub(self): with cli(argv=['-f', 'epub', '-o', self.out_dir, self.GDOC_FILE], credentials=self.credentials) as app: app.run() # check that file downloaded self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example.epub')))