Ejemplo n.º 1
0
    def test__init_auth_flow(self, mock_input, mock_client, mock_log, _):
        GDrive._init_auth_flow()

        self.assertTrue(mock_client.flow_from_clientsecrets.called)
        self.assertFalse(mock_log.error.called)
        self.assertTrue(mock_log.critical.called)
        self.assertTrue(mock_input.called)
Ejemplo n.º 2
0
    def test_upload_file(self, mock_media, mock_log, mock_drive):
        GDrive._upload_file(mock_drive, "test", "test")

        self.assertTrue(mock_drive._get_name.called)
        self.assertTrue(mock_media.called)
        self.assertTrue(mock_drive.create.called)
        self.assertTrue(mock_log.debug.called)
Ejemplo n.º 3
0
    def test_upload_log(self, _, mock_shutil, mock_os, mock_log, mock_drive):
        GDrive.upload_log(mock_drive)

        self.assertTrue(mock_os.path.join.called)
        self.assertTrue(mock_shutil.copyfile.called)
        self.assertTrue(mock_drive._upload_file.called)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        self.assertTrue(mock_os.remove.called)
Ejemplo n.º 4
0
    def test_upload_log_fails(self, mock_shutil, mock_os, mock_log,
                              mock_drive):
        mock_drive._upload_file.return_value = None
        GDrive.upload_log(mock_drive)

        self.assertTrue(mock_os.path.join.called)
        self.assertTrue(mock_shutil.copyfile.called)
        self.assertTrue(mock_drive._upload_file.called)
        self.assertFalse(mock_log.debug.called)
        self.assertTrue(mock_log.warning.called)
        self.assertTrue(mock_os.remove.called)
Ejemplo n.º 5
0
    def test_auth(self, mock_mail, mock_discovery, mock_file, mock_log,
                  mock_drive):
        GDrive.auth(mock_drive)

        self.assertTrue(mock_file.Storage.called)
        self.assertTrue(mock_drive._auth_from_file.called)
        self.assertTrue(mock_log.info.called)
        self.assertFalse(mock_drive._init_auth_flow.called)
        self.assertTrue(mock_discovery.build.called)
        self.assertFalse(mock_log.critical.called)
        self.assertFalse(mock_mail.called)
Ejemplo n.º 6
0
    def test_auth_fail_file(self, mock_mail, mock_discovery, mock_file,
                            mock_log, mock_drive):
        mock_drive._auth_from_file.side_effect = OAuthFailure()
        GDrive.auth(mock_drive)

        self.assertTrue(mock_file.Storage.called)
        self.assertTrue(mock_drive._auth_from_file.called)
        self.assertFalse(mock_log.info.called)
        self.assertTrue(mock_drive._init_auth_flow.called)
        self.assertTrue(mock_discovery.build.called)
        self.assertFalse(mock_log.critical.called)
        self.assertFalse(mock_mail.called)
Ejemplo n.º 7
0
    def test__upload(self, mock_report, mock_db, mock_log, mock_drive):
        tasks_list = ["test task"]
        mock_drive._create_folder.return_value = "test"
        GDrive._upload(tasks_list)

        self.assertTrue(mock_drive._get_upload_service.called)
        self.assertTrue(mock_drive._set_uploading.called)
        self.assertTrue(mock_drive._create_folder.called)
        self.assertTrue(mock_drive._upload_files.called)
        self.assertTrue(mock_drive._share.called)
        self.assertTrue(mock_log.debug.called)
        self.assertTrue(mock_drive._remove.called)
        self.assertTrue(mock_report.called)
        self.assertFalse(mock_db.connect.called)
Ejemplo n.º 8
0
    def test__upload_folder_fails(self, mock_report, mock_db, mock_log,
                                  mock_drive):
        tasks_list = ["test task"]
        mock_drive._create_folder.return_value = None
        mock_drive._upload_files.side_effect = UnexpectedBodyError(
            "test", "text")
        GDrive._upload(tasks_list)

        self.assertTrue(mock_drive._get_upload_service.called)
        self.assertTrue(mock_drive._set_uploading.called)
        self.assertTrue(mock_drive._create_folder.called)
        self.assertTrue(mock_drive._upload_files.called)
        self.assertFalse(mock_drive._share.called)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_drive._remove.called)
        self.assertTrue(mock_report.called)
        self.assertTrue(mock_db.connect.called)
Ejemplo n.º 9
0
    def test__get_mimetype_video(self, _, __):
        expected = "video/mp4"
        output = GDrive._get_mimetype('/home/user/test.mp4')

        self.assertEqual(expected, output)
Ejemplo n.º 10
0
    def test__get_upload_service(self, mock_discovery, _, mock_drive):
        GDrive._get_upload_service()

        self.assertTrue(mock_drive._auth_from_file.called)
        self.assertTrue(mock_discovery.build.called)
Ejemplo n.º 11
0
    def test__share_callback(self, mock_log, _):
        GDrive._share_callback(None, Response(), None)

        self.assertTrue(mock_log.debug.called)
Ejemplo n.º 12
0
    def test__share_callback_error(self, mock_log, _):
        GDrive._share_callback(None, None, "test")

        self.assertTrue(mock_log.debug.called)
Ejemplo n.º 13
0
    def test__auth_from_file(self, mock_log, mock_drive):
        mock_drive.get.return_value = Credentials()
        GDrive._auth_from_file(mock_drive)

        self.assertTrue(mock_drive.get.called)
        self.assertFalse(mock_log.warning.called)
Ejemplo n.º 14
0
    def test__share(self, _, mock_drive):
        GDrive._share(mock_drive, mock_drive, "test", "test")

        self.assertTrue(mock_drive.add.called)
        self.assertTrue(mock_drive.execute.called)
Ejemplo n.º 15
0
    def test__auth_from_file_fail(self, mock_log, mock_drive):
        with self.failUnlessRaises(OAuthFailure):
            GDrive._auth_from_file(mock_drive)

        self.assertTrue(mock_drive.get.called)
        self.assertTrue(mock_log.warning.called)
Ejemplo n.º 16
0
    def test__upload_files(self, mock_os, _, mock_drive):
        GDrive._upload_files(mock_drive, "test", "test")

        self.assertTrue(mock_os.path.join.called)
        self.assertTrue(mock_os.listdir.called)
Ejemplo n.º 17
0
    def test__create_folder(self, mock_log, mock_drive):
        GDrive._create_folder(mock_drive, "test")

        self.assertTrue(mock_drive._get_name.called)
        self.assertTrue(mock_drive.create.called)
        self.assertTrue(mock_log.debug.called)