test_migrationutils.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from django.test import TestCase
  2. from django.utils import translation
  3. from misago.core import migrationutils
  4. from misago.core.models import CacheVersion
  5. class LazyTranslationStringTests(TestCase):
  6. def setUp(self):
  7. translation.activate('de')
  8. def tearDown(self):
  9. translation.deactivate()
  10. def test_ugettext_lazy(self):
  11. """ugettext_lazy for migrations maintains untranslated message"""
  12. string = migrationutils.ugettext_lazy('content type')
  13. self.assertEqual(string.message, 'content type')
  14. self.assertEqual(unicode(string), 'Inhaltstyp')
  15. class OriginalMessageTests(TestCase):
  16. def test_original_message(self):
  17. """original_message returns untranslated message for misago messages"""
  18. string = migrationutils.ugettext_lazy('content type')
  19. self.assertEqual(migrationutils.original_message(string),
  20. string.message)
  21. self.assertEqual("Lorem ipsum", "Lorem ipsum")
  22. class CacheBusterUtilsTests(TestCase):
  23. def setUp(self):
  24. self.orm = {
  25. 'core.CacheVersion': CacheVersion,
  26. }
  27. def test_with_core_models(self):
  28. """with_core_models builds correct dict of models"""
  29. models = {
  30. u'conf.setting': {
  31. 'Meta': {'object_name': 'Setting'},
  32. 'default_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
  33. 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
  34. 'dry_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
  35. 'form_field': ('django.db.models.fields.CharField', [], {'max_length': '255', 'default': u"text"}),
  36. 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['conf.SettingsGroup']"}),
  37. u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  38. 'is_lazy': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  39. 'legend': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
  40. 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
  41. 'order': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}),
  42. 'pickled_field_extra': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
  43. 'python_type': ('django.db.models.fields.CharField', [], {'max_length': '255', 'default': u"string"}),
  44. 'setting': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
  45. },
  46. u'conf.settingsgroup': {
  47. 'Meta': {'object_name': 'SettingsGroup'},
  48. 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
  49. u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  50. 'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
  51. 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
  52. }
  53. }
  54. final_models = migrationutils.with_core_models('0001_initial')
  55. self.assertTrue('core.cacheversion' in final_models),
  56. final_models = migrationutils.with_core_models('0001_initial', models)
  57. self.assertTrue('core.cacheversion' in final_models),
  58. self.assertTrue('conf.settingsgroup' in final_models),
  59. self.assertTrue('conf.setting' in final_models),
  60. def test_cachebuster_register_cache(self):
  61. """
  62. cachebuster_register_cache registers cache on migration successfully
  63. """
  64. cache_name = 'eric_licenses'
  65. migrationutils.cachebuster_register_cache(self.orm, cache_name)
  66. CacheVersion.objects.get(cache=cache_name)
  67. def test_cachebuster_unregister_cache(self):
  68. """
  69. cachebuster_unregister_cache removes cache on migration successfully
  70. """
  71. cache_name = 'eric_licenses'
  72. migrationutils.cachebuster_register_cache(self.orm, cache_name)
  73. CacheVersion.objects.get(cache=cache_name)
  74. migrationutils.cachebuster_unregister_cache(self.orm, cache_name)
  75. with self.assertRaises(CacheVersion.DoesNotExist):
  76. CacheVersion.objects.get(cache=cache_name)
  77. with self.assertRaises(ValueError):
  78. migrationutils.cachebuster_unregister_cache(self.orm, cache_name)