File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed
piccolo/apps/migrations/commands
tests/apps/migrations/commands Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 66import sys
77import typing as t
88
9- from piccolo .conf .apps import AppConfig , MigrationModule , PiccoloAppModule
9+ from piccolo .conf .apps import (
10+ AppConfig ,
11+ MigrationModule ,
12+ PiccoloAppModule ,
13+ AppRegistry ,
14+ )
1015from piccolo .apps .migrations .auto .migration_manager import MigrationManager
1116from piccolo .apps .migrations .auto .diffable_table import DiffableTable
1217from piccolo .apps .migrations .auto .schema_snapshot import SchemaSnapshot
@@ -57,19 +62,22 @@ def _import_app_modules(
5762
5863 return config_modules
5964
60- def get_app_modules (self ) -> t .List [PiccoloAppModule ]:
61- """
62- Returns the piccolo_app.py modules for each registered Piccolo app.
63- """
65+ def get_app_registry (self ) -> AppRegistry :
6466 try :
6567 from piccolo_conf import APP_REGISTRY
6668 except ImportError :
6769 raise Exception (
6870 "Unable to import APP_REGISTRY from piccolo_conf - make sure "
6971 "it's in your path."
7072 )
73+ return APP_REGISTRY
7174
72- app_modules = self ._import_app_modules (APP_REGISTRY .apps )
75+ def get_app_modules (self ) -> t .List [PiccoloAppModule ]:
76+ """
77+ Returns the piccolo_app.py modules for each registered Piccolo app.
78+ """
79+ app_registry = self .get_app_registry ()
80+ app_modules = self ._import_app_modules (app_registry .apps )
7381
7482 # Now deduplicate any dependencies
7583 app_modules = self ._deduplicate (app_modules )
Original file line number Diff line number Diff line change 1- from .base import BaseMigrationManager
1+ from piccolo . apps . migrations . commands .base import BaseMigrationManager
22from piccolo .apps .migrations .tables import Migration
33from piccolo .utils .printing import get_fixed_length_string
44
Original file line number Diff line number Diff line change 1+ from unittest import TestCase
2+ from unittest .mock import patch , MagicMock
3+
4+ from piccolo .conf .apps import AppRegistry
5+ from piccolo .apps .migrations .commands .check import check , CheckMigrationManager
6+
7+
8+ class TestCheckMigrationCommand (TestCase ):
9+ @patch .object (
10+ CheckMigrationManager , "get_app_registry" ,
11+ )
12+ def test_check_migrations (self , get_app_registry : MagicMock ):
13+ get_app_registry .return_value = AppRegistry (
14+ apps = ["piccolo.apps.user.piccolo_app" ]
15+ )
16+
17+ # Make sure it runs without raising an exception:
18+ check ()
You can’t perform that action at this time.
0 commit comments