Simplified a contenttypes check test with mock.

This commit is contained in:
Adam Chainz 2017-01-07 10:14:24 -05:00 committed by Tim Graham
parent cd86f03591
commit 334096dfac
1 changed files with 4 additions and 7 deletions

View File

@ -243,15 +243,12 @@ class GenericForeignKeyTests(SimpleTestCase):
@override_settings(INSTALLED_APPS=['django.contrib.auth', 'django.contrib.contenttypes', 'contenttypes_tests'])
def test_generic_foreign_key_checks_are_performed(self):
class MyGenericForeignKey(GenericForeignKey):
def check(self, **kwargs):
return ['performed!']
class Model(models.Model):
content_object = MyGenericForeignKey()
content_object = GenericForeignKey()
errors = checks.run_checks(app_configs=self.apps.get_app_configs())
self.assertEqual(errors, ['performed!'])
with mock.patch.object(GenericForeignKey, 'check') as check:
checks.run_checks(app_configs=self.apps.get_app_configs())
check.assert_called_once_with()
@isolate_apps('contenttypes_tests')