-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted the
level
field from a CharField
to an IntegerField
- Loading branch information
1 parent
7915c66
commit c2ec8ac
Showing
8 changed files
with
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2.1 on 2023-06-02 00:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notifications", "0010_alter_notification_data"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="notification", | ||
name="new_level", | ||
field=models.IntegerField( | ||
choices=[(1, "Success"), (2, "Info"), (3, "Warning"), (4, "Error")], default=2, verbose_name="level" | ||
), | ||
), | ||
] |
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,21 @@ | ||
# Generated by Django 4.2.1 on 2023-06-02 00:05 | ||
|
||
from django.db import migrations | ||
from ..base.models import NotificationLevel | ||
|
||
def copy_level(apps, schema_editor): | ||
Notification = apps.get_model("notifications", "Notification") | ||
Notification.objects.filter(level="success").update(new_level=NotificationLevel.SUCCESS) | ||
Notification.objects.filter(level="info").update(new_level=NotificationLevel.INFO) | ||
Notification.objects.filter(level="warning").update(new_level=NotificationLevel.WARNING) | ||
Notification.objects.filter(level="error").update(new_level=NotificationLevel.ERROR) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notifications", "0011_notification_new_level"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(copy_level), | ||
] |
16 changes: 16 additions & 0 deletions
16
notifications/migrations/0013_remove_notification_level.py
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,16 @@ | ||
# Generated by Django 4.2.1 on 2023-06-16 01:04 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notifications", "0012_auto_20230601_1905"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="notification", | ||
name="level", | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
notifications/migrations/0014_rename_new_level_notification_level.py
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,17 @@ | ||
# Generated by Django 4.2.1 on 2023-06-16 01:04 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notifications", "0013_remove_notification_level"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="notification", | ||
old_name="new_level", | ||
new_name="level", | ||
), | ||
] |
Empty file.
53 changes: 53 additions & 0 deletions
53
notifications/tests/test_migrations/test_level_migration.py
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,53 @@ | ||
import factory | ||
|
||
from ...base.models import NotificationLevel | ||
from ..factories import users as user_factory | ||
|
||
|
||
def test_main_migration0002(migrator): | ||
"""Ensures that the second migration works.""" | ||
old_state = migrator.apply_initial_migration(("notifications", "0011_notification_new_level")) | ||
|
||
OldUser = old_state.apps.get_model("auth", "User") | ||
OldNotification = old_state.apps.get_model("notifications", "Notification") | ||
OldContentType = old_state.apps.get_model("contenttypes", "ContentType") | ||
|
||
mark_follower = factory.create(OldUser, FACTORY_CLASS=user_factory.Recipient) | ||
guido = factory.create(OldUser, FACTORY_CLASS=user_factory.Target) | ||
mark = factory.create(OldUser, FACTORY_CLASS=user_factory.Actor) | ||
|
||
user_type = OldContentType.objects.get_for_model(mark) | ||
notification_base = { | ||
"recipient": mark_follower, | ||
"actor_content_type": user_type, | ||
"actor_object_id": mark.pk, | ||
"verb": "start follow", | ||
"target_content_type": user_type, | ||
"target_object_id": guido.pk, | ||
} | ||
OldNotification(level="success", **notification_base).save() | ||
OldNotification(level="info", **notification_base).save() | ||
OldNotification(level="warning", **notification_base).save() | ||
OldNotification(level="error", **notification_base).save() | ||
|
||
assert OldNotification.objects.count() == 4 | ||
assert OldNotification.objects.filter(level="info").count() == 1 | ||
assert OldNotification.objects.filter(new_level=NotificationLevel.INFO).count() == 4 | ||
|
||
new_state = migrator.apply_tested_migration(("notifications", "0012_auto_20230601_1905")) | ||
NewNotification = new_state.apps.get_model("notifications", "Notification") | ||
|
||
assert NewNotification.objects.count() == 4 | ||
assert NewNotification.objects.filter(new_level=NotificationLevel.SUCCESS).count() == 1 | ||
assert NewNotification.objects.filter(new_level=NotificationLevel.INFO).count() == 1 | ||
assert NewNotification.objects.filter(new_level=NotificationLevel.WARNING).count() == 1 | ||
assert NewNotification.objects.filter(new_level=NotificationLevel.ERROR).count() == 1 | ||
|
||
new_state_2 = migrator.apply_tested_migration(("notifications", "0014_rename_new_level_notification_level")) | ||
NewNotification2 = new_state_2.apps.get_model("notifications", "Notification") | ||
|
||
assert NewNotification2.objects.count() == 4 | ||
assert NewNotification2.objects.filter(level=NotificationLevel.SUCCESS).count() == 1 | ||
assert NewNotification2.objects.filter(level=NotificationLevel.INFO).count() == 1 | ||
assert NewNotification2.objects.filter(level=NotificationLevel.WARNING).count() == 1 | ||
assert NewNotification2.objects.filter(level=NotificationLevel.ERROR).count() == 1 |