Skip to content

Commit 28e275a

Browse files
committed
chore: fix unit test lint
1 parent a507a16 commit 28e275a

15 files changed

+183
-181
lines changed

tests/test_app.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ def revert_config_env(config_old):
215215
class TestFirebaseApp:
216216
"""Test cases for App initialization and life cycle."""
217217

218-
invalid_credentials = ['', 'foo', 0, 1, dict(), list(), tuple(), True, False]
219-
invalid_options = ['', 0, 1, list(), tuple(), True, False]
220-
invalid_names = [None, '', 0, 1, dict(), list(), tuple(), True, False]
218+
invalid_credentials = ['', 'foo', 0, 1, {}, [], tuple(), True, False]
219+
invalid_options = ['', 0, 1, [], tuple(), True, False]
220+
invalid_names = [None, '', 0, 1, {}, [], tuple(), True, False]
221221
invalid_apps = [
222-
None, '', 0, 1, dict(), list(), tuple(), True, False,
222+
None, '', 0, 1, {}, [], tuple(), True, False,
223223
firebase_admin.App('uninitialized', CREDENTIAL, {})
224224
]
225225

@@ -308,11 +308,11 @@ def test_project_id_from_environment(self):
308308
variables = ['GOOGLE_CLOUD_PROJECT', 'GCLOUD_PROJECT']
309309
for idx, var in enumerate(variables):
310310
old_project_id = os.environ.get(var)
311-
new_project_id = 'env-project-{0}'.format(idx)
311+
new_project_id = f'env-project-{idx}'
312312
os.environ[var] = new_project_id
313313
try:
314314
app = firebase_admin.initialize_app(
315-
testutils.MockCredential(), name='myApp{0}'.format(var))
315+
testutils.MockCredential(), name=f'myApp{var}')
316316
assert app.project_id == new_project_id
317317
finally:
318318
if old_project_id:
@@ -388,7 +388,7 @@ def test_app_services(self, init_app):
388388
with pytest.raises(ValueError):
389389
_utils.get_app_service(init_app, 'test.service', AppService)
390390

391-
@pytest.mark.parametrize('arg', [0, 1, True, False, 'str', list(), dict(), tuple()])
391+
@pytest.mark.parametrize('arg', [0, 1, True, False, 'str', [], {}, tuple()])
392392
def test_app_services_invalid_arg(self, arg):
393393
with pytest.raises(ValueError):
394394
_utils.get_app_service(arg, 'test.service', AppService)

tests/test_app_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from firebase_admin import app_check
2323
from tests import testutils
2424

25-
NON_STRING_ARGS = [list(), tuple(), dict(), True, False, 1, 0]
25+
NON_STRING_ARGS = [[], tuple(), {}, True, False, 1, 0]
2626

2727
APP_ID = "1234567890"
2828
PROJECT_ID = "1334"
@@ -71,7 +71,7 @@ def evaluate():
7171
def test_verify_token_with_non_string_raises_error(self, token):
7272
with pytest.raises(ValueError) as excinfo:
7373
app_check.verify_token(token)
74-
expected = 'app check token "{0}" must be a string.'.format(token)
74+
expected = f'app check token "{token}" must be a string.'
7575
assert str(excinfo.value) == expected
7676

7777
def test_has_valid_token_headers(self):

