forked from opencve/opencve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check if email is unique when editing a profile
- Loading branch information
Showing
3 changed files
with
90 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
from flask import request | ||
|
||
from opencve.models.users import User | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"first_name,last_name,email", | ||
[ | ||
("john", "doe", "[email protected]"), | ||
("john", "", "[email protected]"), | ||
("", "doe", "[email protected]"), | ||
("", "", "[email protected]"), | ||
("", "", "[email protected]"), | ||
], | ||
) | ||
def test_edit_profile(login, client, first_name, last_name, email): | ||
user = User.query.first() | ||
assert user.first_name == "" | ||
assert user.last_name == "" | ||
assert user.email == "[email protected]" | ||
|
||
client.post( | ||
"/account/profile", | ||
data={"first_name": first_name, "last_name": last_name, "email": email}, | ||
follow_redirects=True, | ||
) | ||
|
||
user = User.query.first() | ||
assert user.first_name == first_name | ||
assert user.last_name == last_name | ||
assert user.email == email | ||
|
||
|
||
def test_edit_profile_email_required(login, client): | ||
response = client.post( | ||
"/account/profile", data={"email": ""}, follow_redirects=True | ||
) | ||
assert b"This field is required." in response.data | ||
|
||
|
||
def test_edit_profile_with_existing_email(login, create_user, client): | ||
user = User.query.filter_by(username="user").first() | ||
assert user.email == "[email protected]" | ||
|
||
create_user("user2") | ||
|
||
response = client.post( | ||
"/account/profile", data={"email": "[email protected]"}, follow_redirects=True | ||
) | ||
assert b"This Email is already in use. Please try another one" in response.data | ||
|
||
# Email has not changed | ||
user = User.query.filter_by(username="user").first() | ||
assert user.email == "[email protected]" |