2014-01-20 03:45:21 +01:00
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.core.checks import Error
|
2015-08-01 16:46:25 +02:00
|
|
|
from django.db import connections, models
|
|
|
|
from django.test import mock
|
2014-01-20 03:45:21 +01:00
|
|
|
|
|
|
|
from .base import IsolatedModelsTestCase
|
|
|
|
|
|
|
|
|
2015-08-01 16:46:25 +02:00
|
|
|
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'
|
|
|
|
|
|
|
|
|
2014-01-20 03:45:21 +01:00
|
|
|
class BackendSpecificChecksTests(IsolatedModelsTestCase):
|
|
|
|
|
2015-08-01 16:46:25 +02:00
|
|
|
@mock.patch('django.db.models.fields.router.allow_migrate', new=dummy_allow_migrate)
|
2014-01-20 03:45:21 +01:00
|
|
|
def test_check_field(self):
|
|
|
|
""" Test if backend specific checks are performed. """
|
|
|
|
error = Error('an error', hint=None)
|
|
|
|
|
|
|
|
class Model(models.Model):
|
|
|
|
field = models.IntegerField()
|
|
|
|
|
|
|
|
field = Model._meta.get_field('field')
|
2015-08-01 16:46:25 +02:00
|
|
|
with mock.patch.object(connections['default'].validation, 'check_field', return_value=[error]):
|
2014-01-20 03:45:21 +01:00
|
|
|
errors = field.check()
|
|
|
|
|
|
|
|
self.assertEqual(errors, [error])
|