-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 8: Email address changes (8h)
- Loading branch information
1 parent
4711144
commit 809d39f
Showing
8 changed files
with
124 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends "base.html" %} | ||
{% import "bootstrap/wtf.html" as wtf %} | ||
|
||
{% block title %}Flasky - Change Email Address{% endblock %} | ||
|
||
{% block page_content %} | ||
<div class="page-header"> | ||
<h1>Change Your Email Address</h1> | ||
</div> | ||
<div class="col-md-4"> | ||
{{ wtf.quick_form(form) }} | ||
</div> | ||
{% endblock %} |
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,7 @@ | ||
<p>Dear {{ user.username }},</p> | ||
<p>To confirm your new email address <a href="{{ url_for('auth.change_email', token=token, _external=True) }}">click here</a>.</p> | ||
<p>Alternatively, you can paste the following link in your browser's address bar:</p> | ||
<p>{{ url_for('auth.change_email', token=token, _external=True) }}</p> | ||
<p>Sincerely,</p> | ||
<p>The Flasky Team</p> | ||
<p><small>Note: replies to this email address are not monitored.</small></p> |
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,11 @@ | ||
Dear {{ user.username }}, | ||
|
||
To confirm your new email address click on the following link: | ||
|
||
{{ url_for('auth.change_email', token=token, _external=True) }} | ||
|
||
Sincerely, | ||
|
||
The Flasky Team | ||
|
||
Note: replies to this email address are not monitored. |
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 |
---|---|---|
|
@@ -74,3 +74,31 @@ def test_invalid_reset_token(self): | |
token = u.generate_reset_token() | ||
self.assertFalse(User.reset_password(token + 'a', 'horse')) | ||
self.assertTrue(u.verify_password('cat')) | ||
|
||
def test_valid_email_change_token(self): | ||
u = User(email='[email protected]', password='cat') | ||
db.session.add(u) | ||
db.session.commit() | ||
token = u.generate_email_change_token('[email protected]') | ||
self.assertTrue(u.change_email(token)) | ||
self.assertTrue(u.email == '[email protected]') | ||
|
||
def test_invalid_email_change_token(self): | ||
u1 = User(email='[email protected]', password='cat') | ||
u2 = User(email='[email protected]', password='dog') | ||
db.session.add(u1) | ||
db.session.add(u2) | ||
db.session.commit() | ||
token = u1.generate_email_change_token('[email protected]') | ||
self.assertFalse(u2.change_email(token)) | ||
self.assertTrue(u2.email == '[email protected]') | ||
|
||
def test_duplicate_email_change_token(self): | ||
u1 = User(email='[email protected]', password='cat') | ||
u2 = User(email='[email protected]', password='dog') | ||
db.session.add(u1) | ||
db.session.add(u2) | ||
db.session.commit() | ||
token = u2.generate_email_change_token('[email protected]') | ||
self.assertFalse(u2.change_email(token)) | ||
self.assertTrue(u2.email == '[email protected]') |
809d39f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I'm sorry if my question is very obvious or dumb but,
Why do these tests pass when I clone the repo, go to this commit and do the unit tests if
there is no
data-dev.sqlite
file?When I do this tests with my own
data-dev.sqlite
I have to delete the file,upgrade the database to the last version and do the tests, because if I do several tests in a row
I keep having this error of violating the unique constraint on e-mail column for the users table, namely:
Thanks.
809d39f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cmarsa the data-dev.sqlite database is used by your development web server, not by the tests. If this database is used when you run your tests, then you have an issue with your test configuration. The tests should override the
DATABASE_URL
setting to install their own database.809d39f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I forgot to write the
setUp
andtearDown
methods on theUserModelTestCase
class.Thank you.
809d39f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I fell prey to the setUp and tearDown issue a few weeks ago as well. Took me a couple of days to figure it out.