forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_base.py
More file actions
61 lines (50 loc) · 1.82 KB
/
test_base.py
File metadata and controls
61 lines (50 loc) · 1.82 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
58
59
60
61
import os
from unittest import TestCase
from unittest.mock import patch
from piccolo.conf.apps import AppConfig
from piccolo.apps.migrations.commands.base import (
BaseMigrationManager,
Migration,
)
from piccolo.utils.sync import run_sync
class TestBaseMigrationManager(TestCase):
def test_create_migration_table(self):
self.assertTrue(
run_sync(BaseMigrationManager().create_migration_table())
)
def tearDown(self):
Migration.raw("DROP TABLE IF EXISTS migration").run_sync()
class TestGetMigrationModules(TestCase):
@patch.object(BaseMigrationManager, "get_app_config")
def test_get_migration_modules(self, get_app_config):
get_app_config.return_value = AppConfig(
app_name="music",
migrations_folder_path=os.path.join(
os.path.dirname(__file__), "test_migrations"
),
)
migration_managers = run_sync(
BaseMigrationManager().get_migration_managers(app_name="music")
)
self.assertTrue(len(migration_managers) == 1)
self.assertTrue(
migration_managers[0].migration_id == "2020-03-31T20:38:22"
)
class TestGetTableFromSnapshot(TestCase):
@patch.object(BaseMigrationManager, "get_app_config")
def test_get_table_from_snaphot(self, get_app_config):
"""
Test the get_table_from_snaphot method.
"""
get_app_config.return_value = AppConfig(
app_name="music",
migrations_folder_path=os.path.join(
os.path.dirname(__file__), "test_migrations"
),
)
table = run_sync(
BaseMigrationManager().get_table_from_snaphot(
app_name="music", table_class_name="Band"
)
)
self.assertTrue(table.class_name == "Band")