Son NK 5 years ago
parent
commit
6ddb8ee5ab
4 changed files with 13 additions and 10 deletions
  1. 4 3
      server.py
  2. 1 1
      tests/api/test_alias_options.py
  3. 3 3
      tests/api/test_new_custom_alias.py
  4. 5 3
      tests/test_models.py

+ 4 - 3
server.py

@@ -21,6 +21,7 @@ from app.config import (
     SHA1,
     PADDLE_MONTHLY_PRODUCT_ID,
     RESET_DB,
+    EMAIL_DOMAIN,
 )
 from app.dashboard.base import dashboard_bp
 from app.developer.base import developer_bp
@@ -118,9 +119,9 @@ def fake_data():
     api_key = ApiKey.create(user_id=user.id, name="Chrome")
     api_key.code = "code"
 
-    GenEmail.create_new_gen_email(user_id=user.id)
-
-    GenEmail.create_new_gen_email(user_id=user.id, custom=True)
+    GenEmail.create_custom_alias(user.id, "e1@")
+    GenEmail.create_custom_alias(user.id, "e2@")
+    GenEmail.create_custom_alias(user.id, "e3@")
 
     # Create a client
     client1 = Client.create_new(name="Demo", user_id=user.id)

+ 1 - 1
tests/api/test_alias_options.py

@@ -41,7 +41,7 @@ def test_different_scenarios(flask_client):
     assert r.json["custom"]["suggestion"] == "test"
 
     # <<< with recommendation >>>
-    alias = GenEmail.create_new_gen_email(user.id)
+    alias = GenEmail.create_custom_alias(user.id, prefix="test")
     db.session.commit()
     AliasUsedOn.create(gen_email_id=alias.id, hostname="www.test.com")
     db.session.commit()

+ 3 - 3
tests/api/test_new_custom_alias.py

@@ -36,9 +36,9 @@ def test_out_of_quota(flask_client):
     db.session.commit()
 
     # create 3 custom alias to run out of quota
-    GenEmail.create_new_gen_email(user.id, custom=True)
-    GenEmail.create_new_gen_email(user.id, custom=True)
-    GenEmail.create_new_gen_email(user.id, custom=True)
+    GenEmail.create_custom_alias(user.id, prefix="test")
+    GenEmail.create_custom_alias(user.id, prefix="test")
+    GenEmail.create_custom_alias(user.id, prefix="test")
 
     r = flask_client.post(
         url_for("api.new_custom_alias", hostname="www.test.com"),

+ 5 - 3
tests/test_models.py

@@ -25,10 +25,12 @@ def test_suggested_emails_for_user_who_can_create_new_random_alias(flask_client)
     )
     db.session.commit()
 
-    suggested_email, other_emails = user.suggested_emails()
+    suggested_email, other_emails = user.suggested_emails(website_name="test")
     assert suggested_email
     assert len(other_emails) == 1
 
+    db.session.rollback()
+
     # the suggested email is new and not exist in GenEmail
     assert GenEmail.get_by(email=suggested_email) is None
 
@@ -44,10 +46,10 @@ def test_suggested_emails_for_user_who_cannot_create_new_email(flask_client):
 
     # make sure user runs out of quota to create new email
     for i in range(MAX_NB_EMAIL_FREE_PLAN):
-        GenEmail.create_new_gen_email(user_id=user.id)
+        GenEmail.create_custom_alias(user_id=user.id, prefix="test")
     db.session.commit()
 
-    suggested_email, other_emails = user.suggested_emails()
+    suggested_email, other_emails = user.suggested_emails(website_name="test")
 
     # the suggested email is chosen from existing GenEmail
     assert GenEmail.get_by(email=suggested_email)