test_deprecated.py 721 B

12345678910111213141516171819202122
  1. import warnings
  2. from django.test import TestCase
  3. from .models import Cash, CashModelDeprecated
  4. class FromDBValueDeprecationTests(TestCase):
  5. def test_deprecation(self):
  6. CashModelDeprecated.objects.create(cash='12.50')
  7. with warnings.catch_warnings(record=True) as warns:
  8. warnings.simplefilter('always')
  9. instance = CashModelDeprecated.objects.get()
  10. self.assertIsInstance(instance.cash, Cash)
  11. self.assertEqual(len(warns), 1)
  12. msg = str(warns[0].message)
  13. self.assertEqual(
  14. msg,
  15. 'Remove the context parameter from CashFieldDeprecated.from_db_value(). '
  16. 'Support for it will be removed in Django 3.0.'
  17. )