Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Use direct values instead of raw SQL #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions bitfield/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pickle

from django.db import connection, models
from django.db import models
from django.db.models import F
from django.test import TestCase

Expand Down 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