/desktop/core/ext-py/south/south/tests/autodetection.py

https://github.com/jcrobak/hue · Python · 233 lines · 193 code · 37 blank · 3 comment · 0 complexity · cc658e6f51f6672deb4f39192f828527 MD5 · raw file

  1. import unittest
  2. from south.creator.changes import AutoChanges
  3. class TestComparison(unittest.TestCase):
  4. """
  5. Tests the comparison methods of startmigration.
  6. """
  7. def test_no_change(self):
  8. "Test with a completely unchanged definition."
  9. self.assertEqual(
  10. AutoChanges.different_attributes(
  11. ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['southdemo.Lizard']"}),
  12. ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['southdemo.Lizard']"}),
  13. ),
  14. False,
  15. )
  16. self.assertEqual(
  17. AutoChanges.different_attributes(
  18. ('django.db.models.fields.related.ForeignKey', ['ohhai', 'there'], {'to': "somewhere", "from": "there"}),
  19. ('django.db.models.fields.related.ForeignKey', ['ohhai', 'there'], {"from": "there", 'to': "somewhere"}),
  20. ),
  21. False,
  22. )
  23. def test_pos_change(self):
  24. "Test with a changed positional argument."
  25. self.assertEqual(
  26. AutoChanges.different_attributes(
  27. ('django.db.models.fields.CharField', ['hi'], {'to': "foo"}),
  28. ('django.db.models.fields.CharField', [], {'to': "foo"}),
  29. ),
  30. True,
  31. )
  32. self.assertEqual(
  33. AutoChanges.different_attributes(
  34. ('django.db.models.fields.CharField', [], {'to': "foo"}),
  35. ('django.db.models.fields.CharField', ['bye'], {'to': "foo"}),
  36. ),
  37. True,
  38. )
  39. self.assertEqual(
  40. AutoChanges.different_attributes(
  41. ('django.db.models.fields.CharField', ['pi'], {'to': "foo"}),
  42. ('django.db.models.fields.CharField', ['pi'], {'to': "foo"}),
  43. ),
  44. False,
  45. )
  46. self.assertEqual(
  47. AutoChanges.different_attributes(
  48. ('django.db.models.fields.CharField', ['pisdadad'], {'to': "foo"}),
  49. ('django.db.models.fields.CharField', ['pi'], {'to': "foo"}),
  50. ),
  51. True,
  52. )
  53. self.assertEqual(
  54. AutoChanges.different_attributes(
  55. ('django.db.models.fields.CharField', ['hi'], {}),
  56. ('django.db.models.fields.CharField', [], {}),
  57. ),
  58. True,
  59. )
  60. self.assertEqual(
  61. AutoChanges.different_attributes(
  62. ('django.db.models.fields.CharField', [], {}),
  63. ('django.db.models.fields.CharField', ['bye'], {}),
  64. ),
  65. True,
  66. )
  67. self.assertEqual(
  68. AutoChanges.different_attributes(
  69. ('django.db.models.fields.CharField', ['pi'], {}),
  70. ('django.db.models.fields.CharField', ['pi'], {}),
  71. ),
  72. False,
  73. )
  74. self.assertEqual(
  75. AutoChanges.different_attributes(
  76. ('django.db.models.fields.CharField', ['pi'], {}),
  77. ('django.db.models.fields.CharField', ['45fdfdf'], {}),
  78. ),
  79. True,
  80. )
  81. def test_kwd_change(self):
  82. "Test a changed keyword argument"
  83. self.assertEqual(
  84. AutoChanges.different_attributes(
  85. ('django.db.models.fields.CharField', ['pi'], {'to': "foo"}),
  86. ('django.db.models.fields.CharField', ['pi'], {'to': "blue"}),
  87. ),
  88. True,
  89. )
  90. self.assertEqual(
  91. AutoChanges.different_attributes(
  92. ('django.db.models.fields.CharField', [], {'to': "foo"}),
  93. ('django.db.models.fields.CharField', [], {'to': "blue"}),
  94. ),
  95. True,
  96. )
  97. self.assertEqual(
  98. AutoChanges.different_attributes(
  99. ('django.db.models.fields.CharField', ['b'], {'to': "foo"}),
  100. ('django.db.models.fields.CharField', ['b'], {'to': "blue"}),
  101. ),
  102. True,
  103. )
  104. self.assertEqual(
  105. AutoChanges.different_attributes(
  106. ('django.db.models.fields.CharField', [], {'to': "foo"}),
  107. ('django.db.models.fields.CharField', [], {}),
  108. ),
  109. True,
  110. )
  111. self.assertEqual(
  112. AutoChanges.different_attributes(
  113. ('django.db.models.fields.CharField', ['a'], {'to': "foo"}),
  114. ('django.db.models.fields.CharField', ['a'], {}),
  115. ),
  116. True,
  117. )
  118. self.assertEqual(
  119. AutoChanges.different_attributes(
  120. ('django.db.models.fields.CharField', [], {}),
  121. ('django.db.models.fields.CharField', [], {'to': "foo"}),
  122. ),
  123. True,
  124. )
  125. self.assertEqual(
  126. AutoChanges.different_attributes(
  127. ('django.db.models.fields.CharField', ['a'], {}),
  128. ('django.db.models.fields.CharField', ['a'], {'to': "foo"}),
  129. ),
  130. True,
  131. )
  132. def test_backcompat_nochange(self):
  133. "Test that the backwards-compatable comparison is working"
  134. self.assertEqual(
  135. AutoChanges.different_attributes(
  136. ('models.CharField', [], {}),
  137. ('django.db.models.fields.CharField', [], {}),
  138. ),
  139. False,
  140. )
  141. self.assertEqual(
  142. AutoChanges.different_attributes(
  143. ('models.CharField', ['ack'], {}),
  144. ('django.db.models.fields.CharField', ['ack'], {}),
  145. ),
  146. False,
  147. )
  148. self.assertEqual(
  149. AutoChanges.different_attributes(
  150. ('models.CharField', [], {'to':'b'}),
  151. ('django.db.models.fields.CharField', [], {'to':'b'}),
  152. ),
  153. False,
  154. )
  155. self.assertEqual(
  156. AutoChanges.different_attributes(
  157. ('models.CharField', ['hah'], {'to':'you'}),
  158. ('django.db.models.fields.CharField', ['hah'], {'to':'you'}),
  159. ),
  160. False,
  161. )
  162. self.assertEqual(
  163. AutoChanges.different_attributes(
  164. ('models.CharField', ['hah'], {'to':'you'}),
  165. ('django.db.models.fields.CharField', ['hah'], {'to':'heh'}),
  166. ),
  167. True,
  168. )
  169. self.assertEqual(
  170. AutoChanges.different_attributes(
  171. ('models.CharField', ['hah'], {}),
  172. ('django.db.models.fields.CharField', [], {'to':"orm['appname.hah']"}),
  173. ),
  174. False,
  175. )
  176. self.assertEqual(
  177. AutoChanges.different_attributes(
  178. ('models.CharField', ['hah'], {}),
  179. ('django.db.models.fields.CharField', [], {'to':'hah'}),
  180. ),
  181. True,
  182. )
  183. self.assertEqual(
  184. AutoChanges.different_attributes(
  185. ('models.CharField', ['hah'], {}),
  186. ('django.db.models.fields.CharField', [], {'to':'rrr'}),
  187. ),
  188. True,
  189. )
  190. self.assertEqual(
  191. AutoChanges.different_attributes(
  192. ('models.CharField', ['hah'], {}),
  193. ('django.db.models.fields.IntField', [], {'to':'hah'}),
  194. ),
  195. True,
  196. )