Skip to content

Commit

Permalink
Merge pull request django-cms#72 from Aiky30/bugfix/test-suite-failures
Browse files Browse the repository at this point in the history
fix: Tests throw - empty content type in data migration issues
  • Loading branch information
vinitkumar authored Jan 2, 2022
2 parents 6402328 + f17df1a commit e5e83c6
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ def forwards(apps, schema_editor):
UrlGrouper = apps.get_model("djangocms_url_manager", "UrlGrouper")
User = apps.get_model('auth', 'User')

url_contenttype = ContentType.objects.get(app_label='djangocms_url_manager', model='url')
# The test suite fails to find the Content type, in this scenario we
# try and find the content type and create it if it doesn't yet exist using
# ContentType.objects.get_for_model
# This is the safest way because the following has been heavily manually tested already:
# ContentType.objects.get(app_label='djangocms_url_manager', model='url')
try:
url_contenttype = ContentType.objects.get(app_label='djangocms_url_manager', model='url')
except ContentType.DoesNotExist:
url_contenttype = ContentType.objects.get_for_model(Url)

url_queryset = Url.objects.all()

if djangocms_versioning_config_enabled and djangocms_versioning_installed:
# Only set the additional user etc if
# - versioning is enabled
# - there is url data, test suites fail when empty if not
if djangocms_versioning_config_enabled and djangocms_versioning_installed and len(url_queryset):
# Get a migration user.
migration_user = User.objects.get(id=DJANGOCMS_URL_MANAGER_VERSIONING_MIGRATION_USER_ID)
Version = apps.get_model('djangocms_versioning', 'Version')
Expand Down

0 comments on commit e5e83c6

Please sign in to comment.