Skip to content

Commit 258f06a

Browse files
committed
added tests for 'migrations new' command
1 parent 13ddd53 commit 258f06a

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

tests/apps/migrations/commands/test_base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ def tearDown(self):
1818

1919

2020
class TestGetMigrationModules(TestCase):
21-
"""
22-
This is tricky, because we need to have some example migrations on disk.
23-
Just create them.
24-
"""
25-
2621
@patch.object(BaseMigrationManager, "get_app_config")
2722
def test_get_migration_modules(self, get_app_config):
2823
get_app_config.return_value = AppConfig(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import shutil
3+
from unittest import TestCase
4+
5+
from piccolo.apps.migrations.commands.base import AppConfig
6+
from piccolo.apps.migrations.commands.new import (
7+
_create_new_migration,
8+
BaseMigrationManager,
9+
)
10+
11+
from tests.example_project.tables import Manager
12+
13+
14+
class TestNewMigrationCommand(TestCase):
15+
def test_create_new_migration(self):
16+
migration_folder = "/tmp/piccolo_migrations/"
17+
18+
if os.path.exists(migration_folder):
19+
shutil.rmtree(migration_folder)
20+
21+
os.mkdir(migration_folder)
22+
23+
app_config = AppConfig(
24+
app_name="music",
25+
migrations_folder_path=migration_folder,
26+
table_classes=[Manager],
27+
)
28+
29+
_create_new_migration(app_config, auto=False)
30+
31+
migration_modules = BaseMigrationManager().get_migration_modules(
32+
migration_folder
33+
)
34+
35+
self.assertTrue(len(migration_modules.keys()) == 1)

tests/example_project/tables.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
from piccolo import table
2-
from piccolo import columns
1+
from piccolo.table import Table
2+
from piccolo.columns import Varchar, ForeignKey, Integer
33

44

55
###############################################################################
66
# Simple example
77

88

9-
class Manager(table.Table):
10-
name = columns.Varchar(length=50)
9+
class Manager(Table):
10+
name = Varchar(length=50)
1111

1212

13-
class Band(table.Table):
14-
name = columns.Varchar(length=50)
15-
manager = columns.ForeignKey(Manager, null=True)
16-
popularity = columns.Integer(default=0)
13+
class Band(Table):
14+
name = Varchar(length=50)
15+
manager = ForeignKey(Manager, null=True)
16+
popularity = Integer(default=0)
1717

1818

1919
###############################################################################
2020
# More complex
2121

2222

23-
class Venue(table.Table):
24-
name = columns.Varchar(length=100)
25-
capacity = columns.Integer(default=0)
23+
class Venue(Table):
24+
name = Varchar(length=100)
25+
capacity = Integer(default=0)
2626

2727

28-
class Concert(table.Table):
29-
band_1 = columns.ForeignKey(Band)
30-
band_2 = columns.ForeignKey(Band)
31-
venue = columns.ForeignKey(Venue)
28+
class Concert(Table):
29+
band_1 = ForeignKey(Band)
30+
band_2 = ForeignKey(Band)
31+
venue = ForeignKey(Venue)

0 commit comments

Comments
 (0)