1
- import os
2
-
3
1
import pytest
4
2
3
+ from flux .config import FluxConfig
5
4
from flux .exceptions import InvalidMigrationModuleError
6
5
from flux .migration .read_migration import read_python_migration , read_sql_migration
7
- from tests .unit .constants import MIGRATIONS_DIR
8
6
9
- EXAMPLE_SQL_UP = os .path .join (MIGRATIONS_DIR , "example_up.sql" )
10
- EXAMPLE_SQL_DOWN = os .path .join (MIGRATIONS_DIR , "example_down.sql" )
11
- EXAMPLE_PYTHON_DOWN_STR = os .path .join (
12
- MIGRATIONS_DIR , "example_python_migration_down_str.py"
13
- )
14
- EXAMPLE_PYTHON_DOWN_NONE = os .path .join (
15
- MIGRATIONS_DIR , "example_python_migration_down_none.py"
16
- )
17
- EXAMPLE_PYTHON_DOWN_MISSING = os .path .join (
18
- MIGRATIONS_DIR , "example_python_migration_down_missing.py"
19
- )
7
+ EXAMPLE_SQL_WITH_DOWN = "sql_example"
8
+ EXAMPLE_SQL_WITHOUT_DOWN = "sql_example_2"
9
+ EXAMPLE_PYTHON_DOWN_STR = "example_python_migration_down_str"
10
+ EXAMPLE_PYTHON_DOWN_NONE = "example_python_migration_down_none"
11
+ EXAMPLE_PYTHON_DOWN_MISSING = "example_python_migration_down_missing"
20
12
21
13
22
- INVALID_PYTHON_DOWN_INT = os .path .join (
23
- MIGRATIONS_DIR , "invalid_python_migration_down_int.py"
24
- )
25
- INVALID_PYTHON_DOWN_RAISES = os .path .join (
26
- MIGRATIONS_DIR , "invalid_python_migration_down_raises.py"
27
- )
28
- INVALID_PYTHON_UP_INT = os .path .join (
29
- MIGRATIONS_DIR , "invalid_python_migration_up_int.py"
30
- )
31
- INVALID_PYTHON_UP_MISSING = os .path .join (
32
- MIGRATIONS_DIR , "invalid_python_migration_up_missing.py"
33
- )
34
- INVALID_PYTHON_UP_RAISES = os .path .join (
35
- MIGRATIONS_DIR , "invalid_python_migration_up_raises.py"
36
- )
14
+ INVALID_PYTHON_DOWN_INT = "invalid_python_migration_down_int"
15
+ INVALID_PYTHON_DOWN_RAISES = "invalid_python_migration_down_raises"
16
+ INVALID_PYTHON_UP_INT = "invalid_python_migration_up_int"
17
+ INVALID_PYTHON_UP_MISSING = "invalid_python_migration_up_missing"
18
+ INVALID_PYTHON_UP_RAISES = "invalid_python_migration_up_raises"
37
19
38
20
EXAMPLE_UP_TEXT = "create table example_table ( id serial primary key, name text );"
39
21
EXAMPLE_DOWN_TEXT = "drop table example_table;"
40
22
41
23
42
- def test_read_sql_migration_with_down ():
43
- migration = read_sql_migration (EXAMPLE_SQL_UP , EXAMPLE_SQL_DOWN )
24
+ def test_read_sql_migration_with_down (in_memory_config : FluxConfig ):
25
+ migration = read_sql_migration (
26
+ config = in_memory_config ,
27
+ migration_id = EXAMPLE_SQL_WITH_DOWN ,
28
+ )
44
29
assert migration .up == f"{ EXAMPLE_UP_TEXT } \n "
45
30
assert migration .down == f"{ EXAMPLE_DOWN_TEXT } \n "
46
31
assert migration .up_hash == "a53b94e10e61374e5a20f9e361d638e2"
47
32
48
33
49
- def test_read_sql_migration_without_down ():
50
- migration = read_sql_migration (EXAMPLE_SQL_UP , None )
34
+ def test_read_sql_migration_without_down (in_memory_config : FluxConfig ):
35
+ migration = read_sql_migration (
36
+ config = in_memory_config ,
37
+ migration_id = EXAMPLE_SQL_WITHOUT_DOWN ,
38
+ )
51
39
assert migration .up == f"{ EXAMPLE_UP_TEXT } \n "
52
40
assert migration .down is None
53
41
assert migration .up_hash == "a53b94e10e61374e5a20f9e361d638e2"
54
42
55
43
56
- def test_read_sql_migration_with_up_not_exist ():
57
- with pytest .raises (InvalidMigrationModuleError ):
58
- read_sql_migration ("fake.sql" , EXAMPLE_SQL_DOWN )
59
-
60
-
61
- def test_read_sql_migration_with_down_not_exist ():
44
+ def test_read_sql_migration_not_exist (in_memory_config : FluxConfig ):
62
45
with pytest .raises (InvalidMigrationModuleError ):
63
- read_sql_migration (EXAMPLE_SQL_UP , "fake.sql " )
46
+ read_sql_migration (config = in_memory_config , migration_id = "fake" )
64
47
65
48
66
- def test_read_python_migration_down_str ():
67
- migration = read_python_migration (EXAMPLE_PYTHON_DOWN_STR )
49
+ def test_read_python_migration_down_str (in_memory_config : FluxConfig ):
50
+ migration = read_python_migration (
51
+ config = in_memory_config ,
52
+ migration_id = EXAMPLE_PYTHON_DOWN_STR ,
53
+ )
68
54
assert migration .up == f"{ EXAMPLE_UP_TEXT } "
69
55
assert migration .down == f"{ EXAMPLE_DOWN_TEXT } "
70
56
assert migration .up_hash == "2ea715441b43f1bdc8428238385bb592"
71
57
72
58
73
- def test_read_python_migration_down_none ():
74
- migration = read_python_migration (EXAMPLE_PYTHON_DOWN_NONE )
59
+ def test_read_python_migration_down_none (in_memory_config : FluxConfig ):
60
+ migration = read_python_migration (
61
+ config = in_memory_config ,
62
+ migration_id = EXAMPLE_PYTHON_DOWN_NONE ,
63
+ )
75
64
assert migration .up == f"{ EXAMPLE_UP_TEXT } "
76
65
assert migration .down is None
77
66
assert migration .up_hash == "2ea715441b43f1bdc8428238385bb592"
78
67
79
68
80
- def test_read_python_migration_down_missing ():
81
- migration = read_python_migration (EXAMPLE_PYTHON_DOWN_MISSING )
69
+ def test_read_python_migration_down_missing (in_memory_config : FluxConfig ):
70
+ migration = read_python_migration (
71
+ config = in_memory_config ,
72
+ migration_id = EXAMPLE_PYTHON_DOWN_MISSING ,
73
+ )
82
74
assert migration .up == f"{ EXAMPLE_UP_TEXT } "
83
75
assert migration .down is None
84
76
assert migration .up_hash == "2ea715441b43f1bdc8428238385bb592"
85
77
86
78
87
79
@pytest .mark .parametrize (
88
- "migration_file " ,
80
+ "migration_id " ,
89
81
[
90
82
INVALID_PYTHON_DOWN_INT ,
91
83
INVALID_PYTHON_DOWN_RAISES ,
@@ -94,6 +86,6 @@ def test_read_python_migration_down_missing():
94
86
INVALID_PYTHON_UP_RAISES ,
95
87
],
96
88
)
97
- def test_read_python_migration_invalid (migration_file ):
89
+ def test_read_python_migration_invalid (in_memory_config : FluxConfig , migration_id : str ):
98
90
with pytest .raises (InvalidMigrationModuleError ):
99
- read_python_migration (migration_file )
91
+ read_python_migration (config = in_memory_config , migration_id = migration_id )
0 commit comments