2020-10-28 17:47:26 +01:00
|
|
|
import json
|
|
|
|
|
2020-11-15 19:43:37 +01:00
|
|
|
from app.models import CustomDomain, AliasGeneratorEnum, SenderFormatEnum
|
2020-11-15 19:35:07 +01:00
|
|
|
from tests.utils import login, pretty
|
2020-10-28 17:23:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_setting(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
|
|
|
|
r = flask_client.get("/api/setting")
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json == {
|
2020-10-28 17:47:26 +01:00
|
|
|
"alias_generator": "word",
|
2020-10-28 17:23:58 +01:00
|
|
|
"notification": True,
|
|
|
|
"random_alias_default_domain": "sl.local",
|
2020-11-15 19:35:07 +01:00
|
|
|
"sender_format": "VIA",
|
2020-10-28 17:23:58 +01:00
|
|
|
}
|
2020-10-28 17:30:57 +01:00
|
|
|
|
|
|
|
|
2020-10-28 17:47:26 +01:00
|
|
|
def test_update_settings_notification(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
assert user.notification
|
|
|
|
|
|
|
|
r = flask_client.patch("/api/setting", json={"notification": False})
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert not user.notification
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_settings_alias_generator(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
assert user.alias_generator == AliasGeneratorEnum.word.value
|
|
|
|
|
|
|
|
r = flask_client.patch("/api/setting", json={"alias_generator": "invalid"})
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
|
|
|
r = flask_client.patch("/api/setting", json={"alias_generator": "uuid"})
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert user.alias_generator == AliasGeneratorEnum.uuid.value
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_settings_random_alias_default_domain(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
assert user.default_random_alias_domain() == "sl.local"
|
|
|
|
|
|
|
|
r = flask_client.patch(
|
|
|
|
"/api/setting", json={"random_alias_default_domain": "invalid"}
|
|
|
|
)
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
|
|
|
r = flask_client.patch(
|
|
|
|
"/api/setting", json={"random_alias_default_domain": "d1.test"}
|
|
|
|
)
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert user.default_random_alias_domain() == "d1.test"
|
|
|
|
|
|
|
|
|
2020-11-15 19:43:37 +01:00
|
|
|
def test_update_settings_sender_format(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
assert user.sender_format == SenderFormatEnum.VIA.value
|
|
|
|
|
|
|
|
r = flask_client.patch("/api/setting", json={"sender_format": "invalid"})
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
|
|
|
r = flask_client.patch("/api/setting", json={"sender_format": "AT"})
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert user.sender_format == SenderFormatEnum.AT.value
|
|
|
|
|
|
|
|
|
2020-10-28 17:47:26 +01:00
|
|
|
def test_get_setting_domains(flask_client):
|
2020-10-28 17:30:57 +01:00
|
|
|
user = login(flask_client)
|
|
|
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True, commit=True)
|
|
|
|
|
|
|
|
r = flask_client.get("/api/setting/domains")
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json == [
|
|
|
|
[True, "d1.test"],
|
|
|
|
[True, "d2.test"],
|
|
|
|
[True, "sl.local"],
|
|
|
|
[False, "ab.cd"],
|
|
|
|
]
|
2020-11-14 16:37:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_setting_domains_v2(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True, commit=True)
|
|
|
|
|
|
|
|
r = flask_client.get("/api/v2/setting/domains")
|
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json == [
|
|
|
|
{"domain": "d1.test", "is_custom": False},
|
|
|
|
{"domain": "d2.test", "is_custom": False},
|
|
|
|
{"domain": "sl.local", "is_custom": False},
|
|
|
|
{"domain": "ab.cd", "is_custom": True},
|
|
|
|
]
|