-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't call a lifecycle hook twice with the same state.
This allows users to listen for multiple specific change events and handle them all in a single function.
- Loading branch information
Showing
6 changed files
with
48 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ __pycache__/ | |
README.txt | ||
.tox | ||
django_lifecycle.egg-info | ||
site/ | ||
site/ | ||
.idea/ | ||
venv/ |
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,18 @@ | ||
# Generated by Django 2.2.8 on 2020-02-03 10:45 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('testapp', '0002_auto_20190928_2324'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='useraccount', | ||
name='name_changes', | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -56,6 +56,13 @@ def test_email_after_delete(self): | |
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual(mail.outbox[0].subject, "We have deleted your account") | ||
|
||
def test_only_call_hook_once(self): | ||
account = UserAccount.objects.create(**self.stub_data) | ||
account.first_name = "Waylon" | ||
account.last_name = "Smithers" | ||
account.save() | ||
self.assertEqual(account.name_changes, 1) | ||
|
||
def test_lowercase_email(self): | ||
data = self.stub_data | ||
data["email"] = "[email protected]" | ||
|