fix test
This commit is contained in:
parent
3308919906
commit
3e1f098c79
|
@ -6,59 +6,7 @@ from app.extensions import db
|
|||
from app.models import User, ApiKey, AliasUsedOn, Alias
|
||||
|
||||
|
||||
def test_different_scenarios(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c",
|
||||
password="password",
|
||||
name="Test User",
|
||||
activated=True,
|
||||
commit=True,
|
||||
)
|
||||
|
||||
# create api_key
|
||||
api_key = ApiKey.create(user.id, "for test")
|
||||
db.session.commit()
|
||||
|
||||
# <<< without hostname >>>
|
||||
r = flask_client.get(
|
||||
url_for("api.options"), headers={"Authentication": api_key.code}
|
||||
)
|
||||
|
||||
# {
|
||||
# "can_create_custom": True,
|
||||
# "custom": {"suffixes": ["azdwbw@sl.local"], "suggestion": ""},
|
||||
# "existing": ["cat_cat_cat@sl.local"],
|
||||
# }
|
||||
assert r.status_code == 200
|
||||
assert r.json["can_create_custom"]
|
||||
assert len(r.json["existing"]) == 1
|
||||
assert len(r.json["custom"]["suffixes"]) == 4
|
||||
|
||||
assert r.json["custom"]["suggestion"] == "" # no hostname => no suggestion
|
||||
|
||||
# <<< with hostname >>>
|
||||
r = flask_client.get(
|
||||
url_for("api.options", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
|
||||
assert r.json["custom"]["suggestion"] == "test"
|
||||
|
||||
# <<< with recommendation >>>
|
||||
alias = Alias.create_new(user, prefix="test")
|
||||
db.session.commit()
|
||||
AliasUsedOn.create(alias_id=alias.id, hostname="www.test.com", user_id=user.id)
|
||||
db.session.commit()
|
||||
|
||||
r = flask_client.get(
|
||||
url_for("api.options", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
assert r.json["recommendation"]["alias"] == alias.email
|
||||
assert r.json["recommendation"]["hostname"] == "www.test.com"
|
||||
|
||||
|
||||
def test_different_scenarios_v2(flask_client):
|
||||
def test_different_scenarios_v4(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c", password="password", name="Test User", activated=True
|
||||
)
|
||||
|
@ -70,54 +18,7 @@ def test_different_scenarios_v2(flask_client):
|
|||
|
||||
# <<< without hostname >>>
|
||||
r = flask_client.get(
|
||||
url_for("api.options_v2"), headers={"Authentication": api_key.code}
|
||||
)
|
||||
|
||||
assert r.status_code == 200
|
||||
# {'can_create': True, 'existing': ['my-first-alias.chat@sl.local'], 'prefix_suggestion': '', 'suffixes': ['.meo@sl.local']}
|
||||
|
||||
assert r.json["can_create"]
|
||||
assert len(r.json["existing"]) == 1
|
||||
assert r.json["suffixes"]
|
||||
assert r.json["prefix_suggestion"] == "" # no hostname => no suggestion
|
||||
|
||||
# <<< with hostname >>>
|
||||
r = flask_client.get(
|
||||
url_for("api.options_v2", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
|
||||
assert r.json["prefix_suggestion"] == "test"
|
||||
|
||||
# <<< with recommendation >>>
|
||||
alias = Alias.create_new(user, prefix="test")
|
||||
db.session.commit()
|
||||
AliasUsedOn.create(
|
||||
alias_id=alias.id, hostname="www.test.com", user_id=alias.user_id
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
r = flask_client.get(
|
||||
url_for("api.options_v2", hostname="www.test.com"),
|
||||
headers={"Authentication": api_key.code},
|
||||
)
|
||||
assert r.json["recommendation"]["alias"] == alias.email
|
||||
assert r.json["recommendation"]["hostname"] == "www.test.com"
|
||||
|
||||
|
||||
def test_different_scenarios_v3(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c", password="password", name="Test User", activated=True
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
# create api_key
|
||||
api_key = ApiKey.create(user.id, "for test")
|
||||
db.session.commit()
|
||||
|
||||
# <<< without hostname >>>
|
||||
r = flask_client.get(
|
||||
url_for("api.options_v3"), headers={"Authentication": api_key.code}
|
||||
"/api/v4/alias/options", headers={"Authentication": api_key.code}
|
||||
)
|
||||
|
||||
assert r.status_code == 200
|
||||
|
|
|
@ -9,37 +9,6 @@ from app.utils import random_word
|
|||
from tests.utils import login
|
||||
|
||||
|
||||
def test_v1(flask_client):
|
||||
login(flask_client)
|
||||
|
||||
word = random_word()
|
||||
suffix = f".{word}@{EMAIL_DOMAIN}"
|
||||
|
||||
r = flask_client.post(
|
||||
"/api/alias/custom/new",
|
||||
json={
|
||||
"alias_prefix": "prefix",
|
||||
"alias_suffix": suffix,
|
||||
},
|
||||
)
|
||||
|
||||
assert r.status_code == 201
|
||||
assert r.json["alias"] == f"prefix.{word}@{EMAIL_DOMAIN}"
|
||||
|
||||
res = r.json
|
||||
assert "id" in res
|
||||
assert "email" in res
|
||||
assert "creation_date" in res
|
||||
assert "creation_timestamp" in res
|
||||
assert "nb_forward" in res
|
||||
assert "nb_block" in res
|
||||
assert "nb_reply" in res
|
||||
assert "enabled" in res
|
||||
|
||||
new_alias: Alias = Alias.get_by(email=r.json["alias"])
|
||||
assert len(new_alias.mailboxes) == 1
|
||||
|
||||
|
||||
def test_v2(flask_client):
|
||||
login(flask_client)
|
||||
|
||||
|
|
Loading…
Reference in New Issue