Skip to content

Commit

Permalink
succinct import types
Browse files Browse the repository at this point in the history
  • Loading branch information
pragatimodi committed Dec 21, 2023
1 parent b7e9eba commit 6725d41
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
29 changes: 17 additions & 12 deletions integration/test_project_config_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

import pytest

from firebase_admin import project_config_mgt
from firebase_admin import multi_factor_config_mgt
from firebase_admin.project_config_mgt import ProjectConfig
from firebase_admin.project_config_mgt import get_project_config
from firebase_admin.project_config_mgt import update_project_config
from firebase_admin.multi_factor_config_mgt import MultiFactorConfig
from firebase_admin.multi_factor_config_mgt import MultiFactorServerConfig
from firebase_admin.multi_factor_config_mgt import ProviderConfig
from firebase_admin.multi_factor_config_mgt import TOTPProviderConfig

ADJACENT_INTERVALS = 5

Expand All @@ -37,34 +42,34 @@ def sample_mfa_config():


def test_update_project_config():
mfa_object = multi_factor_config_mgt.MultiFactorConfig(
mfa_object = MultiFactorConfig(
provider_configs=[
multi_factor_config_mgt.ProviderConfig(
state=multi_factor_config_mgt.ProviderConfig.State.ENABLED,
totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig(
ProviderConfig(
state=ProviderConfig.State.ENABLED,
totp_provider_config=TOTPProviderConfig(
adjacent_intervals=5
)
)
]
)
project_config = project_config_mgt.update_project_config(multi_factor_config=mfa_object)
project_config = update_project_config(multi_factor_config=mfa_object)
_assert_multi_factor_config(project_config.multi_factor_config)


def test_get_project():
project_config = project_config_mgt.get_project_config()
assert isinstance(project_config, project_config_mgt.ProjectConfig)
project_config = get_project_config()
assert isinstance(project_config, ProjectConfig)
_assert_multi_factor_config(project_config.multi_factor_config)

def _assert_multi_factor_config(multi_factor_config):
assert isinstance(multi_factor_config, multi_factor_config_mgt.MultiFactorServerConfig)
assert isinstance(multi_factor_config, MultiFactorServerConfig)
assert len(multi_factor_config.provider_configs) == 1
assert isinstance(multi_factor_config.provider_configs, list)
for provider_config in multi_factor_config.provider_configs:
assert isinstance(provider_config, multi_factor_config_mgt.MultiFactorServerConfig
assert isinstance(provider_config, MultiFactorServerConfig
.ProviderServerConfig)
assert provider_config.state == 'ENABLED'
assert isinstance(provider_config.totp_provider_config,
multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig
MultiFactorServerConfig.ProviderServerConfig
.TOTPProviderServerConfig)
assert provider_config.totp_provider_config.adjacent_intervals == ADJACENT_INTERVALS
37 changes: 20 additions & 17 deletions tests/test_multi_factor_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

import pytest

from firebase_admin import multi_factor_config_mgt

sample_mfa_config = multi_factor_config_mgt.MultiFactorConfig(
provider_configs=[multi_factor_config_mgt.ProviderConfig(
state=multi_factor_config_mgt.ProviderConfig.State.ENABLED,
totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig(
from firebase_admin.multi_factor_config_mgt import MultiFactorConfig
from firebase_admin.multi_factor_config_mgt import MultiFactorServerConfig
from firebase_admin.multi_factor_config_mgt import TOTPProviderConfig
from firebase_admin.multi_factor_config_mgt import ProviderConfig

sample_mfa_config = MultiFactorConfig(
provider_configs=[ProviderConfig(
state=ProviderConfig.State.ENABLED,
totp_provider_config=TOTPProviderConfig(
adjacent_intervals=5
)
)]
Expand Down Expand Up @@ -78,7 +81,7 @@ def test_undefined_provider_config_state(self):
@pytest.mark.parametrize('state',
['', 1, True, False, [], (), {}, "foo", 'ENABLED'])
def test_invalid_provider_config_state(self, state):
test_config = multi_factor_config_mgt.ProviderConfig(
test_config = ProviderConfig(
state=state
)
with pytest.raises(ValueError) as excinfo:
Expand All @@ -87,10 +90,10 @@ def test_invalid_provider_config_state(self, state):
' ProviderConfig.State.')

@pytest.mark.parametrize('state',
[multi_factor_config_mgt.ProviderConfig.State.ENABLED,
multi_factor_config_mgt.ProviderConfig.State.DISABLED])
[ProviderConfig.State.ENABLED,
ProviderConfig.State.DISABLED])
def test_undefined_totp_provider_config(self, state):
test_config = multi_factor_config_mgt.ProviderConfig(state=state)
test_config = ProviderConfig(state=state)
with pytest.raises(ValueError) as excinfo:
test_config.build_server_request()
assert str(excinfo.value).startswith('ProviderConfig.totp_provider_config must be'
Expand Down Expand Up @@ -134,21 +137,21 @@ class TestMultiFactorServerConfig:
def test_invalid_multi_factor_config_response(self):
test_config = 'invalid'
with pytest.raises(ValueError) as excinfo:
multi_factor_config_mgt.MultiFactorServerConfig(test_config)
MultiFactorServerConfig(test_config)
assert str(excinfo.value).startswith('Invalid data argument in MultiFactorServerConfig'
' constructor: {0}'.format(test_config))

def test_invalid_provider_config_response(self):
test_config = 'invalid'
with pytest.raises(ValueError) as excinfo:
multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig(test_config)
MultiFactorServerConfig.ProviderServerConfig(test_config)
assert str(excinfo.value).startswith('Invalid data argument in ProviderServerConfig'
' constructor: {0}'.format(test_config))

def test_invalid_totp_provider_config_response(self):
test_config = 'invalid'
with pytest.raises(ValueError) as excinfo:
multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig.\
MultiFactorServerConfig.ProviderServerConfig.\
TOTPProviderServerConfig(test_config)
assert str(excinfo.value).startswith('Invalid data argument in TOTPProviderServerConfig'
' constructor: {0}'.format(test_config))
Expand All @@ -162,20 +165,20 @@ def test_valid_server_response(self):
}
}]
}
mfa_config = multi_factor_config_mgt.MultiFactorServerConfig(response)
mfa_config = MultiFactorServerConfig(response)
_assert_multi_factor_config(mfa_config)


def _assert_multi_factor_config(mfa_config):
assert isinstance(mfa_config, multi_factor_config_mgt.MultiFactorServerConfig)
assert isinstance(mfa_config, MultiFactorServerConfig)
assert len(mfa_config.provider_configs) == 1
assert isinstance(mfa_config.provider_configs, list)
for provider_config in mfa_config.provider_configs:
assert isinstance(
provider_config,
multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig)
MultiFactorServerConfig.ProviderServerConfig)
assert provider_config.state == 'ENABLED'
assert isinstance(provider_config.totp_provider_config,
multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig
MultiFactorServerConfig.ProviderServerConfig
.TOTPProviderServerConfig)
assert provider_config.totp_provider_config.adjacent_intervals == 5
27 changes: 15 additions & 12 deletions tests/test_tenant_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
from firebase_admin import tenant_mgt
from firebase_admin import _auth_providers
from firebase_admin import _user_mgt
from firebase_admin import multi_factor_config_mgt
from firebase_admin.multi_factor_config_mgt import MultiFactorConfig
from firebase_admin.multi_factor_config_mgt import MultiFactorServerConfig
from firebase_admin.multi_factor_config_mgt import ProviderConfig
from firebase_admin.multi_factor_config_mgt import TOTPProviderConfig
from tests import testutils
from tests import test_token_gen

Expand Down Expand Up @@ -257,11 +260,11 @@ def test_invalid_multi_factor_configs(self, multi_factor_config, tenant_mgt_app)

def test_create_tenant(self, tenant_mgt_app):
_, recorder = _instrument_tenant_mgt(tenant_mgt_app, 200, GET_TENANT_RESPONSE)
mfa_object = multi_factor_config_mgt.MultiFactorConfig(
mfa_object = MultiFactorConfig(
provider_configs=[
multi_factor_config_mgt.ProviderConfig(
state=multi_factor_config_mgt.ProviderConfig.State.ENABLED,
totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig(
ProviderConfig(
state=ProviderConfig.State.ENABLED,
totp_provider_config=TOTPProviderConfig(
adjacent_intervals=ADJACENT_INTERVALS
)
)
Expand Down Expand Up @@ -376,11 +379,11 @@ def test_update_tenant_no_args(self, tenant_mgt_app):

def test_update_tenant(self, tenant_mgt_app):
_, recorder = _instrument_tenant_mgt(tenant_mgt_app, 200, GET_TENANT_RESPONSE)
mfa_object = multi_factor_config_mgt.MultiFactorConfig(
mfa_object = MultiFactorConfig(
provider_configs=[
multi_factor_config_mgt.ProviderConfig(
state=multi_factor_config_mgt.ProviderConfig.State.ENABLED,
totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig(
ProviderConfig(
state=ProviderConfig.State.ENABLED,
totp_provider_config=TOTPProviderConfig(
adjacent_intervals=ADJACENT_INTERVALS
)
)
Expand Down Expand Up @@ -1065,15 +1068,15 @@ def test_custom_token_with_claims(self, tenant_aware_custom_token_app):
custom_token, expected_claims=claims, tenant_id='test-tenant')

def _assert_multi_factor_config(mfa_config):
assert isinstance(mfa_config, multi_factor_config_mgt.MultiFactorServerConfig)
assert isinstance(mfa_config, MultiFactorServerConfig)
assert len(mfa_config.provider_configs) == 1
assert isinstance(mfa_config.provider_configs, list)
for provider_config in mfa_config.provider_configs:
assert isinstance(provider_config, multi_factor_config_mgt.MultiFactorServerConfig.\
assert isinstance(provider_config, MultiFactorServerConfig.\
ProviderServerConfig)
assert provider_config.state == 'ENABLED'
assert isinstance(provider_config.totp_provider_config,
multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig
MultiFactorServerConfig.ProviderServerConfig
.TOTPProviderServerConfig)
assert provider_config.totp_provider_config.adjacent_intervals == ADJACENT_INTERVALS

Expand Down

0 comments on commit 6725d41

Please sign in to comment.