Browse Source

fix(tests): Fix tests that create their own models so that they work when MIGRATIONS_TEST_MIGRATE=1 (#27567)

This was broken at some point in the last 9 months. This should unbreak the tests in #27556

Also added sentry.demo to INSTALLED_APPS when running tests. Since we run the demo tests we need this in place so that models are generated properly there
Dan Fuller 3 years ago
parent
commit
2a583e82f7

+ 3 - 0
src/sentry/utils/pytest/sentry.py

@@ -59,6 +59,8 @@ def pytest_configure(config):
 
     # override a few things with our test specifics
     settings.INSTALLED_APPS = tuple(settings.INSTALLED_APPS) + ("tests",)
+    if "sentry" in settings.INSTALLED_APPS:
+        settings.INSTALLED_APPS = settings.INSTALLED_APPS + ("sentry.demo",)
     # Need a predictable key for tests that involve checking signatures
     settings.SENTRY_PUBLIC = False
 
@@ -171,6 +173,7 @@ def pytest_configure(config):
         # Migrations for the "sentry" app take a long time to run, which makes test startup time slow in dev.
         # This is a hack to force django to sync the database state from the models rather than use migrations.
         settings.MIGRATION_MODULES["sentry"] = None
+        settings.MIGRATION_MODULES["demo"] = None
 
     asset_version_patcher = mock.patch(
         "sentry.runner.initializer.get_asset_version", return_value="{version}"

+ 0 - 0
tests/models.py


+ 1 - 1
tests/sentry/db/models/fields/bitfield/test_bitfield.py

@@ -12,7 +12,7 @@ from bitfield.compat import bitand, bitor
 
 class BitFieldTestModel(models.Model):
     class Meta:
-        app_label = "sentry"
+        app_label = "tests"
 
     flags = BitField(
         flags=("FLAG_0", "FLAG_1", "FLAG_2", "FLAG_3"), default=3, db_column="another_name"

+ 4 - 4
tests/sentry/db/models/fields/test_jsonfield.py

@@ -10,14 +10,14 @@ class JSONFieldTestModel(models.Model):
     json = JSONField("test", null=True, blank=True)
 
     class Meta:
-        app_label = "sentry"
+        app_label = "tests"
 
 
 class JSONFieldWithDefaultTestModel(models.Model):
     json = JSONField(default={"sukasuka": "YAAAAAZ"})
 
     class Meta:
-        app_label = "sentry"
+        app_label = "tests"
 
 
 class BlankJSONFieldTestModel(models.Model):
@@ -25,7 +25,7 @@ class BlankJSONFieldTestModel(models.Model):
     blank_json = JSONField(blank=True)
 
     class Meta:
-        app_label = "sentry"
+        app_label = "tests"
 
 
 def default():
@@ -36,7 +36,7 @@ class CallableDefaultModel(models.Model):
     json = JSONField(default=default)
 
     class Meta:
-        app_label = "sentry"
+        app_label = "tests"
 
 
 class JSONFieldTest(TestCase):