|
25 | 25 |
|
26 | 26 | CREDENTIAL = credentials.Certificate(
|
27 | 27 | testutils.resource_filename('service_account.json'))
|
28 |
| -GCLOUD_PROJECT = 'GCLOUD_PROJECT' |
29 | 28 | CONFIG_JSON = firebase_admin._FIREBASE_CONFIG_ENV_VAR
|
30 | 29 |
|
31 | 30 | # This fixture will ignore the environment variable pointing to the default
|
@@ -295,27 +294,26 @@ def test_project_id_from_credentials(self):
|
295 | 294 | assert app.project_id == 'mock-project-id'
|
296 | 295 |
|
297 | 296 | def test_project_id_from_environment(self):
|
298 |
| - project_id = os.environ.get(GCLOUD_PROJECT) |
299 |
| - os.environ[GCLOUD_PROJECT] = 'env-project' |
300 |
| - try: |
301 |
| - app = firebase_admin.initialize_app(testutils.MockCredential(), name='myApp') |
302 |
| - assert app.project_id == 'env-project' |
303 |
| - finally: |
304 |
| - if project_id: |
305 |
| - os.environ[GCLOUD_PROJECT] = project_id |
306 |
| - else: |
307 |
| - del os.environ[GCLOUD_PROJECT] |
| 297 | + variables = ['GOOGLE_CLOUD_PROJECT', 'GCLOUD_PROJECT'] |
| 298 | + for idx, var in enumerate(variables): |
| 299 | + old_project_id = os.environ.get(var) |
| 300 | + new_project_id = 'env-project-{0}'.format(idx) |
| 301 | + os.environ[var] = new_project_id |
| 302 | + try: |
| 303 | + app = firebase_admin.initialize_app( |
| 304 | + testutils.MockCredential(), name='myApp{0}'.format(var)) |
| 305 | + assert app.project_id == new_project_id |
| 306 | + finally: |
| 307 | + if old_project_id: |
| 308 | + os.environ[var] = old_project_id |
| 309 | + else: |
| 310 | + del os.environ[var] |
308 | 311 |
|
309 | 312 | def test_no_project_id(self):
|
310 |
| - project_id = os.environ.get(GCLOUD_PROJECT) |
311 |
| - if project_id: |
312 |
| - del os.environ[GCLOUD_PROJECT] |
313 |
| - try: |
| 313 | + def evaluate(): |
314 | 314 | app = firebase_admin.initialize_app(testutils.MockCredential(), name='myApp')
|
315 | 315 | assert app.project_id is None
|
316 |
| - finally: |
317 |
| - if project_id: |
318 |
| - os.environ[GCLOUD_PROJECT] = project_id |
| 316 | + testutils.run_without_project_id(evaluate) |
319 | 317 |
|
320 | 318 | def test_non_string_project_id(self):
|
321 | 319 | options = {'projectId': {'key': 'not a string'}}
|
|
0 commit comments