From 913f48fd4310b9504fdf2d029867a5729e53e1df Mon Sep 17 00:00:00 2001 From: Jonathan Edey Date: Thu, 12 Oct 2023 13:14:18 -0400 Subject: [PATCH] Optionally load databaseURL and storageBucket from config file. --- .gitignore | 1 + integration/conftest.py | 43 +++++++++++++++++++++++++++++++++---- integration/test_db.py | 14 ++++++------ integration/test_storage.py | 8 +++---- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index e5c1902d5..5c3c81f48 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ dist/ *~ cert.json apikey.txt +test_config.json htmlcov/ .pytest_cache/ .vscode/ diff --git a/integration/conftest.py b/integration/conftest.py index 71f53f612..b8e0f7b3a 100644 --- a/integration/conftest.py +++ b/integration/conftest.py @@ -27,6 +27,8 @@ def pytest_addoption(parser): '--cert', action='store', help='Service account certificate file for integration tests.') parser.addoption( '--apikey', action='store', help='API key file for integration tests.') + parser.addoption( + '--config', action='store', help='Config file for integration tests.') def _get_cert_path(request): cert = request.config.getoption('--cert') @@ -48,18 +50,51 @@ def project_id(request): _, project_id = integration_conf(request) return project_id +@pytest.fixture(scope='session') +def cred(request): + cred, _ = integration_conf(request) + return cred + +@pytest.fixture(scope='session') +def test_config(request): + test_config_path = request.config.getoption('--config') + if test_config_path: + with open(test_config_path,'r') as test_config_file: + test_config = json.load(test_config_file) + if not test_config: + raise ValueError('Failed to load config from path. Verify the path to the ' + 'test_config file is valid') + return test_config + return None + +@pytest.fixture(scope='session') +def databaseURL(project_id, test_config): + if test_config: + databaseURL = test_config.get('databaseURL') + if databaseURL: + return databaseURL + return 'https://{0}.firebaseio.com'.format(project_id) + +@pytest.fixture(scope='session') +def storageBucket(project_id, test_config): + if test_config: + storageBucket = test_config.get('storageBucket') + if storageBucket: + return storageBucket + return '{0}.appspot.com'.format(project_id) + + @pytest.fixture(autouse=True, scope='session') -def default_app(request): +def default_app(cred, databaseURL, storageBucket): """Initializes the default Firebase App instance used for all integration tests. This fixture is attached to the session scope, which ensures that it runs only once during a test session. It is also marked as autouse, and therefore runs automatically without test cases having to call it explicitly. """ - cred, project_id = integration_conf(request) ops = { - 'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id), - 'storageBucket' : '{0}.appspot.com'.format(project_id) + 'databaseURL' : databaseURL, + 'storageBucket' : storageBucket } return firebase_admin.initialize_app(cred, ops) diff --git a/integration/test_db.py b/integration/test_db.py index c448436d6..956fe0c1a 100644 --- a/integration/test_db.py +++ b/integration/test_db.py @@ -35,10 +35,10 @@ def integration_conf(request): @pytest.fixture(scope='module') -def app(request): - cred, project_id = integration_conf(request) +def app(request, databaseURL): + cred, _ = integration_conf(request) ops = { - 'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id), + 'databaseURL' : databaseURL, } return firebase_admin.initialize_app(cred, ops, name='integration-db') @@ -327,11 +327,11 @@ def test_filter_by_value(self, testref): @pytest.fixture(scope='module') -def override_app(request, update_rules): +def override_app(request, update_rules, databaseURL): del update_rules cred, project_id = integration_conf(request) ops = { - 'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id), + 'databaseURL' : databaseURL, 'databaseAuthVariableOverride' : {'uid' : 'user1'} } app = firebase_admin.initialize_app(cred, ops, 'db-override') @@ -339,11 +339,11 @@ def override_app(request, update_rules): firebase_admin.delete_app(app) @pytest.fixture(scope='module') -def none_override_app(request, update_rules): +def none_override_app(request, update_rules, databaseURL): del update_rules cred, project_id = integration_conf(request) ops = { - 'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id), + 'databaseURL' : databaseURL, 'databaseAuthVariableOverride' : None } app = firebase_admin.initialize_app(cred, ops, 'db-none-override') diff --git a/integration/test_storage.py b/integration/test_storage.py index 729190950..03e415bb9 100644 --- a/integration/test_storage.py +++ b/integration/test_storage.py @@ -18,12 +18,12 @@ from firebase_admin import storage -def test_default_bucket(project_id): +def test_default_bucket(storageBucket): bucket = storage.bucket() - _verify_bucket(bucket, '{0}.appspot.com'.format(project_id)) + _verify_bucket(bucket, storageBucket) -def test_custom_bucket(project_id): - bucket_name = '{0}.appspot.com'.format(project_id) +def test_custom_bucket(storageBucket): + bucket_name = storageBucket bucket = storage.bucket(bucket_name) _verify_bucket(bucket, bucket_name) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy