From 60947322a582e4bc3f07622024ef7e2d470b0d68 Mon Sep 17 00:00:00 2001 From: Jason Pellerin Date: Fri, 7 Jul 2006 21:31:16 +0000 Subject: [PATCH] [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 --- tests/modeltests/multiple_databases/models.py | 3 ++- tests/othertests/ansi_sql.py | 20 +++++++++++------- .../othertests/manager_schema_manipulation.py | 21 +++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/tests/modeltests/multiple_databases/models.py b/tests/modeltests/multiple_databases/models.py index 9c974ef7bd..b9a1939d41 100644 --- a/tests/modeltests/multiple_databases/models.py +++ b/tests/modeltests/multiple_databases/models.py @@ -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() diff --git a/tests/othertests/ansi_sql.py b/tests/othertests/ansi_sql.py index 7dfe1165b2..de12eaf590 100644 --- a/tests/othertests/ansi_sql.py +++ b/tests/othertests/ansi_sql.py @@ -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 [] ->>> 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,...);')], {: [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" (...);')] +{: [BoundStatement('CREATE TABLE "ansi_sql_collector_cars" (...);')]} # test indexes >>> builder.get_create_indexes(Car) diff --git a/tests/othertests/manager_schema_manipulation.py b/tests/othertests/manager_schema_manipulation.py index e3c8fb37b9..1b69083e0e 100644 --- a/tests/othertests/manager_schema_manipulation.py +++ b/tests/othertests/manager_schema_manipulation.py @@ -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");')] +{: [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" (...);')] +{} """