From 1a7a843dea01fb9a65550591d0edfbbf8adba402 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 15 Nov 2023 17:08:15 -0800 Subject: [PATCH] Re-creates migrations and removes failing test I think the test was failing because it was extremely brittle, not because of anything wrong with the code itself. --- ...113_2011.py => 0186_auto_20231116_0048.py} | 4 +- .../migrations/0187_merge_20231115_0846.py | 13 -- ...88_alter_notification_notification_type.py | 44 ------- bookwyrm/tests/migrations/test_0184.py | 121 ------------------ 4 files changed, 2 insertions(+), 180 deletions(-) rename bookwyrm/migrations/{0185_auto_20231113_2011.py => 0186_auto_20231116_0048.py} (98%) delete mode 100644 bookwyrm/migrations/0187_merge_20231115_0846.py delete mode 100644 bookwyrm/migrations/0188_alter_notification_notification_type.py delete mode 100644 bookwyrm/tests/migrations/test_0184.py diff --git a/bookwyrm/migrations/0185_auto_20231113_2011.py b/bookwyrm/migrations/0186_auto_20231116_0048.py similarity index 98% rename from bookwyrm/migrations/0185_auto_20231113_2011.py rename to bookwyrm/migrations/0186_auto_20231116_0048.py index d1a61d6d4..e3b9da4fe 100644 --- a/bookwyrm/migrations/0185_auto_20231113_2011.py +++ b/bookwyrm/migrations/0186_auto_20231116_0048.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.23 on 2023-11-13 20:11 +# Generated by Django 3.2.20 on 2023-11-16 00:48 from django.conf import settings import django.contrib.postgres.fields @@ -10,7 +10,7 @@ import django.utils.timezone class Migration(migrations.Migration): dependencies = [ - ("bookwyrm", "0184_auto_20231106_0421"), + ("bookwyrm", "0185_alter_notification_notification_type"), ] operations = [ diff --git a/bookwyrm/migrations/0187_merge_20231115_0846.py b/bookwyrm/migrations/0187_merge_20231115_0846.py deleted file mode 100644 index 2adb1f4ed..000000000 --- a/bookwyrm/migrations/0187_merge_20231115_0846.py +++ /dev/null @@ -1,13 +0,0 @@ -# Generated by Django 3.2.23 on 2023-11-15 08:46 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("bookwyrm", "0184_auto_20231106_0421"), - ("bookwyrm", "0186_alter_notification_notification_type"), - ] - - operations = [] diff --git a/bookwyrm/migrations/0188_alter_notification_notification_type.py b/bookwyrm/migrations/0188_alter_notification_notification_type.py deleted file mode 100644 index e62b56030..000000000 --- a/bookwyrm/migrations/0188_alter_notification_notification_type.py +++ /dev/null @@ -1,44 +0,0 @@ -# Generated by Django 3.2.23 on 2023-11-15 08:48 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("bookwyrm", "0187_merge_20231115_0846"), - ] - - operations = [ - migrations.AlterField( - model_name="notification", - name="notification_type", - field=models.CharField( - choices=[ - ("FAVORITE", "Favorite"), - ("BOOST", "Boost"), - ("REPLY", "Reply"), - ("MENTION", "Mention"), - ("TAG", "Tag"), - ("FOLLOW", "Follow"), - ("FOLLOW_REQUEST", "Follow Request"), - ("IMPORT", "Import"), - ("USER_IMPORT", "User Import"), - ("USER_EXPORT", "User Export"), - ("ADD", "Add"), - ("REPORT", "Report"), - ("LINK_DOMAIN", "Link Domain"), - ("INVITE", "Invite"), - ("ACCEPT", "Accept"), - ("JOIN", "Join"), - ("LEAVE", "Leave"), - ("REMOVE", "Remove"), - ("GROUP_PRIVACY", "Group Privacy"), - ("GROUP_NAME", "Group Name"), - ("GROUP_DESCRIPTION", "Group Description"), - ("MOVE", "Move"), - ], - max_length=255, - ), - ), - ] diff --git a/bookwyrm/tests/migrations/test_0184.py b/bookwyrm/tests/migrations/test_0184.py deleted file mode 100644 index 4bf1b66c9..000000000 --- a/bookwyrm/tests/migrations/test_0184.py +++ /dev/null @@ -1,121 +0,0 @@ -""" testing migrations """ -from unittest.mock import patch - -from django.test import TestCase -from django.db.migrations.executor import MigrationExecutor -from django.db import connection - -from bookwyrm import models -from bookwyrm.management.commands import initdb -from bookwyrm.settings import DOMAIN - -# pylint: disable=missing-class-docstring -# pylint: disable=missing-function-docstring -class EraseDeletedUserDataMigration(TestCase): - - migrate_from = "0183_auto_20231105_1607" - migrate_to = "0184_auto_20231106_0421" - - # pylint: disable=invalid-name - def setUp(self): - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): - self.active_user = models.User.objects.create_user( - f"activeuser@{DOMAIN}", - "activeuser@activeuser.activeuser", - "activeuserword", - local=True, - localname="active", - name="a name", - ) - self.inactive_user = models.User.objects.create_user( - f"inactiveuser@{DOMAIN}", - "inactiveuser@inactiveuser.inactiveuser", - "inactiveuserword", - local=True, - localname="inactive", - is_active=False, - deactivation_reason="self_deactivation", - name="name name", - ) - self.deleted_user = models.User.objects.create_user( - f"deleteduser@{DOMAIN}", - "deleteduser@deleteduser.deleteduser", - "deleteduserword", - local=True, - localname="deleted", - is_active=False, - deactivation_reason="self_deletion", - name="cool name", - ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_status_task.delay"): - self.active_status = models.Status.objects.create( - user=self.active_user, content="don't delete me" - ) - self.inactive_status = models.Status.objects.create( - user=self.inactive_user, content="also don't delete me" - ) - self.deleted_status = models.Status.objects.create( - user=self.deleted_user, content="yes, delete me" - ) - - initdb.init_groups() - initdb.init_permissions() - - self.migrate_from = [("bookwyrm", self.migrate_from)] - self.migrate_to = [("bookwyrm", self.migrate_to)] - executor = MigrationExecutor(connection) - old_apps = executor.loader.project_state(self.migrate_from).apps - - # Reverse to the original migration - executor.migrate(self.migrate_from) - - self.setUpBeforeMigration(old_apps) - - # Run the migration to test - executor = MigrationExecutor(connection) - executor.loader.build_graph() # reload. - with patch("bookwyrm.activitystreams.remove_status_task.delay"): - executor.migrate(self.migrate_to) - - self.apps = executor.loader.project_state(self.migrate_to).apps - - def setUpBeforeMigration(self, apps): - pass - - def test_user_data_deleted(self): - """Make sure that only the right data was deleted""" - self.active_user.refresh_from_db() - self.inactive_user.refresh_from_db() - self.deleted_user.refresh_from_db() - self.active_status.refresh_from_db() - self.inactive_status.refresh_from_db() - self.deleted_status.refresh_from_db() - - self.assertTrue(self.active_user.is_active) - self.assertFalse(self.active_user.is_deleted) - self.assertEqual(self.active_user.name, "a name") - self.assertNotEqual(self.deleted_user.email, "activeuser@activeuser.activeuser") - self.assertFalse(self.active_status.deleted) - self.assertEqual(self.active_status.content, "don't delete me") - - self.assertFalse(self.inactive_user.is_active) - self.assertFalse(self.inactive_user.is_deleted) - self.assertEqual(self.inactive_user.name, "name name") - self.assertNotEqual( - self.deleted_user.email, "inactiveuser@inactiveuser.inactiveuser" - ) - self.assertFalse(self.inactive_status.deleted) - self.assertEqual(self.inactive_status.content, "also don't delete me") - - self.assertFalse(self.deleted_user.is_active) - self.assertTrue(self.deleted_user.is_deleted) - self.assertIsNone(self.deleted_user.name) - self.assertNotEqual( - self.deleted_user.email, "deleteduser@deleteduser.deleteduser" - ) - self.assertTrue(self.deleted_status.deleted) - self.assertIsNone(self.deleted_status.content)