示例#1
0
    def _default(self):
        args = self.app.pargs

        GDocDown(credentials=self.app.credentials).download(
            args.google_file,
            format=args.format,
            out_path=args.out_path,
            extension=args.extension)
示例#2
0
    def test_api_txt(self):
        GDocDown(credentials=self.credentials).download(self.GDOC_FILE,
                                                        format='txt', out_path=os.path.join(self.out_dir, 'example-out.text'))

        # check that file downloaded
        self.assertTrue(os.path.isfile(os.path.join(self.out_dir, 'example-out.text')))

        # check that file has correct content
        with open(os.path.join(self.out_dir, 'example-out.text'), 'r') as file:
            self.assertRegex(file.read().strip(), 'gdoc_down example file')
示例#3
0
    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')
示例#4
0
    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')
示例#5
0
    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')
示例#6
0
    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')
示例#7
0
 def test_get_gdoc_id(self):
     self.assertEqual(
         GDocDown.get_gdoc_id(self.FIXTURE_FILE),
         '1mgPojZVReTAMBIVvt6LSQ59AGTsxx2-myLR9oIYIJ2s')
示例#8
0
 def test_get_credentials(self):
     with mock.patch.object(oauth2client.file.Storage, 'get', return_value=None):
         with mock.patch.object(oauth2client.tools, 'run_flow', return_value=self.credentials):
             gdoc_down = GDocDown()
     self.assertEqual(gdoc_down.credentials, self.credentials)
示例#9
0
 def test_get_google_id(self):
     self.assertEqual(GDocDown.get_google_id(self.GDOC_FILE), '1mgPojZVReTAMBIVvt6LSQ59AGTsxx2-myLR9oIYIJ2s')