|
14 | 14 |
|
15 | 15 | """Integration tests for firebase_admin.dataconnect module (execute_graphql).""" |
16 | 16 |
|
| 17 | +import os |
| 18 | +import subprocess |
17 | 19 | import pytest |
18 | 20 |
|
19 | | -from firebase_admin import dataconnect, exceptions |
| 21 | +import firebase_admin |
| 22 | +from firebase_admin import _utils, dataconnect, exceptions |
| 23 | +from integration import conftest |
| 24 | + |
| 25 | +def integration_conf(request): |
| 26 | + host_override = os.environ.get('DATA_CONNECT_EMULATOR_HOST') |
| 27 | + if host_override: |
| 28 | + return _utils.EmulatorAdminCredentials(), 'fake-project-id' |
| 29 | + |
| 30 | + return conftest.integration_conf(request) |
| 31 | + |
| 32 | +@pytest.fixture(scope='module', autouse=True) |
| 33 | +def default_app(request): |
| 34 | + cred, project_id = integration_conf(request) |
| 35 | + return firebase_admin.initialize_app( |
| 36 | + cred, options={'projectId': project_id}) |
| 37 | + |
20 | 38 |
|
21 | 39 | CONNECTOR_CONFIG = dataconnect.ConnectorConfig( |
22 | 40 | location='us-west2', |
|
122 | 140 | user_deleteMany(all: true) |
123 | 141 | }""" |
124 | 142 |
|
| 143 | +@pytest.fixture(autouse=True) |
| 144 | +def setup_and_cleanup_database(): |
| 145 | + """Initializes database via seed.sh before each test and wipes it via cleanup.sh afterwards.""" |
| 146 | + script_dir = os.path.dirname(__file__) |
| 147 | + seed_script = os.path.join(script_dir, 'emulators', 'seed.sh') |
| 148 | + cleanup_script = os.path.join(script_dir, 'emulators', 'cleanup.sh') |
| 149 | + |
| 150 | + subprocess.run(['bash', seed_script], check=True) |
| 151 | + yield |
| 152 | + subprocess.run(['bash', cleanup_script], check=True) |
| 153 | + |
125 | 154 | # Impersonation Options |
126 | 155 | OPTS_UNAUTHORIZED_CLAIMS = dataconnect.GraphqlOptions( |
127 | 156 | impersonate=dataconnect.Impersonation.unauthenticated() |
|
140 | 169 | }) |
141 | 170 | ) |
142 | 171 |
|
143 | | - |
144 | 172 | class TestExecuteGraphql: |
145 | 173 | """Integration tests for execute_graphql method.""" |
146 | 174 |
|
@@ -192,7 +220,6 @@ def test_execute_graphql_mutation(self): |
192 | 220 | QUERY_GET_EMAIL, options=get_email_options |
193 | 221 | ) |
194 | 222 | assert query_email_resp.data['email'] == UPDATED_FRED_EMAIL |
195 | | - dc_client.execute_graphql(UPSERT_FRED_EMAIL) |
196 | 223 |
|
197 | 224 |
|
198 | 225 | class TestExecuteGraphqlRead: |
@@ -265,7 +292,6 @@ def test_execute_graphql_impersonated_mutation_authenticated(self): |
265 | 292 | query_options = dataconnect.GraphqlOptions(variables={'id': {'id': user_id}}) |
266 | 293 | query_resp = dc_client.execute_graphql(QUERY_GET_USER_BY_ID, options=query_options) |
267 | 294 | assert query_resp.data['user'] == FREDRICK_USER |
268 | | - dc_client.execute_graphql(UPSERT_FRED_USER) |
269 | 295 |
|
270 | 296 | def test_execute_graphql_impersonated_mutation_unauthenticated_fails(self): |
271 | 297 | """Tests mutation with unauthenticated impersonation fails.""" |
|
0 commit comments