Skip to content

Commit

Permalink
Fix schema generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abondar committed Jul 26, 2024
1 parent cf54410 commit 166e7e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ up:
@poetry update

deps:
@poetry install -E asyncpg -E aiomysql -E accel -E psycopg -E asyncodbc
@poetry install -E asyncpg -E aiomysql -E asyncmy -E accel -E psycopg -E asyncodbc

check: deps build
ifneq ($(shell which black),)
Expand Down
3 changes: 3 additions & 0 deletions tests/backends/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from tortoise import Tortoise
from tortoise.contrib import test
from tortoise.contrib.test.condition import NotIn


class TestMySQL(test.SimpleTestCase):
Expand All @@ -26,6 +27,8 @@ async def test_bad_charset(self):
with self.assertRaisesRegex(ConnectionError, "Unknown charset"):
await Tortoise.init(self.db_config, _create_db=True)

# asyncmy does not support ssl
@test.requireCapability(dialect=NotIn("mssql"))
async def test_ssl_true(self):
self.db_config["connections"]["models"]["credentials"]["ssl"] = True
try:
Expand Down
32 changes: 20 additions & 12 deletions tests/schema/test_generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async def test_schema_no_db_constraint(self):
"prize" VARCHAR(40),
"token" VARCHAR(100) NOT NULL UNIQUE /* Unique token */,
"key" VARCHAR(100) NOT NULL,
"tournament_id" SMALLINT NOT NULL,
"tournament_id" SMALLINT NOT NULL /* FK to tournament */,
CONSTRAINT "uid_event_name_c6f89f" UNIQUE ("name", "prize"),
CONSTRAINT "uid_event_tournam_a5b730" UNIQUE ("tournament_id", "key")
) /* This table contains a list of all the events */;
Expand Down Expand Up @@ -492,17 +492,19 @@ async def test_schema_no_db_constraint(self):
`prize` DECIMAL(10,2),
`token` VARCHAR(100) NOT NULL UNIQUE COMMENT 'Unique token',
`key` VARCHAR(100) NOT NULL,
`tournament_id` SMALLINT NOT NULL,
`tournament_id` SMALLINT NOT NULL COMMENT 'FK to tournament',
UNIQUE KEY `uid_event_name_c6f89f` (`name`, `prize`),
UNIQUE KEY `uid_event_tournam_a5b730` (`tournament_id`, `key`)
) CHARACTER SET utf8mb4 COMMENT='This table contains a list of all the events';
CREATE TABLE `team_team` (
`team_rel_id` VARCHAR(50) NOT NULL,
`team_id` VARCHAR(50) NOT NULL
`team_id` VARCHAR(50) NOT NULL,
UNIQUE KEY `uidx_team_team_team_re_d994df` (`team_rel_id`, `team_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE `teamevents` (
`event_id` BIGINT NOT NULL,
`team_id` VARCHAR(50) NOT NULL
`team_id` VARCHAR(50) NOT NULL,
UNIQUE KEY `uidx_teamevents_event_i_664dbc` (`event_id`, `team_id`)
) CHARACTER SET utf8mb4 COMMENT='How participants relate';""",
)

Expand Down Expand Up @@ -588,19 +590,22 @@ async def test_schema(self):
`backward_sts` INT NOT NULL,
`sts_forward` INT NOT NULL,
FOREIGN KEY (`backward_sts`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE,
FOREIGN KEY (`sts_forward`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE
FOREIGN KEY (`sts_forward`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE,
UNIQUE KEY `uidx_sometable_s_backwar_fc8fc8` (`backward_sts`, `sts_forward`)
) CHARACTER SET utf8mb4;
CREATE TABLE `team_team` (
`team_rel_id` VARCHAR(50) NOT NULL,
`team_id` VARCHAR(50) NOT NULL,
FOREIGN KEY (`team_rel_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
UNIQUE KEY `uidx_team_team_team_re_d994df` (`team_rel_id`, `team_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE `teamevents` (
`event_id` BIGINT NOT NULL,
`team_id` VARCHAR(50) NOT NULL,
FOREIGN KEY (`event_id`) REFERENCES `event` (`id`) ON DELETE SET NULL,
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE SET NULL
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE SET NULL,
UNIQUE KEY `uidx_teamevents_event_i_664dbc` (`event_id`, `team_id`)
) CHARACTER SET utf8mb4 COMMENT='How participants relate';
""".strip(),
)
Expand Down Expand Up @@ -691,19 +696,22 @@ async def test_schema_safe(self):
`backward_sts` INT NOT NULL,
`sts_forward` INT NOT NULL,
FOREIGN KEY (`backward_sts`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE,
FOREIGN KEY (`sts_forward`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE
FOREIGN KEY (`sts_forward`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE,
UNIQUE KEY `uidx_sometable_s_backwar_fc8fc8` (`backward_sts`, `sts_forward`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `team_team` (
`team_rel_id` VARCHAR(50) NOT NULL,
`team_id` VARCHAR(50) NOT NULL,
FOREIGN KEY (`team_rel_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
UNIQUE KEY `uidx_team_team_team_re_d994df` (`team_rel_id`, `team_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `teamevents` (
`event_id` BIGINT NOT NULL,
`team_id` VARCHAR(50) NOT NULL,
FOREIGN KEY (`event_id`) REFERENCES `event` (`id`) ON DELETE SET NULL,
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE SET NULL
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE SET NULL,
UNIQUE KEY `uidx_teamevents_event_i_664dbc` (`event_id`, `team_id`)
) CHARACTER SET utf8mb4 COMMENT='How participants relate';
""".strip(),
)
Expand Down Expand Up @@ -781,9 +789,9 @@ async def test_m2m_no_auto_create(self):
`team_rel_id` VARCHAR(50) NOT NULL,
`team_id` VARCHAR(50) NOT NULL,
FOREIGN KEY (`team_rel_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE
FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
UNIQUE KEY `uidx_team_team_team_re_d994df` (`team_rel_id`, `team_id`)
) CHARACTER SET utf8mb4;
CREATE UNIQUE INDEX IF NOT EXISTS "uidx_team_team_team_re_d994df" ON "team_team" ("team_rel_id", "team_id");
""".strip(),
)

Expand Down

0 comments on commit 166e7e4

Please sign in to comment.