Пример #1
0
def move_document_to_user_folder(resource_id, user):
    logger = LoggingHelper.getDebugLogger()
    client = GoogleDriveHelper.get_docs_client()

    dest_folder = user.get_profile().drive_folder_id
    if not dest_folder:
        logger.debug('Creating folder for {0}'.format(user.username))
        dest_folder = GoogleDriveHelper.create_unistar_folder(user)
        user.get_profile().drive_folder_id = dest_folder
        user.get_profile().save()

    logger.debug('Moving {0} to {1}'.format(resource_id, GoogleDriveHelper._get_unistar_collection_name(user.username)))
    client.files().update(fileId=resource_id, body={"parents":[{'id':dest_folder}]}).execute()
Пример #2
0
    def test_create_unistar_folder(self):
        response = {'id': 'abcdef'}

        requestBuilder = RequestMockBuilder({
            'drive.files.insert': (None, json.dumps(response)),
        })

        GoogleDriveHelper.get_docs_client = Mock()
        GoogleDriveHelper.get_docs_client.return_value = apiclient.discovery.build(
            "drive", "v2", requestBuilder=requestBuilder)

        user = User.objects.create_user('arnaud.breton', '*****@*****.**')
        self.assertEqual(GoogleDriveHelper.create_unistar_folder(user),
                         'abcdef')
Пример #3
0
    def test_create_unistar_folder(self):
        response = {
            'id' : 'abcdef'
        }

        requestBuilder = RequestMockBuilder(
            {
                'drive.files.insert': (None, json.dumps(response)),
            }
        )

        GoogleDriveHelper.get_docs_client = Mock()
        GoogleDriveHelper.get_docs_client.return_value = apiclient.discovery.build("drive", "v2", requestBuilder=requestBuilder)

        user = User.objects.create_user('arnaud.breton','*****@*****.**')
        self.assertEqual(GoogleDriveHelper.create_unistar_folder(user), 'abcdef')
Пример #4
0
def move_document_to_user_folder(resource_id, user):
    logger = LoggingHelper.getDebugLogger()
    client = GoogleDriveHelper.get_docs_client()

    dest_folder = user.get_profile().drive_folder_id
    if not dest_folder:
        logger.debug('Creating folder for {0}'.format(user.username))
        dest_folder = GoogleDriveHelper.create_unistar_folder(user)
        user.get_profile().drive_folder_id = dest_folder
        user.get_profile().save()

    logger.debug('Moving {0} to {1}'.format(
        resource_id,
        GoogleDriveHelper._get_unistar_collection_name(user.username)))
    client.files().update(fileId=resource_id,
                          body={
                              "parents": [{
                                  'id': dest_folder
                              }]
                          }).execute()