From d69b03001c12c97e867ff6e5054676cfbf1a7446 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:45:01 -0700 Subject: [PATCH] Coverage --- .../management/commands/convert_mariadb_uuid.py | 6 +++--- src/documents/tests/test_management.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/documents/management/commands/convert_mariadb_uuid.py b/src/documents/management/commands/convert_mariadb_uuid.py index c3e158647..4000e67cb 100644 --- a/src/documents/management/commands/convert_mariadb_uuid.py +++ b/src/documents/management/commands/convert_mariadb_uuid.py @@ -5,16 +5,16 @@ from django.db import models from documents.models import Document -class Command(BaseCommand): # pragma: no cover +class Command(BaseCommand): # This code is taken almost entirely from https://github.com/wagtail/wagtail/pull/11912 with all credit to the original author. help = "Converts UUID columns from char type to the native UUID type used in MariaDB 10.7+ and Django 5.0+." def convert_field(self, model, field_name, null=False): - if model._meta.get_field(field_name).model != model: + if model._meta.get_field(field_name).model != model: # pragma: no cover # Field is inherited from a parent model return - if not model._meta.managed: + if not model._meta.managed: # pragma: no cover # The migration framework skips unmanaged models, so we should too return diff --git a/src/documents/tests/test_management.py b/src/documents/tests/test_management.py index d1efe27d4..76a0a2c74 100644 --- a/src/documents/tests/test_management.py +++ b/src/documents/tests/test_management.py @@ -3,6 +3,7 @@ import hashlib import os import shutil import tempfile +from io import StringIO from pathlib import Path from unittest import mock @@ -238,3 +239,16 @@ class TestSanityChecker(DirectoriesMixin, TestCase): self.assertEqual(len(capture.output), 2) self.assertIn("Checksum mismatch. Stored: abc, actual:", capture.output[1]) + + +class TestConvertMariaDBUUID(TestCase): + @mock.patch("django.db.connection.schema_editor") + def test_convert(self, m): + m.alter_field.return_value = None + + stdout = StringIO() + call_command("convert_mariadb_uuid", stdout=stdout) + + m.assert_called_once() + + self.assertIn("Successfully converted", stdout.getvalue())