tests/test_auth_providers.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
ID_TOOLKIT_URL = 'https://identitytoolkit.googleapis.com/v2'
2828
EMULATOR_HOST_ENV_VAR = 'FIREBASE_AUTH_EMULATOR_HOST'
2929
AUTH_EMULATOR_HOST = 'localhost:9099'
30-
EMULATED_ID_TOOLKIT_URL = 'http://{}/identitytoolkit.googleapis.com/v2'.format(
31-
AUTH_EMULATOR_HOST)
30+
EMULATED_ID_TOOLKIT_URL = f'http://{AUTH_EMULATOR_HOST}/identitytoolkit.googleapis.com/v2'
3231
URL_PROJECT_SUFFIX = '/projects/mock-project-id'
3332
USER_MGT_URLS = {
3433
'ID_TOOLKIT': ID_TOOLKIT_URL,
@@ -45,7 +44,7 @@
4544
}
4645
}"""
4746

48-
INVALID_PROVIDER_IDS = [None, True, False, 1, 0, list(), tuple(), dict(), '']
47+
INVALID_PROVIDER_IDS = [None, True, False, 1, 0, [], tuple(), {}, '']
4948

5049

5150
@pytest.fixture(scope='module', params=[{'emulated': False}, {'emulated': True}])
@@ -282,12 +281,12 @@ def test_delete(self, user_mgt_app):
282281
_assert_request(recorder[0], 'DELETE',
283282
f'{USER_MGT_URLS["PREFIX"]}/oauthIdpConfigs/oidc.provider')
284283

285-
@pytest.mark.parametrize('arg', [None, 'foo', list(), dict(), 0, -1, 101, False])
284+
@pytest.mark.parametrize('arg', [None, 'foo', [], {}, 0, -1, 101, False])
286285
def test_invalid_max_results(self, user_mgt_app, arg):
287286
with pytest.raises(ValueError):
288287
auth.list_oidc_provider_configs(max_results=arg, app=user_mgt_app)
289288

290-
@pytest.mark.parametrize('arg', ['', list(), dict(), 0, -1, 101, False])
289+
@pytest.mark.parametrize('arg', ['', [], {}, 0, -1, 101, False])
291290
def test_invalid_page_token(self, user_mgt_app, arg):
292291
with pytest.raises(ValueError):
293292
auth.list_oidc_provider_configs(page_token=arg, app=user_mgt_app)
@@ -346,7 +345,7 @@ def test_paged_iteration(self, user_mgt_app):
346345

347346
for index in range(2):
348347
provider_config = next(iterator)
349-
assert provider_config.provider_id == 'oidc.provider{0}'.format(index)
348+
assert provider_config.provider_id == f'oidc.provider{index}'
350349
assert len(recorder) == 1
351350
_assert_request(recorder[0], 'GET',
352351
f'{USER_MGT_URLS["PREFIX"]}/oauthIdpConfigs?pageSize=100')
@@ -403,7 +402,7 @@ def _assert_page(self, page, count=2, start=0, next_page_token=''):
403402
index = start
404403
assert len(page.provider_configs) == count
405404
for provider_config in page.provider_configs:
406-
self._assert_provider_config(provider_config, want_id='oidc.provider{0}'.format(index))
405+
self._assert_provider_config(provider_config, want_id=f'oidc.provider{index}')
407406
index += 1
408407

409408
if next_page_token:
@@ -621,12 +620,12 @@ def test_config_not_found(self, user_mgt_app):
621620
assert excinfo.value.http_response is not None
622621
assert excinfo.value.cause is not None
623622

624-
@pytest.mark.parametrize('arg', [None, 'foo', list(), dict(), 0, -1, 101, False])
623+
@pytest.mark.parametrize('arg', [None, 'foo', [], {}, 0, -1, 101, False])
625624
def test_invalid_max_results(self, user_mgt_app, arg):
626625
with pytest.raises(ValueError):
627626
auth.list_saml_provider_configs(max_results=arg, app=user_mgt_app)
628627

629-
@pytest.mark.parametrize('arg', ['', list(), dict(), 0, -1, 101, False])
628+
@pytest.mark.parametrize('arg', ['', [], {}, 0, -1, 101, False])
630629
def test_invalid_page_token(self, user_mgt_app, arg):
631630
with pytest.raises(ValueError):
632631
auth.list_saml_provider_configs(page_token=arg, app=user_mgt_app)
@@ -686,7 +685,7 @@ def test_paged_iteration(self, user_mgt_app):
686685

687686
for index in range(2):
688687
provider_config = next(iterator)
689-
assert provider_config.provider_id == 'saml.provider{0}'.format(index)
688+
assert provider_config.provider_id == f'saml.provider{index}'
690689
assert len(recorder) == 1
691690
_assert_request(
692691
recorder[0], 'GET', f'{USER_MGT_URLS["PREFIX"]}/inboundSamlConfigs?pageSize=100')
@@ -735,7 +734,7 @@ def _assert_page(self, page, count=2, start=0, next_page_token=''):
735734
index = start
736735
assert len(page.provider_configs) == count
737736
for provider_config in page.provider_configs:
738-
self._assert_provider_config(provider_config, want_id='saml.provider{0}'.format(index))
737+
self._assert_provider_config(provider_config, want_id=f'saml.provider{index}')
739738
index += 1
740739

741740
if next_page_token:

tests/test_credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_init_from_invalid_certificate(self, file_name, error):
6464
with pytest.raises(error):
6565
credentials.Certificate(testutils.resource_filename(file_name))
6666

67-
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, list(), tuple(), dict()])
67+
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, [], tuple(), {}])
6868
def test_invalid_args(self, arg):
6969
with pytest.raises(ValueError):
7070
credentials.Certificate(arg)
@@ -156,7 +156,7 @@ def test_init_from_invalid_file(self):
156156
credentials.RefreshToken(
157157
testutils.resource_filename('service_account.json'))
158158

159-
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, list(), tuple(), dict()])
159+
@pytest.mark.parametrize('arg', [None, 0, 1, True, False, [], tuple(), {}])
160160
def test_invalid_args(self, arg):
161161
with pytest.raises(ValueError):
162162
credentials.RefreshToken(arg)

tests/test_db.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TestReferencePath:
8787
}
8888

8989
invalid_paths = [
90-
None, True, False, 0, 1, dict(), list(), tuple(), _Object(),
90+
None, True, False, 0, 1, {}, [], tuple(), _Object(),
9191
'foo#', 'foo.', 'foo$', 'foo[', 'foo]',
9292
]
9393

@@ -98,7 +98,7 @@ class TestReferencePath:
9898
}
9999

100100
invalid_children = [
101-
None, '', '/foo', '/foo/bar', True, False, 0, 1, dict(), list(), tuple(),
101+
None, '', '/foo', '/foo/bar', True, False, 0, 1, {}, [], tuple(),
102102
'foo#', 'foo.', 'foo$', 'foo[', 'foo]', _Object()
103103
]
104104

@@ -248,7 +248,7 @@ def test_get_if_changed(self, data):
248248
self._assert_request(recorder[1], 'GET', 'https://test.firebaseio.com/test.json')
249249
assert recorder[1].headers['if-none-match'] == MockAdapter.ETAG
250250

251-
@pytest.mark.parametrize('etag', [0, 1, True, False, dict(), list(), tuple()])
251+
@pytest.mark.parametrize('etag', [0, 1, True, False, {}, [], tuple()])
252252
def test_get_if_changed_invalid_etag(self, etag):
253253
ref = db.reference('/test')
254254
with pytest.raises(ValueError):
@@ -347,7 +347,7 @@ def test_set_if_unchanged_failure(self, data):
347347
assert json.loads(recorder[0].body.decode()) == data
348348
assert recorder[0].headers['if-match'] == 'invalid-etag'
349349

350-
@pytest.mark.parametrize('etag', [0, 1, True, False, dict(), list(), tuple()])
350+
@pytest.mark.parametrize('etag', [0, 1, True, False, {}, [], tuple()])
351351
def test_set_if_unchanged_invalid_etag(self, etag):
352352
ref = db.reference('/test')
353353
with pytest.raises(ValueError):
@@ -369,7 +369,7 @@ def test_set_if_unchanged_non_json_value(self, value):
369369
ref.set_if_unchanged(MockAdapter.ETAG, value)
370370

371371
@pytest.mark.parametrize('update', [
372-
None, {}, {None:'foo'}, '', 'foo', 0, 1, list(), tuple(), _Object()
372+
None, {}, {None:'foo'}, '', 'foo', 0, 1, [], tuple(), _Object()
373373
])
374374
def test_set_invalid_update(self, update):
375375
ref = db.reference('/test')
@@ -466,7 +466,7 @@ def test_transaction_abort(self):
466466
assert excinfo.value.http_response is None
467467
assert len(recorder) == 1 + 25
468468

469-
@pytest.mark.parametrize('func', [None, 0, 1, True, False, 'foo', dict(), list(), tuple()])
469+
@pytest.mark.parametrize('func', [None, 0, 1, True, False, 'foo', {}, [], tuple()])
470470
def test_transaction_invalid_function(self, func):
471471
ref = db.reference('/test')
472472
with pytest.raises(ValueError):
@@ -672,7 +672,7 @@ def _assert_request(self, request, expected_method, expected_url):
672672
def test_get_value(self):
673673
ref = db.reference('/test')
674674
recorder = self.instrument(ref, json.dumps('data'))
675-
query_str = 'auth_variable_override={0}'.format(self.encoded_override)
675+
query_str = f'auth_variable_override={self.encoded_override}'
676676
assert ref.get() == 'data'
677677
assert len(recorder) == 1
678678
self._assert_request(
@@ -683,7 +683,7 @@ def test_set_value(self):
683683
recorder = self.instrument(ref, '')
684684
data = {'foo' : 'bar'}
685685
ref.set(data)
686-
query_str = 'print=silent&auth_variable_override={0}'.format(self.encoded_override)
686+
query_str = f'print=silent&auth_variable_override={self.encoded_override}'
687687
assert len(recorder) == 1
688688
self._assert_request(
689689
recorder[0], 'PUT', 'https://test.firebaseio.com/test.json?' + query_str)
@@ -693,7 +693,7 @@ def test_order_by_query(self):
693693
ref = db.reference('/test')
694694
recorder = self.instrument(ref, json.dumps('data'))
695695
query = ref.order_by_child('foo')
696-
query_str = 'orderBy=%22foo%22&auth_variable_override={0}'.format(self.encoded_override)
696+
query_str = f'orderBy=%22foo%22&auth_variable_override={self.encoded_override}'
697697
assert query.get() == 'data'
698698
assert len(recorder) == 1
699699
self._assert_request(
@@ -703,8 +703,9 @@ def test_range_query(self):
703703
ref = db.reference('/test')
704704
recorder = self.instrument(ref, json.dumps('data'))
705705
query = ref.order_by_child('foo').start_at(1).end_at(10)
706-
query_str = ('endAt=10&orderBy=%22foo%22&startAt=1&'
707-
'auth_variable_override={0}'.format(self.encoded_override))
706+
query_str = (
707+
f'endAt=10&orderBy=%22foo%22&startAt=1&auth_variable_override={self.encoded_override}'
708+
)
708709
assert query.get() == 'data'
709710
assert len(recorder) == 1
710711
self._assert_request(
@@ -794,7 +795,7 @@ def test_valid_db_url(self, url):
794795

795796
@pytest.mark.parametrize('url', [
796797
None, '', 'foo', 'http://test.firebaseio.com', 'http://test.firebasedatabase.app',
797-
True, False, 1, 0, dict(), list(), tuple(), _Object()
798+
True, False, 1, 0, {}, [], tuple(), _Object()
798799
])
799800
def test_invalid_db_url(self, url):
800801
firebase_admin.initialize_app(testutils.MockCredential(), {'databaseURL' : url})
@@ -838,7 +839,7 @@ def test_valid_auth_override(self, override):
838839
assert ref._client.params['auth_variable_override'] == encoded
839840

840841
@pytest.mark.parametrize('override', [
841-
'', 'foo', 0, 1, True, False, list(), tuple(), _Object()])
842+
'', 'foo', 0, 1, True, False, [], tuple(), _Object()])
842843
def test_invalid_auth_override(self, override):
843844
firebase_admin.initialize_app(testutils.MockCredential(), {
844845
'databaseURL' : 'https://test.firebaseio.com',
@@ -885,8 +886,10 @@ def test_app_delete(self):
885886
assert other_ref._client.session is None
886887

887888
def test_user_agent_format(self):
888-
expected = 'Firebase/HTTP/{0}/{1}.{2}/AdminPython'.format(
889-
firebase_admin.__version__, sys.version_info.major, sys.version_info.minor)
889+
expected = (
890+
f'Firebase/HTTP/{firebase_admin.__version__}/{sys.version_info.major}.'
891+
f'{sys.version_info.minor}/AdminPython'
892+
)
890893
assert db._USER_AGENT == expected
891894

892895
def _check_timeout(self, ref, timeout):
@@ -925,7 +928,7 @@ class TestQuery:
925928
ref = db.Reference(path='foo')
926929

927930
@pytest.mark.parametrize('path', [
928-
'', None, '/', '/foo', 0, 1, True, False, dict(), list(), tuple(), _Object(),
931+
'', None, '/', '/foo', 0, 1, True, False, {}, [], tuple(), _Object(),
929932
'$foo', '.foo', '#foo', '[foo', 'foo]', '$key', '$value', '$priority'
930933
])
931934
def test_invalid_path(self, path):
@@ -935,13 +938,13 @@ def test_invalid_path(self, path):
935938
@pytest.mark.parametrize('path, expected', valid_paths.items())
936939
def test_order_by_valid_path(self, path, expected):
937940
query = self.ref.order_by_child(path)
938-
assert query._querystr == 'orderBy="{0}"'.format(expected)
941+
assert query._querystr == f'orderBy="{expected}"'
939942

940943
@pytest.mark.parametrize('path, expected', valid_paths.items())
941944
def test_filter_by_valid_path(self, path, expected):
942945
query = self.ref.order_by_child(path)
943946
query.equal_to(10)
944-
assert query._querystr == 'equalTo=10&orderBy="{0}"'.format(expected)
947+
assert query._querystr == f'equalTo=10&orderBy="{expected}"'
945948

946949
def test_order_by_key(self):
947950
query = self.ref.order_by_key()
@@ -972,7 +975,7 @@ def test_multiple_limits(self):
972975
with pytest.raises(ValueError):
973976
query.limit_to_first(1)
974977

975-
@pytest.mark.parametrize('limit', [None, -1, 'foo', 1.2, list(), dict(), tuple(), _Object()])
978+
@pytest.mark.parametrize('limit', [None, -1, 'foo', 1.2, [], {}, tuple(), _Object()])
976979
def test_invalid_limit(self, limit):
977980
query = self.ref.order_by_child('foo')
978981
with pytest.raises(ValueError):
@@ -985,55 +988,55 @@ def test_start_at_none(self):
985988
with pytest.raises(ValueError):
986989
query.start_at(None)
987990

988-
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, dict()])
991+
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, {}])
989992
def test_valid_start_at(self, arg):
990993
query = self.ref.order_by_child('foo').start_at(arg)
991-
assert query._querystr == 'orderBy="foo"&startAt={0}'.format(json.dumps(arg))
994+
assert query._querystr == f'orderBy="foo"&startAt={json.dumps(arg)}'
992995

993996
def test_end_at_none(self):
994997
query = self.ref.order_by_child('foo')
995998
with pytest.raises(ValueError):
996999
query.end_at(None)
9971000

998-
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, dict()])
1001+
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, {}])
9991002
def test_valid_end_at(self, arg):
10001003
query = self.ref.order_by_child('foo').end_at(arg)
1001-
assert query._querystr == 'endAt={0}&orderBy="foo"'.format(json.dumps(arg))
1004+
assert query._querystr == f'endAt={json.dumps(arg)}&orderBy="foo"'
10021005

10031006
def test_equal_to_none(self):
10041007
query = self.ref.order_by_child('foo')
10051008
with pytest.raises(ValueError):
10061009
query.equal_to(None)
10071010

1008-
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, dict()])
1011+
@pytest.mark.parametrize('arg', ['', 'foo', True, False, 0, 1, {}])
10091012
def test_valid_equal_to(self, arg):
10101013
query = self.ref.order_by_child('foo').equal_to(arg)
1011-
assert query._querystr == 'equalTo={0}&orderBy="foo"'.format(json.dumps(arg))
1014+
assert query._querystr == f'equalTo={json.dumps(arg)}&orderBy="foo"'
10121015

10131016
def test_range_query(self, initquery):
10141017
query, order_by = initquery
10151018
query.start_at(1)
10161019
query.equal_to(2)
10171020
query.end_at(3)
1018-
assert query._querystr == 'endAt=3&equalTo=2&orderBy="{0}"&startAt=1'.format(order_by)
1021+
assert query._querystr == f'endAt=3&equalTo=2&orderBy="{order_by}"&startAt=1'
10191022

10201023
def test_limit_first_query(self, initquery):
10211024
query, order_by = initquery
10221025
query.limit_to_first(1)
1023-
assert query._querystr == 'limitToFirst=1&orderBy="{0}"'.format(order_by)
1026+
assert query._querystr == f'limitToFirst=1&orderBy="{order_by}"'
10241027

10251028
def test_limit_last_query(self, initquery):
10261029
query, order_by = initquery
10271030
query.limit_to_last(1)
1028-
assert query._querystr == 'limitToLast=1&orderBy="{0}"'.format(order_by)
1031+
assert query._querystr == f'limitToLast=1&orderBy="{order_by}"'
10291032

10301033
def test_all_in(self, initquery):
10311034
query, order_by = initquery
10321035
query.start_at(1)
10331036
query.equal_to(2)
10341037
query.end_at(3)
10351038
query.limit_to_first(10)
1036-
expected = 'endAt=3&equalTo=2&limitToFirst=10&orderBy="{0}"&startAt=1'.format(order_by)
1039+
expected = f'endAt=3&equalTo=2&limitToFirst=10&orderBy="{order_by}"&startAt=1'
10371040
assert query._querystr == expected
10381041

10391042
def test_invalid_query_args(self):
@@ -1059,9 +1062,9 @@ class TestSorter:
10591062
({'k1' : False, 'k2' : 'bar', 'k3' : None}, ['k3', 'k1', 'k2']),
10601063
({'k1' : False, 'k2' : 1, 'k3' : None}, ['k3', 'k1', 'k2']),
10611064
({'k1' : True, 'k2' : 0, 'k3' : None, 'k4' : 'foo'}, ['k3', 'k1', 'k2', 'k4']),
1062-
({'k1' : True, 'k2' : 0, 'k3' : None, 'k4' : 'foo', 'k5' : False, 'k6' : dict()},
1065+
({'k1' : True, 'k2' : 0, 'k3' : None, 'k4' : 'foo', 'k5' : False, 'k6' : {}},
10631066
['k3', 'k5', 'k1', 'k2', 'k4', 'k6']),
1064-
({'k1' : True, 'k2' : 0, 'k3' : 'foo', 'k4' : 'foo', 'k5' : False, 'k6' : dict()},
1067+
({'k1' : True, 'k2' : 0, 'k3' : 'foo', 'k4' : 'foo', 'k5' : False, 'k6' : {}},
10651068
['k5', 'k1', 'k2', 'k3', 'k4', 'k6']),
10661069
]
10671070

0 commit comments

Comments
 (0)