forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_new.py
More file actions
57 lines (44 loc) · 1.58 KB
/
test_new.py
File metadata and controls
57 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import shutil
from unittest import TestCase
from unittest.mock import call, patch, MagicMock
from piccolo.apps.migrations.commands.new import (
_create_new_migration,
BaseMigrationManager,
new,
)
from piccolo.conf.apps import AppConfig
from piccolo.utils.sync import run_sync
from tests.base import postgres_only
from tests.example_app.tables import Manager
class TestNewMigrationCommand(TestCase):
def test_create_new_migration(self):
"""
Create a manual migration (i.e. non-auto).
"""
migration_folder = "/tmp/piccolo_migrations/"
if os.path.exists(migration_folder):
shutil.rmtree(migration_folder)
os.mkdir(migration_folder)
app_config = AppConfig(
app_name="music",
migrations_folder_path=migration_folder,
table_classes=[Manager],
)
run_sync(_create_new_migration(app_config, auto=False))
migration_modules = BaseMigrationManager().get_migration_modules(
migration_folder
)
self.assertTrue(len(migration_modules.keys()) == 1)
@postgres_only
@patch("piccolo.apps.migrations.commands.new.print")
def test_new_command(self, print_: MagicMock):
"""
Call the command, when no migration changes are needed.
"""
with self.assertRaises(SystemExit) as manager:
run_sync(new(app_name="example_app", auto=True))
self.assertEqual(manager.exception.code, 0)
self.assertTrue(
print_.mock_calls[-1] == call("No changes detected - exiting.")
)