|
@@ -1,3 +1,5 @@
|
|
|
|
+import uuid
|
|
|
|
+
|
|
from flask import url_for
|
|
from flask import url_for
|
|
|
|
|
|
from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN
|
|
from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN
|
|
@@ -24,6 +26,28 @@ def test_success(flask_client):
|
|
assert r.json["alias"].endswith(EMAIL_DOMAIN)
|
|
assert r.json["alias"].endswith(EMAIL_DOMAIN)
|
|
|
|
|
|
|
|
|
|
|
|
+def test_custom_mode(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()
|
|
|
|
+
|
|
|
|
+ r = flask_client.post(
|
|
|
|
+ url_for("api.new_random_alias", hostname="www.test.com", mode="uuid"),
|
|
|
|
+ headers={"Authentication": api_key.code},
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ assert r.status_code == 201
|
|
|
|
+ # extract the uuid part
|
|
|
|
+ alias = r.json["alias"]
|
|
|
|
+ uuid_part = alias[: len(alias) - len(EMAIL_DOMAIN) - 1]
|
|
|
|
+ assert is_valid_uuid(uuid_part)
|
|
|
|
+
|
|
|
|
+
|
|
def test_out_of_quota(flask_client):
|
|
def test_out_of_quota(flask_client):
|
|
user = User.create(
|
|
user = User.create(
|
|
email="a@b.c", password="password", name="Test User", activated=True
|
|
email="a@b.c", password="password", name="Test User", activated=True
|
|
@@ -49,3 +73,11 @@ def test_out_of_quota(flask_client):
|
|
r.json["error"]
|
|
r.json["error"]
|
|
== "You have reached the limitation of a free account with the maximum of 3 aliases, please upgrade your plan to create more aliases"
|
|
== "You have reached the limitation of a free account with the maximum of 3 aliases, please upgrade your plan to create more aliases"
|
|
)
|
|
)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def is_valid_uuid(val):
|
|
|
|
+ try:
|
|
|
|
+ uuid.UUID(str(val))
|
|
|
|
+ return True
|
|
|
|
+ except ValueError:
|
|
|
|
+ return False
|