From ad1cf3af8c9c99547c71126178335330fdd76d7d Mon Sep 17 00:00:00 2001 From: Son NK Date: Thu, 30 Jan 2020 13:20:32 +0700 Subject: [PATCH] fix test --- app/models.py | 5 ++++- local_data/words.txt | 6 +++++- tests/api/test_new_custom_alias.py | 1 + tests/api/test_new_random_alias.py | 5 ++--- tests/api/test_user_info.py | 4 ++-- tests/test_models.py | 10 ++++++++-- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/models.py b/app/models.py index 6061313d..6ee7799d 100644 --- a/app/models.py +++ b/app/models.py @@ -177,7 +177,10 @@ class User(db.Model, ModelMixin, UserMixin): if self.lifetime_or_active_subscription(): return True - return self.trial_end and arrow.now() < self.trial_end + if self.trial_end and arrow.now() < self.trial_end: + return True + + return False def can_create_new_alias(self) -> bool: if self.is_premium(): diff --git a/local_data/words.txt b/local_data/words.txt index 3c69bf08..32dd3b1b 100644 --- a/local_data/words.txt +++ b/local_data/words.txt @@ -1,3 +1,7 @@ meo cat -chat \ No newline at end of file +chat +alo +hey +yeah +yes \ No newline at end of file diff --git a/tests/api/test_new_custom_alias.py b/tests/api/test_new_custom_alias.py index e5107956..3d75d612 100644 --- a/tests/api/test_new_custom_alias.py +++ b/tests/api/test_new_custom_alias.py @@ -32,6 +32,7 @@ def test_out_of_quota(flask_client): user = User.create( email="a@b.c", password="password", name="Test User", activated=True ) + user.trial_end = None db.session.commit() # create api_key diff --git a/tests/api/test_new_random_alias.py b/tests/api/test_new_random_alias.py index a50f3c1f..6eb692b5 100644 --- a/tests/api/test_new_random_alias.py +++ b/tests/api/test_new_random_alias.py @@ -28,17 +28,16 @@ def test_out_of_quota(flask_client): user = User.create( email="a@b.c", password="password", name="Test User", activated=True ) + user.trial_end = None db.session.commit() # create api_key api_key = ApiKey.create(user.id, "for test") db.session.commit() - # create 3 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): GenEmail.create_new(user.id, prefix="test1") - GenEmail.create_new(user.id, prefix="test2") - GenEmail.create_new(user.id, prefix="test3") r = flask_client.post( url_for("api.new_random_alias", hostname="www.test.com"), diff --git a/tests/api/test_user_info.py b/tests/api/test_user_info.py index ffa96edf..a7aeacd4 100644 --- a/tests/api/test_user_info.py +++ b/tests/api/test_user_info.py @@ -4,7 +4,7 @@ from app.extensions import db from app.models import User, ApiKey, AliasUsedOn, GenEmail -def test_success(flask_client): +def test_user_in_trial(flask_client): user = User.create( email="a@b.c", password="password", name="Test User", activated=True ) @@ -19,7 +19,7 @@ def test_success(flask_client): ) assert r.status_code == 200 - assert r.json == {"is_premium": False, "name": "Test User"} + assert r.json == {"is_premium": True, "name": "Test User"} def test_wrong_api_key(flask_client): diff --git a/tests/test_models.py b/tests/test_models.py index 741270e1..e386c20e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -28,10 +28,16 @@ def test_profile_picture_url(flask_client): assert user.profile_picture_url() == "http://sl.test/static/default-avatar.png" -def test_suggested_emails_for_user_who_cannot_create_new_email(flask_client): +def test_suggested_emails_for_user_who_cannot_create_new_alias(flask_client): + # make sure user is not in trial 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, + trial_end=None, ) + db.session.commit() # make sure user runs out of quota to create new email