summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-01-24 14:58:05 +0000
committerRamiro Morales <cramm0@gmail.com>2011-01-24 14:58:05 +0000
commitbafe879188f3cd268f81e426bcdf4addc2d9a10a (patch)
tree626fac6fb3970793eec1824bb19c84b2dcff5ff8 /tests
parent3f528e10d50ff7ba19a8a9e6cb2f9417a1e7f270 (diff)
Fixed 14796 -- Modified order of operations performed on field names by the inspectdb command so it doesn't generates model fields with names equal to Python keywords. Thanks pappjm at gmail dot com for the report and mmcnickle for the fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15296 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/inspectdb/__init__.py1
-rw-r--r--tests/regressiontests/inspectdb/bug/__init__.py1
-rw-r--r--tests/regressiontests/inspectdb/bug/models.py7
-rw-r--r--tests/regressiontests/inspectdb/models.py1
-rw-r--r--tests/regressiontests/inspectdb/tests.py29
5 files changed, 39 insertions, 0 deletions
diff --git a/tests/regressiontests/inspectdb/__init__.py b/tests/regressiontests/inspectdb/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/tests/regressiontests/inspectdb/__init__.py
@@ -0,0 +1 @@
+
diff --git a/tests/regressiontests/inspectdb/bug/__init__.py b/tests/regressiontests/inspectdb/bug/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/tests/regressiontests/inspectdb/bug/__init__.py
@@ -0,0 +1 @@
+
diff --git a/tests/regressiontests/inspectdb/bug/models.py b/tests/regressiontests/inspectdb/bug/models.py
new file mode 100644
index 0000000000..6fec2273e0
--- /dev/null
+++ b/tests/regressiontests/inspectdb/bug/models.py
@@ -0,0 +1,7 @@
+from django.db import models
+
+class People(models.Model):
+ name = models.CharField(max_length=255)
+
+class Message(models.Model):
+ from_field = models.ForeignKey(People, db_column='from_id')
diff --git a/tests/regressiontests/inspectdb/models.py b/tests/regressiontests/inspectdb/models.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/tests/regressiontests/inspectdb/models.py
@@ -0,0 +1 @@
+
diff --git a/tests/regressiontests/inspectdb/tests.py b/tests/regressiontests/inspectdb/tests.py
new file mode 100644
index 0000000000..30c7948b22
--- /dev/null
+++ b/tests/regressiontests/inspectdb/tests.py
@@ -0,0 +1,29 @@
+import os
+import sys
+from StringIO import StringIO
+
+from django.conf import settings
+from django.core.management import call_command
+from django.db.models.loading import load_app
+from django.test import TestCase
+
+class InspectDBTestCase(TestCase):
+
+ def setUp(self):
+ self.old_sys_path = sys.path[:]
+ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+ self.old_installed_apps = settings.INSTALLED_APPS
+ settings.INSTALLED_APPS = ('bug',)
+ map(load_app, settings.INSTALLED_APPS)
+ call_command('syncdb', verbosity=0)
+
+ def test_attribute_name_not_python_keyword(self):
+ out = StringIO()
+ call_command('inspectdb', stdout=out)
+ error_message = "inspectdb generated an attribute name which is a python keyword"
+ self.assertNotIn("from = models.ForeignKey(BugPeople)", out.getvalue(), msg=error_message)
+ out.close()
+
+ def tearDown(self):
+ settings.INSTALLED_APPS = self.old_installed_apps
+ sys.path = self.old_sys_path