Ticket #12308: t12308_2.diff

File t12308_2.diff, 3.3 KB (added by Andrii Kurinnyi, 14 years ago)

added tests

  • django/db/backends/postgresql/operations.py

    diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
    index f517436..1f5fb6e 100644
    a b class DatabaseOperations(BaseDatabaseOperations):  
    133133                        style.SQL_TABLE(qn(f.m2m_db_table()))))
    134134        return output
    135135
     136    def tablespace_sql(self, tablespace, inline=False):
     137        return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""),
     138            self.quote_name(tablespace))
     139
    136140    def savepoint_create_sql(self, sid):
    137141        return "SAVEPOINT %s" % sid
    138142
  • new file tests/modeltests/tablespaces/tablespaces_app/models.py

    diff --git a/tests/modeltests/tablespaces/__init__.py b/tests/modeltests/tablespaces/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/modeltests/tablespaces/models.py b/tests/modeltests/tablespaces/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/modeltests/tablespaces/tablespaces_app/__init__.py b/tests/modeltests/tablespaces/tablespaces_app/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/modeltests/tablespaces/tablespaces_app/models.py b/tests/modeltests/tablespaces/tablespaces_app/models.py
    new file mode 100644
    index 0000000..947a0b2
    - +  
     1from django.db import models
     2
     3class TestModel1(models.Model):
     4    """
     5    Model with overriden tablespace
     6    """
     7    name = models.CharField(max_length=255, default='')
     8
     9    class Meta:
     10        db_tablespace = "custom1"
     11
     12class TestModel2(models.Model):
     13    """
     14    Model with default tablespace
     15    """
     16    name = models.CharField(max_length=255, default='')
  • new file tests/modeltests/tablespaces/tests.py

    diff --git a/tests/modeltests/tablespaces/tests.py b/tests/modeltests/tablespaces/tests.py
    new file mode 100644
    index 0000000..3fc3c58
    - +  
     1from django.core.management import call_command
     2from django.test import TestCase
     3from django.conf import settings
     4import sys
     5from StringIO import StringIO
     6from django.db import DEFAULT_DB_ALIAS
     7
     8if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].startswith('django.db.backends.postgresql'):
     9    class TablespacesTests(TestCase):
     10
     11        def setUp(self):
     12            self.old_default_tablespace = settings.DEFAULT_TABLESPACE
     13            settings.DEFAULT_TABLESPACE = "custom"
     14            self.old_installed_apps = settings.INSTALLED_APPS
     15            settings.INSTALLED_APPS+=['modeltests.tablespaces.tablespaces_app']
     16
     17        def tearDown(self):
     18            settings.DEFAULT_TABLESPACE = self.old_default_tablespace
     19            settings.INSTALLED_APPS = self.old_installed_apps
     20
     21        def test_tablespace(self):
     22            sys.stdout = StringIO()
     23            call_command("sql", "tablespaces_app")
     24            output = sys.stdout.getvalue().strip()
     25            sys.stdout = sys.__stdout__
     26            result = 'BEGIN;\nCREATE TABLE "tablespaces_app_testmodel1" (\n    "id" serial NOT NULL PRIMARY KEY USING INDEX TABLESPACE "custom1",\n    "name" varchar(255) NOT NULL\n)\nTABLESPACE "custom1"\n;\nCREATE TABLE "tablespaces_app_testmodel2" (\n    "id" serial NOT NULL PRIMARY KEY USING INDEX TABLESPACE "custom",\n    "name" varchar(255) NOT NULL\n)\nTABLESPACE "custom"\n;\nCOMMIT;'
     27            self.assertEqual(output, result)
Back to Top