コード例 #1
0
def test_storage():
    """Test Firebase Storage by managing a test file."""

    # Get the path to your service account.
    from dotenv import dotenv_values
    config = dotenv_values('./env')
    key_path = config['GOOGLE_APPLICATION_CREDENTIALS']
    bucket_name = config['FIREBASE_STORAGE_BUCKET']

    # Initialize Firebase.
    firebase.initialize_firebase(key_path, bucket_name)

    # Define file names.
    bucket_folder = 'tests/assets/pdfs'
    destination_blob_name = 'tests/assets/pdfs/pandas_cheat_sheet.pdf'
    local_folder = './assets/pdfs'
    source_file_name = './assets/pdfs/Pandas_Cheat_Sheet.pdf'
    download_folder = './assets/downloads/pdfs'
    download_file_name = './assets/downloads/pdfs/Pandas_Cheat_Sheet.pdf'
    file_name = 'pandas_cheat_sheet.pdf'
    file_copy = 'pandas_cheat_sheet_copy.pdf'
    newfile_name = 'tests/assets/pdfs/' + file_copy

    # Upload a file to a Firebase Storage bucket, with and without bucket name.
    firebase.upload_file(destination_blob_name, source_file_name)
    firebase.upload_file(destination_blob_name, source_file_name, bucket_name)

    # Upload all files in a folder to a Firebase Storage bucket, with and without bucket name.
    firebase.upload_files(bucket_folder, local_folder)
    firebase.upload_files(bucket_folder, local_folder, bucket_name)

    # List all files in the Firebase Storage bucket folder, with and without bucket name.
    files = firebase.list_files(bucket_folder)
    assert isinstance(files, list)
    files = firebase.list_files(bucket_folder, bucket_name)
    assert isinstance(files, list)

    # Download a file from Firebase Storage, with and without bucket name.
    firebase.download_file(destination_blob_name, download_file_name)
    firebase.download_file(destination_blob_name, download_file_name, bucket_name)

    # Download all files in a given Firebase Storage folder, with and without bucket name.
    firebase.download_files(bucket_folder, download_folder)
    firebase.download_files(bucket_folder, download_folder, bucket_name)

    # Rename a file in the Firebase Storage bucket, with and without bucket name.
    firebase.rename_file(bucket_folder, file_name, newfile_name)
    firebase.rename_file(bucket_folder, file_name, newfile_name, bucket_name)

    # Delete a file from the Firebase Storage bucket, with and without bucket name.
    firebase.delete_file(bucket_folder, file_copy)
    firebase.delete_file(bucket_folder, file_copy, bucket_name)
コード例 #2
0
def test_storage():
    """Test Firebase Storage by managing a test file."""

    # Initialize Firebase.
    env = environ.Env()
    env.read_env('../.env')
    credentials = env('GOOGLE_APPLICATION_CREDENTIALS')
    os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials
    firebase.initialize_firebase()

    # Define file names.
    bucket_name = 'cannlytics.appspot.com'
    bucket_folder = 'tests/assets/pdfs'
    destination_blob_name = 'tests/assets/pdfs/pandas_cheat_sheet.pdf'
    local_folder = './assets/pdfs'
    source_file_name = './assets/pdfs/Pandas_Cheat_Sheet.pdf'
    download_folder = './assets/downloads/pdfs'
    download_file_name = './assets/downloads/pdfs/Pandas_Cheat_Sheet.pdf'
    file_name = 'pandas_cheat_sheet.pdf'
    file_copy = 'pandas_cheat_sheet_copy.pdf'
    newfile_name = 'tests/assets/pdfs/' + file_copy

    # Upload a file to a Firebase Storage bucket.
    firebase.upload_file(bucket_name, destination_blob_name, source_file_name)

    # Upload all files in a folder to a Firebase Storage bucket.
    firebase.upload_files(bucket_name, bucket_folder, local_folder)

    # List all files in the Firebase Storage bucket folder.
    files = firebase.list_files(bucket_name, bucket_folder)
    assert isinstance(files, list) == True

    # Download a file from Firebase Storage.
    firebase.download_file(bucket_name, destination_blob_name, download_file_name)

    # Download all files in a given Firebase Storage folder.
    firebase.download_files(bucket_name, bucket_folder, download_folder)

    # Rename a file in the Firebase Storage bucket.
    firebase.rename_file(bucket_name, bucket_folder, file_name, newfile_name)

    # Delete a file from the Firebase Storage bucket.
    firebase.delete_file(bucket_name, bucket_folder, file_copy)
コード例 #3
0
ファイル: auth.py プロジェクト: cannlytics/cannlytics-website
def delete_signature(request, *args, **argv): #pylint: disable=unused-argument
    """Delete a user's signature.
    Args:
        request (HTTPRequest): A request to get the user's session.
    Returns:
        (JsonResponse): A JSON response containing the user's claims.
    """
    user_claims = authenticate_request(request)
    uid = user_claims['uid']
    entry = {
        'signature_created_at': '',
        'signature_url': '',
        'signature_ref': '',
    }
    delete_file(BUCKET_NAME, f'users/{uid}/user_settings/signature.png')
    update_document(f'users/{uid}', entry)
    update_document(f'users/{uid}/user_settings/signature', entry)
    create_log(f'users/{uid}/logs', user_claims, 'Deleted signature.', 'signature', 'signature_delete', [{'deleted_at': datetime.now().isoformat()}])
    return JsonResponse({'success': True, 'message': 'Signature deleted.'})