Altered test introduced in f19a3669b8 for the sake of readability. refs #14786

This commit is contained in:
Simon Charette 2013-08-29 14:50:55 -04:00
parent 50d25a9c5a
commit 36bbe3b7c5
1 changed files with 9 additions and 4 deletions

View File

@ -672,12 +672,17 @@ class CustomFieldTests(unittest.TestCase):
Regression test for #14786 -- Test that field values are not prepared
twice in get_db_prep_lookup().
"""
prepare_count = [0]
class NoopField(models.TextField):
def __init__(self, *args, **kwargs):
self.prep_value_count = 0
super(NoopField, self).__init__(*args, **kwargs)
def get_prep_value(self, value):
prepare_count[0] += 1
self.prep_value_count += 1
return super(NoopField, self).get_prep_value(value)
field = NoopField()
field.get_db_prep_lookup('exact', 'TEST', connection=connection, prepared=False)
self.assertEqual(prepare_count[0], 1)
field.get_db_prep_lookup(
'exact', 'TEST', connection=connection, prepared=False
)
self.assertEqual(field.prep_value_count, 1)