Skip to content

Commit

Permalink
tests: Use direct values instead of raw SQL
Browse files Browse the repository at this point in the history
Supercedes disqus#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)
  • Loading branch information
iamahuman committed Jan 16, 2021
1 parent fe55754 commit b5588c2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions bitfield/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b5588c2

Please sign in to comment.