-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from diverso-lab/develop
Develop
- Loading branch information
Showing
5 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import time | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from flask import url_for | ||
|
||
from app import mail_service | ||
from app.modules.auth.services import AuthenticationService | ||
from app.modules.auth.repositories import UserRepository | ||
from app.modules.profile.repositories import UserProfileRepository | ||
|
@@ -122,3 +125,74 @@ def test_service_create_with_profile_fail_no_password(clean_database): | |
|
||
assert UserRepository().count() == 0 | ||
assert UserProfileRepository().count() == 0 | ||
|
||
|
||
@patch('app.modules.captcha.services.CaptchaService.validate_captcha', return_value=True) | ||
def test_signup_send_confirmation_email(mock_captcha, test_client, clean_database): | ||
data = { | ||
"name": "Test", | ||
"surname": "Foo", | ||
"email": "[email protected]", | ||
"password": "test1234", | ||
"captcha": "dummy_captcha" | ||
} | ||
|
||
with mail_service.mail.record_messages() as outbox: | ||
test_client.post("/signup", data=data, follow_redirects=True) | ||
assert len(outbox) == 1 | ||
|
||
|
||
def test_create_with_profile_create_inactive_user(test_client, clean_database): | ||
data = { | ||
"name": "Test", | ||
"surname": "Foo", | ||
"email": "[email protected]", | ||
"password": "test1234" | ||
} | ||
user = AuthenticationService().create_with_profile(**data) | ||
assert UserRepository().count() == 1 | ||
assert UserProfileRepository().count() == 1 | ||
assert user.active is False | ||
|
||
|
||
def test_confirm_user_token_expired(test_client): | ||
email = "[email protected]" | ||
|
||
with patch("time.time", return_value=time.time() - (AuthenticationService.MAX_AGE + 1)): | ||
token = AuthenticationService().get_token_from_email(email) | ||
|
||
url = url_for('auth.confirm_user', token=token, _external=False) | ||
response = test_client.get(url, follow_redirects=True) | ||
assert response.request.path == url_for("auth.show_signup_form", _external=False) | ||
|
||
|
||
def test_confirm_user_token_tempered(test_client): | ||
email = "[email protected]" | ||
|
||
AuthenticationService.SALT = "bad_salt" | ||
token = AuthenticationService().get_token_from_email(email) | ||
|
||
AuthenticationService.SALT = "user-confirm" | ||
url = url_for('auth.confirm_user', token=token, _external=False) | ||
response = test_client.get(url, follow_redirects=True) | ||
assert response.request.path == url_for("auth.show_signup_form", _external=False) | ||
|
||
|
||
def test_confirm_user_active_user(test_client): | ||
data = { | ||
"name": "Test", | ||
"surname": "Foo", | ||
"email": "[email protected]", | ||
"password": "test1234" | ||
} | ||
user = AuthenticationService().create_with_profile(**data) | ||
assert user.active is False | ||
|
||
token = AuthenticationService().get_token_from_email(user.email) | ||
|
||
url = url_for('auth.confirm_user', token=token, _external=False) | ||
response = test_client.get(url, follow_redirects=True) | ||
assert response.request.path == url_for("public.index", _external=False) | ||
|
||
user = UserRepository().get_by_email(user.email) | ||
assert user.active is True |