Shinya Okano avatar Shinya Okano committed b87f5b2

Djagno1.1でテスト用データベースをセットアップできるように修正

Comments (0)

Files changed (2)

tests/djangomodel_tests.py

         testing_django._setup_db()
         testing_django.create_table(ChildModel)
         testing_django.create_table(ParentModel)
+        if testing_django.get_django_version() < (1, 2):
+            testing_django.create_table(ThroughModel)
 
         class TestMapper(djangomodel.ModelMapper):
             class Meta:

tests/testing_django.py

     return obj.__class__.__name__.lower()
 
 
-def initialize():
-    from django.conf import settings
-    settings.configure(
-        DATABASES={
-            'default': {
-                'ENGINE': 'django.db.backends.sqlite3',
-                'NAME': ':memory:',
-            },
-        },
-    )
-
-
 def get_django_version():
     return django.VERSION
 
 
+def initialize():
+    from django.conf import settings
+    if get_django_version() >= (1, 2):
+        settings_dict = dict(
+            DATABASES={
+                'default': {
+                    'ENGINE': 'django.db.backends.sqlite3',
+                    'NAME': ':memory:',
+                },
+            },
+        )
+    else:
+        settings_dict = dict(
+            DATABASE_ENGINE='sqlite3',
+            DATABASE_NAME=':memory:'
+        )
+    settings.configure(**settings_dict)
+
+
 def get_connection():
     "get default database connection"
-    from django.db import connections
-    return connections['default']
+    if get_django_version() >= (1, 2):
+        from django.db import connections
+        connection = connections['default']
+    else:
+        from django.db import connection
+    return connection
 
 
 def get_cursor(connection):
     for statement in sql:
         cursor.execute(statement)
     for f in model._meta.many_to_many:
-        create_table(f.rel.through)
+        if get_django_version() >= (1, 2):
+            create_table(f.rel.through)
+        else:
+            m2m_sql = connection.creation.sql_for_many_to_many(model, style)
+            if m2m_sql:
+                cursor.execute(m2m_sql[0])
 
 
 def _setup_db():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.