test_migration_names.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from django.test import TestCase
  2. from wagtail.blocks.migrations.operations import (
  3. RemoveStreamChildrenOperation,
  4. RenameStreamChildrenOperation,
  5. )
  6. from wagtail.test.streamfield_migrations import models
  7. from wagtail.test.streamfield_migrations.testutils import MigrationTestMixin
  8. class MigrationNameTest(TestCase, MigrationTestMixin):
  9. model = models.SamplePage
  10. app_name = "wagtail_streamfield_migration_toolkit_test"
  11. def test_rename(self):
  12. operations_and_block_path = [
  13. (
  14. RenameStreamChildrenOperation(old_name="char1", new_name="renamed1"),
  15. "",
  16. )
  17. ]
  18. migration = self.init_migration(
  19. operations_and_block_path=operations_and_block_path
  20. )
  21. suggested_name = migration.suggest_name()
  22. self.assertEqual(suggested_name, "rename_char1_to_renamed1")
  23. def test_remove(self):
  24. operations_and_block_path = [
  25. (
  26. RemoveStreamChildrenOperation(name="char1"),
  27. "",
  28. )
  29. ]
  30. migration = self.init_migration(
  31. operations_and_block_path=operations_and_block_path
  32. )
  33. suggested_name = migration.suggest_name()
  34. self.assertEqual(suggested_name, "remove_char1")
  35. def test_multiple(self):
  36. operations_and_block_path = [
  37. (
  38. RenameStreamChildrenOperation(old_name="char1", new_name="renamed1"),
  39. "",
  40. ),
  41. (
  42. RemoveStreamChildrenOperation(name="char1"),
  43. "simplestruct",
  44. ),
  45. ]
  46. migration = self.init_migration(
  47. operations_and_block_path=operations_and_block_path
  48. )
  49. suggested_name = migration.suggest_name()
  50. self.assertEqual(suggested_name, "rename_char1_to_renamed1_remove_char1")