Repository: svthalia/concrexit

Issue:
Running tests is very slow due to newsletter migration
<!--

Please add the appropriate label for what change should be made:
docs: changes to the documentation)
refactor: refactoring production code, eg. renaming a variable or rewriting a function
test: adding missing tests, refactoring tests; no production code change
chore: updating poetry etc; no production code change

-->

### Describe the change
Running tests takes very long due to the migration `newsletters.0015_embed_images_html`. I'm not sure how this migration works and why it is so slow, but we should probably work around the slowness of this in some way, e.g. enabling a developer to re-use the same database when testing.

### Motivation
When debugging some tests, needing to wait multiple minutes to run each test is very demotivating and makes it impossible to iterate quickly to see if my changes are correct.

### Suggested implementation
Either speed up this migration, find a way to 'skip' it, or use enable using a pre-populated database for testing.



Discussion:
Quick fix should be removing any newsletter HTML files from your media folder. It was part of #2290
And since it did do it's job where possible we can just make it an empty migration from now on.

Resolving patch:
diff --git a/website/newsletters/migrations/0001_squashed_0015_embed_images_html.py b/website/newsletters/migrations/0001_squashed_0015_embed_images_html.py
new file mode 100644
--- /dev/null
+++ b/website/newsletters/migrations/0001_squashed_0015_embed_images_html.py
@@ -0,0 +1,67 @@
+# Generated by Django 4.0.7 on 2022-10-05 19:30
+
+from django.db import migrations, models
+import django.db.models.deletion
+import payments.models
+import tinymce.models
+
+
+class Migration(migrations.Migration):
+
+    replaces = [('newsletters', '0001_initial'), ('newsletters', '0002_auto_20161109_2257'), ('newsletters', '0003_auto_20161109_2257'), ('newsletters', '0004_newsletterevent_show_costs_warning'), ('newsletters', '0004_auto_20161211_2145'), ('newsletters', '0005_merge_20161214_2018'), ('newsletters', '0006_make_newslettercontent_non_abstract'), ('newsletters', '0007_newsletter_send_date'), ('newsletters', '0008_auto_20190413_1603'), ('newsletters', '0009_auto_20191103_1821'), ('newsletters', '0010_newslettercontent_url'), ('newsletters', '0011_auto_20200907_1835'), ('newsletters', '0012_remove_multilang_field'), ('newsletters', '0013_auto_20211216_2250'), ('newsletters', '0014_auto_20211216_2257'), ('newsletters', '0015_embed_images_html')]
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Newsletter',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('title', models.CharField(help_text='The title is used for the email subject.', max_length=150, verbose_name='Title')),
+                ('date', models.DateField(blank=True, help_text='This date is used to extract the week of this newsletter, best scenario:always use the monday of the week the newsletter is for. If you leave it empty no week is shown.', null=True, verbose_name='Date')),
+                ('send_date', models.DateTimeField(blank=True, null=True, verbose_name='Send date')),
+                ('description', tinymce.models.HTMLField(help_text='This is the text that starts the newsletter. It always begins with "Dear members" and you can append whatever you want.', verbose_name='Introduction')),
+                ('sent', models.BooleanField(default=False)),
+            ],
+            options={
+                'permissions': (('send_newsletter', 'Can send newsletter'),),
+            },
+        ),
+        migrations.CreateModel(
+            name='NewsletterContent',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('title', models.CharField(max_length=150, verbose_name='Title')),
+                ('url', models.URLField(blank=True, help_text='If filled, it will make the title a link to this URL', null=True, verbose_name='URL')),
+                ('description', tinymce.models.HTMLField(verbose_name='Description')),
+                ('order', models.PositiveIntegerField(default=0, null=True, verbose_name='order')),
+                ('newsletter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='newsletters.newsletter')),
+            ],
+            options={
+                'ordering': ('order',),
+            },
+        ),
+        migrations.CreateModel(
+            name='NewsletterEvent',
+            fields=[
+                ('newslettercontent_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='newsletters.newslettercontent')),
+                ('where', models.CharField(max_length=150, verbose_name='Where')),
+                ('start_datetime', models.DateTimeField(verbose_name='Start date and time')),
+                ('end_datetime', models.DateTimeField(verbose_name='End date and time')),
+                ('show_costs_warning', models.BooleanField(default=True, verbose_name='Show warnings about costs')),
+                ('price', payments.models.PaymentAmountField(blank=True, decimal_places=2, default=None, max_digits=8, null=True, validators=[payments.models.validate_not_zero], verbose_name='Price (in Euro)')),
+                ('penalty_costs', payments.models.PaymentAmountField(blank=True, decimal_places=2, default=None, help_text='This is the price that a member has to pay when he/she did not show up.', max_digits=8, null=True, validators=[payments.models.validate_not_zero], verbose_name='Costs (in Euro)')),
+            ],
+            bases=('newsletters.newslettercontent',),
+        ),
+        migrations.CreateModel(
+            name='NewsletterItem',
+            fields=[
+                ('newslettercontent_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='newsletters.newslettercontent')),
+            ],
+            bases=('newsletters.newslettercontent',),
+        ),
+    ]
diff --git a/website/newsletters/migrations/0015_embed_images_html.py b/website/newsletters/migrations/0015_embed_images_html.py
--- a/website/newsletters/migrations/0015_embed_images_html.py
+++ b/website/newsletters/migrations/0015_embed_images_html.py
@@ -28,5 +28,5 @@ class Migration(migrations.Migration):
     ]
 
     operations = [
-        migrations.RunPython(embed_images_html, lambda *args: None)
+        migrations.RunPython(embed_images_html, migrations.RunPython.noop),
     ]


Test patch: