Skip to content

Commit 684801d

Browse files
committed
chore: fix integration test lint
1 parent 28e275a commit 684801d

10 files changed

+52
-54
lines changed

integration/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _get_cert_path(request):
3636

3737
def integration_conf(request):
3838
cert_path = _get_cert_path(request)
39-
with open(cert_path) as cert:
39+
with open(cert_path, encoding='utf-8') as cert:
4040
project_id = json.load(cert).get('project_id')
4141
if not project_id:
4242
raise ValueError('Failed to determine project ID from service account certificate.')
@@ -57,8 +57,8 @@ def default_app(request):
5757
"""
5858
cred, project_id = integration_conf(request)
5959
ops = {
60-
'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id),
61-
'storageBucket' : '{0}.appspot.com'.format(project_id)
60+
'databaseURL' : f'https://{project_id}.firebaseio.com',
61+
'storageBucket' : f'{project_id}.appspot.com'
6262
}
6363
return firebase_admin.initialize_app(cred, ops)
6464

@@ -68,5 +68,5 @@ def api_key(request):
6868
if not path:
6969
raise ValueError('API key file not specified. Make sure to specify the "--apikey" '
7070
'command-line option.')
71-
with open(path) as keyfile:
71+
with open(path, encoding='utf-8') as keyfile:
7272
return keyfile.read().strip()

integration/test_auth.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import firebase_admin
3131
from firebase_admin import auth
3232
from firebase_admin import credentials
33+
from firebase_admin._http_client import DEFAULT_TIMEOUT_SECONDS as timeout
3334

3435

3536
_verify_token_url = 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken'
@@ -67,14 +68,14 @@
6768
def _sign_in(custom_token, api_key):
6869
body = {'token' : custom_token.decode(), 'returnSecureToken' : True}
6970
params = {'key' : api_key}
70-
resp = requests.request('post', _verify_token_url, params=params, json=body)
71+
resp = requests.request('post', _verify_token_url, params=params, json=body, timeout=timeout)
7172
resp.raise_for_status()
7273
return resp.json().get('idToken')
7374

7475
def _sign_in_with_password(email, password, api_key):
7576
body = {'email': email, 'password': password, 'returnSecureToken': True}
7677
params = {'key' : api_key}
77-
resp = requests.request('post', _verify_password_url, params=params, json=body)
78+
resp = requests.request('post', _verify_password_url, params=params, json=body, timeout=timeout)
7879
resp.raise_for_status()
7980
return resp.json().get('idToken')
8081

@@ -84,7 +85,7 @@ def _random_string(length=10):
8485

8586
def _random_id():
8687
random_id = str(uuid.uuid4()).lower().replace('-', '')
87-
email = 'test{0}@example.{1}.com'.format(random_id[:12], random_id[12:])
88+
email = f'test{random_id[:12]}@example.{random_id[12:]}.com'
8889
return random_id, email
8990

9091
def _random_phone():
@@ -93,21 +94,21 @@ def _random_phone():
9394
def _reset_password(oob_code, new_password, api_key):
9495
body = {'oobCode': oob_code, 'newPassword': new_password}
9596
params = {'key' : api_key}
96-
resp = requests.request('post', _password_reset_url, params=params, json=body)
97+
resp = requests.request('post', _password_reset_url, params=params, json=body, timeout=timeout)
9798
resp.raise_for_status()
9899
return resp.json().get('email')
99100

100101
def _verify_email(oob_code, api_key):
101102
body = {'oobCode': oob_code}
102103
params = {'key' : api_key}
103-
resp = requests.request('post', _verify_email_url, params=params, json=body)
104+
resp = requests.request('post', _verify_email_url, params=params, json=body, timeout=timeout)
104105
resp.raise_for_status()
105106
return resp.json().get('email')
106107

107108
def _sign_in_with_email_link(email, oob_code, api_key):
108109
body = {'oobCode': oob_code, 'email': email}
109110
params = {'key' : api_key}
110-
resp = requests.request('post', _email_sign_in_url, params=params, json=body)
111+
resp = requests.request('post', _email_sign_in_url, params=params, json=body, timeout=timeout)
111112
resp.raise_for_status()
112113
return resp.json().get('idToken')
113114

@@ -870,7 +871,7 @@ def test_delete_saml_provider_config():
870871

871872

872873
def _create_oidc_provider_config():
873-
provider_id = 'oidc.{0}'.format(_random_string())
874+
provider_id = f'oidc.{_random_string()}'
874875
return auth.create_oidc_provider_config(
875876
provider_id=provider_id,
876877
client_id='OIDC_CLIENT_ID',
@@ -882,7 +883,7 @@ def _create_oidc_provider_config():
882883

883884

884885
def _create_saml_provider_config():
885-
provider_id = 'saml.{0}'.format(_random_string())
886+
provider_id = f'saml.{_random_string()}'
886887
return auth.create_saml_provider_config(
887888
provider_id=provider_id,
888889
idp_entity_id='IDP_ENTITY_ID',

integration/test_db.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def integration_conf(request):
3939
def app(request):
4040
cred, project_id = integration_conf(request)
4141
ops = {
42-
'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id),
42+
'databaseURL' : f'https://{project_id}.firebaseio.com',
4343
}
4444
return firebase_admin.initialize_app(cred, ops, name='integration-db')
4545

@@ -53,7 +53,7 @@ def default_app():
5353

5454
@pytest.fixture(scope='module')
5555
def update_rules(app):
56-
with open(testutils.resource_filename('dinosaurs_index.json')) as rules_file:
56+
with open(testutils.resource_filename('dinosaurs_index.json'), encoding='utf-8') as rules_file:
5757
new_rules = json.load(rules_file)
5858
client = db.reference('', app)._client
5959
rules = client.body('get', '/.settings/rules.json', params='format=strict')
@@ -64,7 +64,7 @@ def update_rules(app):
6464

6565
@pytest.fixture(scope='module')
6666
def testdata():
67-
with open(testutils.resource_filename('dinosaurs.json')) as dino_file:
67+
with open(testutils.resource_filename('dinosaurs.json'), encoding='utf-8') as dino_file:
6868
return json.load(dino_file)
6969

7070
@pytest.fixture(scope='module')
@@ -195,8 +195,8 @@ def test_update_nested_children(self, testref):
195195
edward = python.child('users').push({'name' : 'Edward Cope', 'since' : 1800})
196196
jack = python.child('users').push({'name' : 'Jack Horner', 'since' : 1940})
197197
delta = {
198-
'{0}/since'.format(edward.key) : 1840,
199-
'{0}/since'.format(jack.key) : 1946
198+
f'{edward.key}/since' : 1840,
199+
f'{jack.key}/since' : 1946
200200
}
201201
python.child('users').update(delta)
202202
assert edward.get() == {'name' : 'Edward Cope', 'since' : 1840}
@@ -363,7 +363,7 @@ def override_app(request, update_rules):
363363
del update_rules
364364
cred, project_id = integration_conf(request)
365365
ops = {
366-
'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id),
366+
'databaseURL' : f'https://{project_id}.firebaseio.com',
367367
'databaseAuthVariableOverride' : {'uid' : 'user1'}
368368
}
369369
app = firebase_admin.initialize_app(cred, ops, 'db-override')
@@ -375,7 +375,7 @@ def none_override_app(request, update_rules):
375375
del update_rules
376376
cred, project_id = integration_conf(request)
377377
ops = {
378-
'databaseURL' : 'https://{0}.firebaseio.com'.format(project_id),
378+
'databaseURL' : f'https://{project_id}.firebaseio.com',
379379
'databaseAuthVariableOverride' : None
380380
}
381381
app = firebase_admin.initialize_app(cred, ops, 'db-none-override')

integration/test_firestore.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
from firebase_admin import firestore
1919

2020
_CITY = {
21-
'name': u'Mountain View',
22-
'country': u'USA',
21+
'name': 'Mountain View',
22+
'country': 'USA',
2323
'population': 77846,
2424
'capital': False
2525
}
2626

2727
_MOVIE = {
28-
'Name': u'Interstellar',
28+
'Name': 'Interstellar',
2929
'Year': 2014,
30-
'Runtime': u'2h 49m',
30+
'Runtime': '2h 49m',
3131
'Academy Award Winner': True
3232
}
3333

3434

3535
def test_firestore():
3636
client = firestore.client()
3737
expected = {
38-
'name': u'Mountain View',
39-
'country': u'USA',
38+
'name': 'Mountain View',
39+
'country': 'USA',
4040
'population': 77846,
4141
'capital': False
4242
}
@@ -93,7 +93,7 @@ def test_firestore_multi_db():
9393
def test_server_timestamp():
9494
client = firestore.client()
9595
expected = {
96-
'name': u'Mountain View',
96+
'name': 'Mountain View',
9797
'timestamp': firestore.SERVER_TIMESTAMP # pylint: disable=no-member
9898
}
9999
doc = client.collection('cities').document()

integration/test_firestore_async.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
from firebase_admin import firestore_async
2121

2222
_CITY = {
23-
'name': u'Mountain View',
24-
'country': u'USA',
23+
'name': 'Mountain View',
24+
'country': 'USA',
2525
'population': 77846,
2626
'capital': False
2727
}
2828

2929
_MOVIE = {
30-
'Name': u'Interstellar',
30+
'Name': 'Interstellar',
3131
'Year': 2014,
32-
'Runtime': u'2h 49m',
32+
'Runtime': '2h 49m',
3333
'Academy Award Winner': True
3434
}
3535

@@ -102,7 +102,7 @@ async def test_firestore_async_multi_db():
102102
async def test_server_timestamp():
103103
client = firestore_async.client()
104104
expected = {
105-
'name': u'Mountain View',
105+
'name': 'Mountain View',
106106
'timestamp': firestore_async.SERVER_TIMESTAMP # pylint: disable=no-member
107107
}
108108
doc = client.collection('cities').document()

integration/test_messaging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_send_each():
121121
def test_send_each_500():
122122
messages = []
123123
for msg_number in range(500):
124-
topic = 'foo-bar-{0}'.format(msg_number % 10)
124+
topic = f'foo-bar-{msg_number % 10}'
125125
messages.append(messaging.Message(topic=topic))
126126

127127
batch_response = messaging.send_each(messages, dry_run=True)
@@ -193,7 +193,7 @@ async def test_send_each_async():
193193
async def test_send_each_async_500():
194194
messages = []
195195
for msg_number in range(500):
196-
topic = 'foo-bar-{0}'.format(msg_number % 10)
196+
topic = f'foo-bar-{msg_number % 10}'
197197
messages.append(messaging.Message(topic=topic))
198198

199199
batch_response = await messaging.send_each_async(messages, dry_run=True)

integration/test_ml.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
def _random_identifier(prefix):
3838
#pylint: disable=unused-variable
3939
suffix = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(8)])
40-
return '{0}_{1}'.format(prefix, suffix)
40+
return f'{prefix}_{suffix}'
4141

4242

4343
NAME_ONLY_ARGS = {
@@ -170,7 +170,7 @@ def test_create_already_existing_fails(firebase_model):
170170
ml.create_model(model=firebase_model)
171171
check_operation_error(
172172
excinfo,
173-
'Model \'{0}\' already exists'.format(firebase_model.display_name))
173+
f'Model \'{firebase_model.display_name}\' already exists')
174174

175175

176176
@pytest.mark.parametrize('firebase_model', [INVALID_FULL_MODEL_ARGS], indirect=True)
@@ -219,7 +219,7 @@ def test_update_non_existing_model(firebase_model):
219219
ml.update_model(firebase_model)
220220
check_operation_error(
221221
excinfo,
222-
'Model \'{0}\' was not found'.format(firebase_model.as_dict().get('name')))
222+
f'Model \'{firebase_model.as_dict().get("name")}\' was not found')
223223

224224

225225
@pytest.mark.parametrize('firebase_model', [FULL_MODEL_ARGS], indirect=True)
@@ -252,18 +252,17 @@ def test_publish_unpublish_non_existing_model(firebase_model):
252252
ml.publish_model(firebase_model.model_id)
253253
check_operation_error(
254254
excinfo,
255-
'Model \'{0}\' was not found'.format(firebase_model.as_dict().get('name')))
255+
f'Model \'{firebase_model.as_dict().get("name")}\' was not found')
256256

257257
with pytest.raises(exceptions.NotFoundError) as excinfo:
258258
ml.unpublish_model(firebase_model.model_id)
259259
check_operation_error(
260260
excinfo,
261-
'Model \'{0}\' was not found'.format(firebase_model.as_dict().get('name')))
261+
f'Model \'{firebase_model.as_dict().get("name")}\' was not found')
262262

263263

264264
def test_list_models(model_list):
265-
filter_str = 'displayName={0} OR tags:{1}'.format(
266-
model_list[0].display_name, model_list[1].tags[0])
265+
filter_str = f'displayName={model_list[0].display_name} OR tags:{model_list[1].tags[0]}'
267266

268267
all_models = ml.list_models(list_filter=filter_str)
269268
all_model_ids = [mdl.model_id for mdl in all_models.iterate_all()]

integration/test_project_management.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ def test_create_android_app_already_exists(android_app):
7474
def test_android_set_display_name_and_get_metadata(android_app, project_id):
7575
app_id = android_app.app_id
7676
android_app = project_management.android_app(app_id)
77-
new_display_name = '{0} helloworld {1}'.format(
78-
TEST_APP_DISPLAY_NAME_PREFIX, random.randint(0, 10000))
77+
new_display_name = f'{TEST_APP_DISPLAY_NAME_PREFIX} helloworld {random.randint(0, 10000)}'
7978

8079
android_app.set_display_name(new_display_name)
8180
metadata = project_management.android_app(app_id).get_metadata()
8281
android_app.set_display_name(TEST_APP_DISPLAY_NAME_PREFIX) # Revert the display name.
8382

84-
assert metadata._name == 'projects/{0}/androidApps/{1}'.format(project_id, app_id)
83+
assert metadata._name == f'projects/{project_id}/androidApps/{app_id}'
8584
assert metadata.app_id == app_id
8685
assert metadata.project_id == project_id
8786
assert metadata.display_name == new_display_name
@@ -149,15 +148,13 @@ def test_create_ios_app_already_exists(ios_app):
149148
def test_ios_set_display_name_and_get_metadata(ios_app, project_id):
150149
app_id = ios_app.app_id
151150
ios_app = project_management.ios_app(app_id)
152-
new_display_name = '{0} helloworld {1}'.format(
153-
TEST_APP_DISPLAY_NAME_PREFIX, random.randint(0, 10000))
151+
new_display_name = f'{TEST_APP_DISPLAY_NAME_PREFIX} helloworld {random.randint(0, 10000)}'
154152

155153
ios_app.set_display_name(new_display_name)
156154
metadata = project_management.ios_app(app_id).get_metadata()
157155
ios_app.set_display_name(TEST_APP_DISPLAY_NAME_PREFIX) # Revert the display name.
158156

159-
assert metadata._name == 'projects/{0}/iosApps/{1}'.format(project_id, app_id)
160-
assert metadata.app_id == app_id
157+
assert metadata._name == f'projects/{project_id}/iosApps/{app_id}'
161158
assert metadata.project_id == project_id
162159
assert metadata.display_name == new_display_name
163160
assert metadata.bundle_id == TEST_APP_BUNDLE_ID

integration/test_storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
def test_default_bucket(project_id):
2222
bucket = storage.bucket()
23-
_verify_bucket(bucket, '{0}.appspot.com'.format(project_id))
23+
_verify_bucket(bucket, f'{project_id}.appspot.com')
2424

2525
def test_custom_bucket(project_id):
26-
bucket_name = '{0}.appspot.com'.format(project_id)
26+
bucket_name = f'{project_id}.appspot.com'
2727
bucket = storage.bucket(bucket_name)
2828
_verify_bucket(bucket, bucket_name)
2929

@@ -33,7 +33,7 @@ def test_non_existing_bucket():
3333

3434
def _verify_bucket(bucket, expected_name):
3535
assert bucket.name == expected_name
36-
file_name = 'data_{0}.txt'.format(int(time.time()))
36+
file_name = f'data_{int(time.time())}.txt'
3737
blob = bucket.blob(file_name)
3838
blob.upload_from_string('Hello World')
3939

integration/test_tenant_mgt.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from firebase_admin import auth
2727
from firebase_admin import tenant_mgt
28+
from firebase_admin._http_client import DEFAULT_TIMEOUT_SECONDS as timeout
2829
from integration import test_auth
2930

3031

@@ -359,7 +360,7 @@ def test_delete_saml_provider_config(sample_tenant):
359360

360361

361362
def _create_oidc_provider_config(client):
362-
provider_id = 'oidc.{0}'.format(_random_string())
363+
provider_id = f'oidc.{_random_string()}'
363364
return client.create_oidc_provider_config(
364365
provider_id=provider_id,
365366
client_id='OIDC_CLIENT_ID',
@@ -369,7 +370,7 @@ def _create_oidc_provider_config(client):
369370

370371

371372
def _create_saml_provider_config(client):
372-
provider_id = 'saml.{0}'.format(_random_string())
373+
provider_id = f'saml.{_random_string()}'
373374
return client.create_saml_provider_config(
374375
provider_id=provider_id,
375376
idp_entity_id='IDP_ENTITY_ID',
@@ -387,7 +388,7 @@ def _random_uid():
387388

388389
def _random_email():
389390
random_id = str(uuid.uuid4()).lower().replace('-', '')
390-
return 'test{0}@example.{1}.com'.format(random_id[:12], random_id[12:])
391+
return f'test{random_id[:12]}@example.{random_id[12:]}.com'
391392

392393

393394
def _random_phone():
@@ -412,6 +413,6 @@ def _sign_in(custom_token, tenant_id, api_key):
412413
'tenantId': tenant_id,
413414
}
414415
params = {'key' : api_key}
415-
resp = requests.request('post', VERIFY_TOKEN_URL, params=params, json=body)
416+
resp = requests.request('post', VERIFY_TOKEN_URL, params=params, json=body, timeout=timeout)
416417
resp.raise_for_status()
417418
return resp.json().get('idToken')

0 commit comments

Comments
 (0)