diff options
| author | Ion Scerbatiuc <ion@rover.com> | 2015-08-01 07:46:25 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-12 18:00:26 -0400 |
| commit | 0cc059cd104cdb70340bd08e597d403d80dc42a6 (patch) | |
| tree | e9015bb84e07c0a4c407c465faf7e672ebe4c05e /tests/invalid_models_tests | |
| parent | d0bd5330432e1dda519ebd89606bd0980a36dcb4 (diff) | |
Fixed #25172 -- Fixed check framework to work with multiple databases.
Diffstat (limited to 'tests/invalid_models_tests')
| -rw-r--r-- | tests/invalid_models_tests/test_backend_specific.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/tests/invalid_models_tests/test_backend_specific.py b/tests/invalid_models_tests/test_backend_specific.py index 2d3ea7e6c7..5be1d6f691 100644 --- a/tests/invalid_models_tests/test_backend_specific.py +++ b/tests/invalid_models_tests/test_backend_specific.py @@ -1,37 +1,31 @@ # -*- encoding: utf-8 -*- from __future__ import unicode_literals -from types import MethodType - from django.core.checks import Error -from django.db import connection, models +from django.db import connections, models +from django.test import mock from .base import IsolatedModelsTestCase +def dummy_allow_migrate(db, app_label, **hints): + # Prevent checks from being run on the 'other' database, which doesn't have + # its check_field() method mocked in the test. + return db == 'default' + + class BackendSpecificChecksTests(IsolatedModelsTestCase): + @mock.patch('django.db.models.fields.router.allow_migrate', new=dummy_allow_migrate) def test_check_field(self): """ Test if backend specific checks are performed. """ - error = Error('an error', hint=None) - def mock(self, field, **kwargs): - return [error] - class Model(models.Model): field = models.IntegerField() field = Model._meta.get_field('field') - - # Mock connection.validation.check_field method. - v = connection.validation - old_check_field = v.check_field - v.check_field = MethodType(mock, v) - try: + with mock.patch.object(connections['default'].validation, 'check_field', return_value=[error]): errors = field.check() - finally: - # Unmock connection.validation.check_field method. - v.check_field = old_check_field self.assertEqual(errors, [error]) |
