11import asyncio
2+ from piccolo .conf .apps import AppConfig
23from piccolo .columns .column_types import ForeignKey
34from unittest .mock import patch , MagicMock
45
@@ -86,7 +87,8 @@ async def run():
8687 asyncio .run (manager .run_backwards ())
8788
8889 @postgres_only
89- def test_add_table (self ):
90+ @patch .object (BaseMigrationManager , "get_app_config" )
91+ def test_add_table (self , get_app_config : MagicMock ):
9092 """
9193 Test adding a table to a MigrationManager.
9294 """
@@ -106,6 +108,10 @@ def test_add_table(self):
106108 self .assertEqual (response , [{"id" : 1 , "name" : "Bob Jones" }])
107109
108110 # Reverse
111+
112+ get_app_config .return_value = AppConfig (
113+ app_name = "music" , migrations_folder_path = ""
114+ )
109115 asyncio .run (manager .run_backwards ())
110116 self .assertEqual (self .table_exists ("musician" ), False )
111117 self .run_sync ("DROP TABLE IF EXISTS musician;" )
@@ -255,7 +261,10 @@ def test_add_non_nullable_column(self):
255261
256262 @postgres_only
257263 @patch .object (BaseMigrationManager , "get_migration_managers" )
258- def test_drop_column (self , get_migration_managers : MagicMock ):
264+ @patch .object (BaseMigrationManager , "get_app_config" )
265+ def test_drop_column (
266+ self , get_app_config : MagicMock , get_migration_managers : MagicMock
267+ ):
259268 """
260269 Test dropping a column with MigrationManager.
261270 """
@@ -284,6 +293,8 @@ def test_drop_column(self, get_migration_managers: MagicMock):
284293
285294 # Reverse
286295 set_mock_return_value (get_migration_managers , [manager_1 ])
296+ app_config = AppConfig (app_name = "music" , migrations_folder_path = "" )
297+ get_app_config .return_value = app_config
287298 asyncio .run (manager_2 .run_backwards ())
288299 response = self .run_sync ("SELECT * FROM musician;" )
289300 self .assertEqual (response , [{"id" : 1 , "name" : "" }])
@@ -596,7 +607,10 @@ def test_alter_column_set_length(self):
596607
597608 @postgres_only
598609 @patch .object (BaseMigrationManager , "get_migration_managers" )
599- def test_drop_table (self , get_migration_managers : MagicMock ):
610+ @patch .object (BaseMigrationManager , "get_app_config" )
611+ def test_drop_table (
612+ self , get_app_config : MagicMock , get_migration_managers : MagicMock
613+ ):
600614 self .run_sync ("DROP TABLE IF EXISTS musician;" )
601615
602616 name_column = Varchar ()
@@ -612,14 +626,16 @@ def test_drop_table(self, get_migration_managers: MagicMock):
612626 manager_2 .drop_table (class_name = "Musician" , tablename = "musician" )
613627 asyncio .run (manager_2 .run ())
614628
615- set_mock_return_value (get_migration_managers , [manager_1 ])
616-
617629 self .assertTrue (not self .table_exists ("musician" ))
618630
631+ # Reverse
632+ set_mock_return_value (get_migration_managers , [manager_1 ])
633+ app_config = AppConfig (app_name = "music" , migrations_folder_path = "" )
634+ get_app_config .return_value = app_config
619635 asyncio .run (manager_2 .run_backwards ())
620636
621637 get_migration_managers .assert_called_with (
622- app_name = "music" , max_migration_id = "2" , offset = - 1
638+ app_config = app_config , max_migration_id = "2" , offset = - 1
623639 )
624640 self .assertTrue (self .table_exists ("musician" ))
625641
0 commit comments