/scrumdo-web/apps/django_evolution/tests/delete_model.py

https://github.com/abstract-open-solutions/ScrumDo
Python | 131 lines | 130 code | 1 blank | 0 comment | 0 complexity | e4db07f37f81b150a56df0736aa5f120 MD5 | raw file
  1. from django_evolution.tests.utils import test_sql_mapping
  2. tests = r"""
  3. >>> from django.db import models
  4. >>> from django_evolution.mutations import DeleteModel
  5. >>> from django_evolution.tests.utils import test_proj_sig, execute_test_sql, register_models, deregister_models
  6. >>> from django_evolution.diff import Diff
  7. >>> import copy
  8. # Now, a useful test model we can use for evaluating diffs
  9. >>> class DeleteModelAnchor(models.Model):
  10. ... value = models.IntegerField()
  11. >>> class BasicModel(models.Model):
  12. ... value = models.IntegerField()
  13. >>> class BasicWithM2MModel(models.Model):
  14. ... value = models.IntegerField()
  15. ... m2m = models.ManyToManyField(DeleteModelAnchor)
  16. >>> class CustomTableModel(models.Model):
  17. ... value = models.IntegerField()
  18. ... class Meta:
  19. ... db_table = 'custom_table_name'
  20. >>> class CustomTableWithM2MModel(models.Model):
  21. ... value = models.IntegerField()
  22. ... m2m = models.ManyToManyField(DeleteModelAnchor)
  23. ... class Meta:
  24. ... db_table = 'another_custom_table_name'
  25. # Store the base signature
  26. >>> base_models = (
  27. ... ('DeleteModelAnchor', DeleteModelAnchor),
  28. ... ('BasicModel', BasicModel),
  29. ... ('BasicWithM2MModel', BasicWithM2MModel),
  30. ... ('CustomTableModel', CustomTableModel),
  31. ... ('CustomTableWithM2MModel', CustomTableWithM2MModel),
  32. ... )
  33. >>> start = register_models(*base_models)
  34. >>> start_sig = test_proj_sig(*base_models)
  35. # Delete a Model
  36. >>> end_sig = copy.deepcopy(start_sig)
  37. >>> _ = end_sig['tests'].pop('BasicModel')
  38. >>> end = copy.deepcopy(start)
  39. >>> _ = end.pop('basicmodel')
  40. >>> d = Diff(start_sig, end_sig)
  41. >>> print [str(e) for e in d.evolution()['tests']]
  42. ["DeleteModel('BasicModel')"]
  43. >>> test_sig = copy.deepcopy(start_sig)
  44. >>> test_sql = []
  45. >>> for mutation in d.evolution()['tests']:
  46. ... test_sql.extend(mutation.mutate('tests', test_sig))
  47. ... mutation.simulate('tests', test_sig)
  48. >>> Diff(test_sig, end_sig).is_empty()
  49. True
  50. >>> execute_test_sql(start, end, test_sql) #BasicModel
  51. %(BasicModel)s
  52. # Delete a model with an m2m field
  53. >>> end_sig = copy.deepcopy(start_sig)
  54. >>> _ = end_sig['tests'].pop('BasicWithM2MModel')
  55. >>> end = copy.deepcopy(start)
  56. >>> _ = end.pop('basicwithm2mmodel')
  57. >>> d = Diff(start_sig, end_sig)
  58. >>> print [str(e) for e in d.evolution()['tests']]
  59. ["DeleteModel('BasicWithM2MModel')"]
  60. >>> test_sig = copy.deepcopy(start_sig)
  61. >>> test_sql = []
  62. >>> for mutation in d.evolution()['tests']:
  63. ... test_sql.extend(mutation.mutate('tests', test_sig))
  64. ... mutation.simulate('tests', test_sig)
  65. >>> Diff(test_sig, end_sig).is_empty()
  66. True
  67. >>> execute_test_sql(start, end, test_sql) # BasicWithM2MModels
  68. %(BasicWithM2MModel)s
  69. # Delete a model with a custom table name
  70. >>> end_sig = copy.deepcopy(start_sig)
  71. >>> _ = end_sig['tests'].pop('CustomTableModel')
  72. >>> end = copy.deepcopy(start)
  73. >>> _ = end.pop('customtablemodel')
  74. >>> d = Diff(start_sig, end_sig)
  75. >>> print [str(e) for e in d.evolution()['tests']]
  76. ["DeleteModel('CustomTableModel')"]
  77. >>> test_sig = copy.deepcopy(start_sig)
  78. >>> test_sql = []
  79. >>> for mutation in d.evolution()['tests']:
  80. ... test_sql.extend(mutation.mutate('tests', test_sig))
  81. ... mutation.simulate('tests', test_sig)
  82. >>> Diff(test_sig, end_sig).is_empty()
  83. True
  84. >>> execute_test_sql(start, end, test_sql) #CustomTableModel
  85. %(CustomTableModel)s
  86. # Delete a model with a custom table name and an m2m field
  87. >>> end_sig = copy.deepcopy(start_sig)
  88. >>> _ = end_sig['tests'].pop('CustomTableWithM2MModel')
  89. >>> d = Diff(start_sig, end_sig)
  90. >>> print [str(e) for e in d.evolution()['tests']]
  91. ["DeleteModel('CustomTableWithM2MModel')"]
  92. >>> test_sig = copy.deepcopy(start_sig)
  93. >>> test_sql = []
  94. >>> for mutation in d.evolution()['tests']:
  95. ... test_sql.extend(mutation.mutate('tests', test_sig))
  96. ... mutation.simulate('tests', test_sig)
  97. >>> Diff(test_sig, end_sig).is_empty()
  98. True
  99. >>> execute_test_sql(start, end, test_sql) #CustomTableWithM2MModel
  100. %(CustomTableWithM2MModel)s
  101. # Clean up after the applications that were installed
  102. >>> deregister_models()
  103. """ % test_sql_mapping('delete_model')