summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-04-24 18:03:14 +0000
committerAnssi Kääriäinen <akaariai@gmail.com>2012-04-24 18:03:14 +0000
commitc4e62eff9074bedb5f2242b46625c35721502989 (patch)
tree83c2255db9b33f825d208e0d38e43fa65481b0d4 /tests/regressiontests
parent612247b3a0acbdec17b9c52410b2349533ff2d95 (diff)
Fixed #17653 -- Changed MySQL backend to raise a ValueError if zero is used as an AutoField value.
Thanks to Sylvain Lebon for the report, krzysiumed for the patch and charettes and claudep for reviews. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17933 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/backends/tests.py15
-rw-r--r--tests/regressiontests/bulk_create/tests.py16
2 files changed, 28 insertions, 3 deletions
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 9b28787c15..3e675cc1ea 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -13,7 +13,8 @@ from django.db import (backend, connection, connections, DEFAULT_DB_ALIAS,
from django.db.backends.signals import connection_created
from django.db.backends.postgresql_psycopg2 import version as pg_version
from django.db.utils import ConnectionHandler, DatabaseError, load_backend
-from django.test import TestCase, skipUnlessDBFeature, TransactionTestCase
+from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
+ TransactionTestCase)
from django.test.utils import override_settings
from django.utils import unittest
@@ -642,3 +643,15 @@ class BackendLoadingTests(TestCase):
self.assertRaisesRegexp(ImproperlyConfigured,
"Try using django.db.backends.sqlite3 instead",
load_backend, 'sqlite3')
+
+
+class MySQLPKZeroTests(TestCase):
+ """
+ Zero as id for AutoField should raise exception in MySQL, because MySQL
+ does not allow zero for automatic primary key.
+ """
+
+ @skipIfDBFeature('allows_primary_key_0')
+ def test_zero_as_autoval(self):
+ with self.assertRaises(ValueError):
+ models.Square.objects.create(id=0, root=0, square=1)
diff --git a/tests/regressiontests/bulk_create/tests.py b/tests/regressiontests/bulk_create/tests.py
index 284ea9fdd9..0b55f637a4 100644
--- a/tests/regressiontests/bulk_create/tests.py
+++ b/tests/regressiontests/bulk_create/tests.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import
from operator import attrgetter
-from django.test import TestCase, skipUnlessDBFeature
+from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from .models import Country, Restaurant, Pizzeria, State
@@ -56,4 +56,16 @@ class BulkCreateTests(TestCase):
])
self.assertQuerysetEqual(State.objects.order_by("two_letter_code"), [
"CA", "IL", "ME", "NY",
- ], attrgetter("two_letter_code")) \ No newline at end of file
+ ], attrgetter("two_letter_code"))
+
+ @skipIfDBFeature('allows_primary_key_0')
+ def test_zero_as_autoval(self):
+ """
+ Zero as id for AutoField should raise exception in MySQL, because MySQL
+ does not allow zero for automatic primary key.
+ """
+
+ valid_country = Country(name='Germany', iso_two_letter='DE')
+ invalid_country = Country(id=0, name='Poland', iso_two_letter='PL')
+ with self.assertRaises(ValueError):
+ Country.objects.bulk_create([valid_country, invalid_country])