Skip to content

Commit

Permalink
[1.7.x] Fixed #24595 Oracle test failure
Browse files Browse the repository at this point in the history
The only problem for Oracle was the test, which tested nullity on
text/char fields -- but Oracle interprets_empty_strings_as_null.

Backport of d5a0acc from master
  • Loading branch information
shaib committed Apr 18, 2015
1 parent 8414294 commit 773ec51
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/schema/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datetime
import unittest

from django.test import TransactionTestCase
from django.test import TransactionTestCase, skipIfDBFeature
from django.db import connection, DatabaseError, IntegrityError, OperationalError
from django.db.models.fields import (BinaryField, BooleanField, CharField, IntegerField,
PositiveIntegerField, SlugField, TextField)
from django.db.models.fields import (BigIntegerField, BinaryField, BooleanField, CharField,
IntegerField, PositiveIntegerField, SlugField, TextField)
from django.db.models.fields.related import ForeignKey, ManyToManyField, OneToOneField
from django.db.transaction import atomic
from .fields import CustomManyToManyField, InheritedManyToManyField
Expand Down Expand Up @@ -439,7 +439,8 @@ def test_alter_text_field(self):
strict=True,
)

def test_alter_field_keep_null_status(self):
@skipIfDBFeature('interprets_empty_strings_as_nulls')
def test_alter_textual_field_keep_null_status(self):
"""
Changing a field type shouldn't affect the not null status.
"""
Expand All @@ -455,6 +456,22 @@ def test_alter_field_keep_null_status(self):
with self.assertRaises(IntegrityError):
Note.objects.create(info=None)

def test_alter_numeric_field_keep_null_status(self):
"""
Changing a field type shouldn't affect the not null status.
"""
with connection.schema_editor() as editor:
editor.create_model(UniqueTest)
with self.assertRaises(IntegrityError):
UniqueTest.objects.create(year=None, slug='aaa')
old_field = UniqueTest._meta.get_field("year")
new_field = BigIntegerField()
new_field.set_attributes_from_name("year")
with connection.schema_editor() as editor:
editor.alter_field(UniqueTest, old_field, new_field, strict=True)
with self.assertRaises(IntegrityError):
UniqueTest.objects.create(year=None, slug='bbb')

def test_alter_null_to_not_null(self):
"""
#23609 - Tests handling of default values when altering from NULL to NOT NULL.
Expand Down

0 comments on commit 773ec51

Please sign in to comment.