Commit 5a3ae7e2 authored by Moayad Mardini's avatar Moayad Mardini Committed by Tim Graham
Browse files

Created a new tests folder (`model_options`).

And moved `tablespaces` option tests to it.
The new folder can be used to test models/options, like the new option
added in refs #22778.
parent 68efbfde
Loading
Loading
Loading
Loading
+0 −0

Empty file added.

+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ class Scientist(models.Model):
    name = models.CharField(max_length=50)

    class Meta:
        db_table = 'tablespaces_scientistref'
        db_table = 'model_options_scientistref'
        db_tablespace = 'tbl_tbsp'
        managed = False

@@ -35,14 +35,14 @@ class Article(models.Model):
    reviewers = models.ManyToManyField(Scientist, related_name='articles_reviewed_set', db_tablespace='idx_tbsp')

    class Meta:
        db_table = 'tablespaces_articleref'
        db_table = 'model_options_articleref'
        db_tablespace = 'tbl_tbsp'
        managed = False

# Also set the tables for automatically created models

Authors = Article._meta.get_field('authors').rel.through
Authors._meta.db_table = 'tablespaces_articleref_authors'
Authors._meta.db_table = 'model_options_articleref_authors'

Reviewers = Article._meta.get_field('reviewers').rel.through
Reviewers._meta.db_table = 'tablespaces_articleref_reviewers'
Reviewers._meta.db_table = 'model_options_articleref_reviewers'
+12 −10
Original line number Diff line number Diff line
@@ -6,27 +6,29 @@ from django.db import connection
from django.core.management.color import no_style
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature

from .models import Article, ArticleRef, Authors, Reviewers, Scientist, ScientistRef

# We can't test the DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE settings
# because they're evaluated when the model class is defined. As a consequence,
# @override_settings doesn't work, and the tests depend
from .models.tablespaces import (Article, ArticleRef, Authors, Reviewers,
    Scientist, ScientistRef)


def sql_for_table(model):
    return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
    return '\n'.join(connection.creation.sql_create_model(model,
                                                          no_style())[0])


def sql_for_index(model):
    return '\n'.join(connection.creation.sql_indexes_for_model(model, no_style()))
    return '\n'.join(connection.creation.sql_indexes_for_model(model,
                                                               no_style()))


# We can't test the DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE settings
# because they're evaluated when the model class is defined. As a consequence,
# @override_settings doesn't work, and the tests depend
class TablespacesTests(TestCase):

    def setUp(self):
        # The unmanaged models need to be removed after the test in order to
        # prevent bad interactions with the flush operation in other tests.
        self._old_models = apps.app_configs['tablespaces'].models.copy()
        self._old_models = apps.app_configs['model_options'].models.copy()

        for model in Article, Authors, Reviewers, Scientist:
            model._meta.managed = True
@@ -35,8 +37,8 @@ class TablespacesTests(TestCase):
        for model in Article, Authors, Reviewers, Scientist:
            model._meta.managed = False

        apps.app_configs['tablespaces'].models = self._old_models
        apps.all_models['tablespaces'] = self._old_models
        apps.app_configs['model_options'].models = self._old_models
        apps.all_models['model_options'] = self._old_models
        apps.clear_cache()

    def assertNumContains(self, haystack, needle, count):