fix test
This commit is contained in:
parent
a6f4059d5d
commit
3b454b9a80
|
@ -154,14 +154,14 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# create a first alias mail to show user how to use when they login
|
|
||||||
GenEmail.create_new(user.id, prefix="my-first-alias")
|
|
||||||
db.session.flush()
|
|
||||||
|
|
||||||
mb = Mailbox.create(user_id=user.id, email=user.email, verified=True)
|
mb = Mailbox.create(user_id=user.id, email=user.email, verified=True)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
user.default_mailbox_id = mb.id
|
user.default_mailbox_id = mb.id
|
||||||
|
|
||||||
|
# create a first alias mail to show user how to use when they login
|
||||||
|
GenEmail.create_new(user, prefix="my-first-alias", mailbox_id=mb.id)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
# Schedule onboarding emails
|
# Schedule onboarding emails
|
||||||
Job.create(
|
Job.create(
|
||||||
name=JOB_ONBOARDING_1,
|
name=JOB_ONBOARDING_1,
|
||||||
|
@ -272,9 +272,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
|
|
||||||
all_gen_emails = [ge.email for ge in GenEmail.filter_by(user_id=self.id)]
|
all_gen_emails = [ge.email for ge in GenEmail.filter_by(user_id=self.id)]
|
||||||
if self.can_create_new_alias():
|
if self.can_create_new_alias():
|
||||||
suggested_gen_email = GenEmail.create_new(
|
suggested_gen_email = GenEmail.create_new(self, prefix=website_name).email
|
||||||
self.id, prefix=website_name
|
|
||||||
).email
|
|
||||||
else:
|
else:
|
||||||
# pick an email from the list of gen emails
|
# pick an email from the list of gen emails
|
||||||
suggested_gen_email = random.choice(all_gen_emails)
|
suggested_gen_email = random.choice(all_gen_emails)
|
||||||
|
@ -553,7 +551,7 @@ class GenEmail(db.Model, ModelMixin):
|
||||||
mailbox = db.relationship("Mailbox")
|
mailbox = db.relationship("Mailbox")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_new(cls, user_id, prefix, note=None, mailbox_id=None):
|
def create_new(cls, user, prefix, note=None, mailbox_id=None):
|
||||||
if not prefix:
|
if not prefix:
|
||||||
raise Exception("alias prefix cannot be empty")
|
raise Exception("alias prefix cannot be empty")
|
||||||
|
|
||||||
|
@ -566,7 +564,10 @@ class GenEmail(db.Model, ModelMixin):
|
||||||
break
|
break
|
||||||
|
|
||||||
return GenEmail.create(
|
return GenEmail.create(
|
||||||
user_id=user_id, email=email, note=note, mailbox_id=mailbox_id
|
user_id=user.id,
|
||||||
|
email=email,
|
||||||
|
note=note,
|
||||||
|
mailbox_id=mailbox_id or user.default_mailbox_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -160,7 +160,7 @@ def fake_data():
|
||||||
|
|
||||||
user.default_mailbox_id = m1.id
|
user.default_mailbox_id = m1.id
|
||||||
|
|
||||||
GenEmail.create_new(user.id, "e1@", mailbox_id=m1.id)
|
GenEmail.create_new(user, "e1@", mailbox_id=m1.id)
|
||||||
|
|
||||||
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
||||||
CustomDomain.create(
|
CustomDomain.create(
|
||||||
|
|
|
@ -27,7 +27,7 @@ def test_different_scenarios(flask_client):
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.json["can_create_custom"]
|
assert r.json["can_create_custom"]
|
||||||
assert len(r.json["existing"]) == 1
|
assert len(r.json["existing"]) == 1
|
||||||
assert len(r.json["custom"]["suffixes"]) == 3
|
assert len(r.json["custom"]["suffixes"]) == 4
|
||||||
|
|
||||||
assert r.json["custom"]["suggestion"] == "" # no hostname => no suggestion
|
assert r.json["custom"]["suggestion"] == "" # no hostname => no suggestion
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def test_different_scenarios(flask_client):
|
||||||
assert r.json["custom"]["suggestion"] == "test"
|
assert r.json["custom"]["suggestion"] == "test"
|
||||||
|
|
||||||
# <<< with recommendation >>>
|
# <<< with recommendation >>>
|
||||||
alias = GenEmail.create_new(user.id, prefix="test")
|
alias = GenEmail.create_new(user, prefix="test")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
AliasUsedOn.create(gen_email_id=alias.id, hostname="www.test.com")
|
AliasUsedOn.create(gen_email_id=alias.id, hostname="www.test.com")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -85,7 +85,7 @@ def test_different_scenarios_v2(flask_client):
|
||||||
assert r.json["prefix_suggestion"] == "test"
|
assert r.json["prefix_suggestion"] == "test"
|
||||||
|
|
||||||
# <<< with recommendation >>>
|
# <<< with recommendation >>>
|
||||||
alias = GenEmail.create_new(user.id, prefix="test")
|
alias = GenEmail.create_new(user, prefix="test")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
AliasUsedOn.create(gen_email_id=alias.id, hostname="www.test.com")
|
AliasUsedOn.create(gen_email_id=alias.id, hostname="www.test.com")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -41,7 +41,7 @@ def test_out_of_quota(flask_client):
|
||||||
|
|
||||||
# create MAX_NB_EMAIL_FREE_PLAN custom alias to run out of quota
|
# create MAX_NB_EMAIL_FREE_PLAN custom alias to run out of quota
|
||||||
for _ in range(MAX_NB_EMAIL_FREE_PLAN):
|
for _ in range(MAX_NB_EMAIL_FREE_PLAN):
|
||||||
GenEmail.create_new(user.id, prefix="test")
|
GenEmail.create_new(user, prefix="test")
|
||||||
|
|
||||||
word = random_word()
|
word = random_word()
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
|
|
|
@ -61,7 +61,7 @@ def test_out_of_quota(flask_client):
|
||||||
|
|
||||||
# create MAX_NB_EMAIL_FREE_PLAN random alias to run out of quota
|
# create MAX_NB_EMAIL_FREE_PLAN random alias to run out of quota
|
||||||
for _ in range(MAX_NB_EMAIL_FREE_PLAN):
|
for _ in range(MAX_NB_EMAIL_FREE_PLAN):
|
||||||
GenEmail.create_new(user.id, prefix="test1")
|
GenEmail.create_new(user, prefix="test1")
|
||||||
|
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("api.new_random_alias", hostname="www.test.com"),
|
url_for("api.new_random_alias", hostname="www.test.com"),
|
||||||
|
|
|
@ -5,7 +5,7 @@ URL=http://localhost
|
||||||
# Only print email content, not sending it
|
# Only print email content, not sending it
|
||||||
NOT_SEND_EMAIL=true
|
NOT_SEND_EMAIL=true
|
||||||
EMAIL_DOMAIN=sl.local
|
EMAIL_DOMAIN=sl.local
|
||||||
OTHER_ALIAS_DOMAINS=["d1.test", "d2.test"]
|
OTHER_ALIAS_DOMAINS=["d1.test", "d2.test", "sl.local"]
|
||||||
SUPPORT_EMAIL=support@sl.local
|
SUPPORT_EMAIL=support@sl.local
|
||||||
ADMIN_EMAIL=to_fill
|
ADMIN_EMAIL=to_fill
|
||||||
# Max number emails user can generate for free plan
|
# Max number emails user can generate for free plan
|
||||||
|
|
|
@ -42,7 +42,7 @@ def test_suggested_emails_for_user_who_cannot_create_new_alias(flask_client):
|
||||||
|
|
||||||
# make sure user runs out of quota to create new email
|
# make sure user runs out of quota to create new email
|
||||||
for i in range(MAX_NB_EMAIL_FREE_PLAN):
|
for i in range(MAX_NB_EMAIL_FREE_PLAN):
|
||||||
GenEmail.create_new(user_id=user.id, prefix="test")
|
GenEmail.create_new(user=user, prefix="test")
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
suggested_email, other_emails = user.suggested_emails(website_name="test")
|
suggested_email, other_emails = user.suggested_emails(website_name="test")
|
||||||
|
|
Loading…
Reference in a new issue