From b5588c219b0706a66340d014668aad7b0d5566f3 Mon Sep 17 00:00:00 2001 From: iamahuman Date: Sat, 16 Jan 2021 17:16:56 +0900 Subject: [PATCH] tests: Use direct values instead of raw SQL Supercedes #11. Fixes: eea01c6 (use the db_column attribute of a model field if set https://docs.djangoproject.com/en/dev/ref/models/fields/#db-column, 2012-01-05) --- bitfield/tests/tests.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bitfield/tests/tests.py b/bitfield/tests/tests.py index cbedc33e..c2cacc18 100644 --- a/bitfield/tests/tests.py +++ b/bitfield/tests/tests.py @@ -155,11 +155,12 @@ def test_regression_1425(self): self.assertTrue(instance.flags.FLAG_2) self.assertTrue(instance.flags.FLAG_3) - cursor = connection.cursor() - flags_field = BitFieldTestModel._meta.get_field('flags') - flags_db_column = flags_field.db_column or flags_field.name - cursor.execute("INSERT INTO %s (%s) VALUES (-1)" % (BitFieldTestModel._meta.db_table, flags_db_column)) - # There should only be the one row we inserted through the cursor. + # Bypass BitField.to_python and insert (-1) directly. + instance = BitFieldTestModel() + instance.__dict__['flags'] = models.Value(-1, output_field=models.IntegerField()) + instance.save() + + # There should only be the one row we inserted with a direct value. instance = BitFieldTestModel.objects.get(flags=-1) self.assertTrue(instance.flags.FLAG_0) self.assertTrue(instance.flags.FLAG_1)