Rename method to account for domain being a string and not an int (#2161)

This commit is contained in:
Adrià Casajús 2024-07-23 17:58:52 +02:00 committed by GitHub
parent 1407c969d2
commit 666bf86441
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions

View File

@ -165,7 +165,7 @@ def setting():
elif request.form.get("form-name") == "change-random-alias-default-domain": elif request.form.get("form-name") == "change-random-alias-default-domain":
default_domain = request.form.get("random-alias-default-domain") default_domain = request.form.get("random-alias-default-domain")
try: try:
user_settings.set_default_alias_id(current_user, default_domain) user_settings.set_default_alias_domain(current_user, default_domain)
except user_settings.CannotSetAlias as e: except user_settings.CannotSetAlias as e:
flash(e.msg, "error") flash(e.msg, "error")
return redirect(url_for("dashboard.setting")) return redirect(url_for("dashboard.setting"))

View File

@ -10,7 +10,7 @@ class CannotSetAlias(Exception):
self.msg = msg self.msg = msg
def set_default_alias_id(user: User, domain_name: Optional[str]): def set_default_alias_domain(user: User, domain_name: Optional[str]):
if domain_name is None: if domain_name is None:
LOG.i(f"User {user} has set no domain as default domain") LOG.i(f"User {user} has set no domain as default domain")
user.default_alias_public_domain_id = None user.default_alias_public_domain_id = None

View File

@ -38,7 +38,7 @@ def test_set_default_no_domain():
domain=custom_domain_name domain=custom_domain_name
).id ).id
Session.flush() Session.flush()
user_settings.set_default_alias_id(user, None) user_settings.set_default_alias_domain(user, None)
assert user.default_alias_public_domain_id is None assert user.default_alias_public_domain_id is None
assert user.default_alias_custom_domain_id is None assert user.default_alias_custom_domain_id is None
@ -50,7 +50,7 @@ def test_set_premium_sl_domain_with_non_premium_user():
domain.premium_only = True domain.premium_only = True
Session.flush() Session.flush()
with pytest.raises(user_settings.CannotSetAlias): with pytest.raises(user_settings.CannotSetAlias):
user_settings.set_default_alias_id(user, sl_domain_name) user_settings.set_default_alias_domain(user, sl_domain_name)
def test_set_hidden_sl_domain(): def test_set_hidden_sl_domain():
@ -60,7 +60,7 @@ def test_set_hidden_sl_domain():
domain.premium_only = False domain.premium_only = False
Session.flush() Session.flush()
with pytest.raises(user_settings.CannotSetAlias): with pytest.raises(user_settings.CannotSetAlias):
user_settings.set_default_alias_id(user, sl_domain_name) user_settings.set_default_alias_domain(user, sl_domain_name)
def test_set_sl_domain(): def test_set_sl_domain():
@ -70,7 +70,7 @@ def test_set_sl_domain():
domain.hidden = False domain.hidden = False
domain.premium_only = False domain.premium_only = False
Session.flush() Session.flush()
user_settings.set_default_alias_id(user, sl_domain_name) user_settings.set_default_alias_domain(user, sl_domain_name)
assert user.default_alias_public_domain_id == domain.id assert user.default_alias_public_domain_id == domain.id
assert user.default_alias_custom_domain_id is None assert user.default_alias_custom_domain_id is None
@ -82,7 +82,7 @@ def test_set_sl_premium_domain():
domain.hidden = False domain.hidden = False
domain.premium_only = True domain.premium_only = True
Session.flush() Session.flush()
user_settings.set_default_alias_id(user, sl_domain_name) user_settings.set_default_alias_domain(user, sl_domain_name)
assert user.default_alias_public_domain_id == domain.id assert user.default_alias_public_domain_id == domain.id
assert user.default_alias_custom_domain_id is None assert user.default_alias_custom_domain_id is None
@ -98,7 +98,7 @@ def test_set_other_user_custom_domain():
).domain ).domain
Session.flush() Session.flush()
with pytest.raises(user_settings.CannotSetAlias): with pytest.raises(user_settings.CannotSetAlias):
user_settings.set_default_alias_id(user, other_user_domain_name) user_settings.set_default_alias_domain(user, other_user_domain_name)
def test_set_unverified_custom_domain(): def test_set_unverified_custom_domain():
@ -108,7 +108,7 @@ def test_set_unverified_custom_domain():
domain.verified = False domain.verified = False
Session.flush() Session.flush()
with pytest.raises(user_settings.CannotSetAlias): with pytest.raises(user_settings.CannotSetAlias):
user_settings.set_default_alias_id(user, custom_domain_name) user_settings.set_default_alias_domain(user, custom_domain_name)
def test_set_custom_domain(): def test_set_custom_domain():
@ -117,7 +117,7 @@ def test_set_custom_domain():
domain = CustomDomain.get_by(domain=custom_domain_name) domain = CustomDomain.get_by(domain=custom_domain_name)
domain.verified = True domain.verified = True
Session.flush() Session.flush()
user_settings.set_default_alias_id(user, custom_domain_name) user_settings.set_default_alias_domain(user, custom_domain_name)
assert user.default_alias_public_domain_id is None assert user.default_alias_public_domain_id is None
assert user.default_alias_custom_domain_id == domain.id assert user.default_alias_custom_domain_id == domain.id
@ -125,4 +125,4 @@ def test_set_custom_domain():
def test_set_invalid_custom_domain(): def test_set_invalid_custom_domain():
user = User.get(user_id) user = User.get(user_id)
with pytest.raises(user_settings.CannotSetAlias): with pytest.raises(user_settings.CannotSetAlias):
user_settings.set_default_alias_id(user, "invalid_nop" + random_token()) user_settings.set_default_alias_domain(user, "invalid_nop" + random_token())