1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[multi-db] Updated tests to expect pendings in dict format instead of

list.


git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3293 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jason Pellerin 2006-07-07 21:31:16 +00:00
parent c1087076b4
commit 60947322a5
3 changed files with 26 additions and 18 deletions

View File

@ -131,11 +131,12 @@ False
>>> artists[0]._meta.connection.settings == connections['django_test_db_a'].settings
True
# When not using transaction management, model save will commit only
# When transactions are not managed, model save will commit only
# for the model's connection.
>>> from django.db import transaction
>>> transaction.enter_transaction_management()
>>> transaction.managed(False)
>>> a = Artist(name="Joan Miro", alive=False)
>>> w = Widget(code="99rbln", weight=1)
>>> a.save()

View File

@ -1,3 +1,7 @@
# For Python 2.3
if not hasattr(__builtins__, 'set'):
from sets import Set as set
"""
>>> from django.db import models
>>> from django.db.backends.ansi import sql
@ -33,30 +37,30 @@
([BoundStatement('CREATE TABLE "ansi_sql_car" (...);')], [])
>>> builder.models_already_seen
[<class 'othertests.ansi_sql.Car'>]
>>> builder.models_already_seen = []
>>> builder.models_already_seen = set()
# test that styles are used
>>> builder.get_create_table(Car, style=mockstyle())
([BoundStatement('SQL_KEYWORD(CREATE TABLE) SQL_TABLE("ansi_sql_car") (...SQL_FIELD("id")...);')], [])
# test pending relationships
>>> builder.models_already_seen = []
>>> builder.models_already_seen = set()
>>> real_cnst = Mod._meta.connection_info.backend.supports_constraints
>>> Mod._meta.connection_info.backend.supports_constraints = True
>>> builder.get_create_table(Mod)
([BoundStatement('CREATE TABLE "ansi_sql_mod" (..."car_id" integer NOT NULL,...);')], [BoundStatement('ALTER TABLE "ansi_sql_mod" ADD CONSTRAINT ... FOREIGN KEY ("car_id") REFERENCES "ansi_sql_car" ("id");')])
>>> builder.models_already_seen = []
([BoundStatement('CREATE TABLE "ansi_sql_mod" (..."car_id" integer NOT NULL,...);')], {<class 'othertests.ansi_sql.Car'>: [BoundStatement('ALTER TABLE "ansi_sql_mod" ADD CONSTRAINT ... FOREIGN KEY ("car_id") REFERENCES "ansi_sql_car" ("id");')]})
>>> builder.models_already_seen = set()
>>> builder.get_create_table(Car)
([BoundStatement('CREATE TABLE "ansi_sql_car" (...);')], [])
([BoundStatement('CREATE TABLE "ansi_sql_car" (...);')], {})
>>> builder.get_create_table(Mod)
([BoundStatement('CREATE TABLE "ansi_sql_mod" (..."car_id" integer NOT NULL REFERENCES "ansi_sql_car" ("id"),...);')], [])
([BoundStatement('CREATE TABLE "ansi_sql_mod" (..."car_id" integer NOT NULL REFERENCES "ansi_sql_car" ("id"),...);')], {})
>>> Mod._meta.connection_info.backend.supports_constraints = real_cnst
# test many-many
>>> builder.get_create_table(Collector)
([BoundStatement('CREATE TABLE "ansi_sql_collector" (...);')], [])
([BoundStatement('CREATE TABLE "ansi_sql_collector" (...);')], {})
>>> builder.get_create_many_to_many(Collector)
[BoundStatement('CREATE TABLE "ansi_sql_collector_cars" (...);')]
{<class 'othertests.ansi_sql.Car'>: [BoundStatement('CREATE TABLE "ansi_sql_collector_cars" (...);')]}
# test indexes
>>> builder.get_create_indexes(Car)

View File

@ -87,11 +87,11 @@
# use the default connection or a named connection.
>>> DA.objects.install()
[]
{}
>>> QA.objects.install()
[]
{}
>>> QB.objects.install()
[]
{}
>>> DA.objects.all()
[]
>>> list(QA.objects.all())
@ -107,25 +107,28 @@
# statements that could not be executed because (for instance) they are
# meant to establish foreign key relationships to tables that don't
# exist. These are bound to the model's connection and should
# be executed after all models in the app have been installed.
# be executed after all models in the app have been installed. The pending
# statments are returned as a dict keyed by the model which must be installed
# before the pending statements can be installed.
# NOTE: pretend db supports constraints for this test
>>> real_cnst = PA._meta.connection_info.backend.supports_constraints
>>> PA._meta.connection_info.backend.supports_constraints = True
>>> result = PA.objects.install()
>>> result
[BoundStatement('ALTER TABLE "othertests_pa" ADD CONSTRAINT "c_id_referencing_othertests_pc_id" FOREIGN KEY ("c_id") REFERENCES "othertests_pc" ("id");')]
{<class 'othertests.manager_schema_manipulation.PC'>: [BoundStatement('ALTER TABLE "othertests_pa" ADD CONSTRAINT "c_id_referencing_othertests_pc_id" FOREIGN KEY ("c_id") REFERENCES "othertests_pc" ("id");')]}
# NOTE: restore real constraint flag
>>> PA._meta.connection_info.backend.supports_constraints = real_cnst
# Models with many-many relationships will also have pending statement
# Models with many-many relationships may also have pending statement
# lists. Like other pending statements, these should be executed after
# all models in the app have been installed.
# all models in the app have been installed. If the related table's model
# has already been created, then there will be no pending list.
>>> QC.objects.install()
[]
{}
>>> QD.objects.install()
[BoundStatement('CREATE TABLE "othertests_qd_qcs" (...);')]
{}
"""