From 334096dfac60fbc494e17b9a9ba22d098334c73b Mon Sep 17 00:00:00 2001 From: Adam Chainz Date: Sat, 7 Jan 2017 10:14:24 -0500 Subject: [PATCH] Simplified a contenttypes check test with mock. --- tests/contenttypes_tests/tests.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py index 5845c02af6..db97557f24 100644 --- a/tests/contenttypes_tests/tests.py +++ b/tests/contenttypes_tests/tests.py @@ -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')