3
3
"""Test dlairflow.postgresql.
4
4
"""
5
5
import os
6
+ import warnings
6
7
from ..postgresql import pg_dump_schema , pg_restore_schema
7
8
from airflow .hooks .base import BaseHook
9
+ from airflow .operators .bash import BashOperator
8
10
9
11
10
12
class MockConnection (object ):
@@ -29,7 +31,9 @@ def mock_connection(connection):
29
31
30
32
test_operator = pg_dump_schema ("login,password,host,schema" , "dump_schema" )
31
33
32
- print (dir (test_operator ))
34
+ assert isinstance (test_operator , BashOperator )
35
+ assert test_operator .env ['PGHOST' ] == 'host'
36
+ assert test_operator .params ['schema' ] == 'dump_schema'
33
37
34
38
35
39
def test_pg_dump_schema_alt_dir (monkeypatch ):
@@ -43,4 +47,38 @@ def mock_connection(connection):
43
47
44
48
test_operator = pg_dump_schema ("login,password,host,schema" , "dump_schema" , "dump_dir" )
45
49
46
- print (dir (test_operator ))
50
+ assert isinstance (test_operator , BashOperator )
51
+ assert test_operator .env ['PGHOST' ] == 'host'
52
+ assert test_operator .params ['dump_dir' ] == 'dump_dir'
53
+
54
+
55
+ def test_pg_restore_schema (monkeypatch ):
56
+ """Test pg_restore task.
57
+ """
58
+ def mock_connection (connection ):
59
+ conn = MockConnection (connection )
60
+ return conn
61
+
62
+ monkeypatch .setattr (BaseHook , "get_connection" , mock_connection )
63
+
64
+ test_operator = pg_restore_schema ("login,password,host,schema" , "dump_schema" )
65
+
66
+ assert isinstance (test_operator , BashOperator )
67
+ assert test_operator .env ['PGHOST' ] == 'host'
68
+ assert test_operator .params ['schema' ] == 'dump_schema'
69
+
70
+
71
+ def test_pg_dump_schema_alt_dir (monkeypatch ):
72
+ """Test pg_restore task with alternate directory.
73
+ """
74
+ def mock_connection (connection ):
75
+ conn = MockConnection (connection )
76
+ return conn
77
+
78
+ monkeypatch .setattr (BaseHook , "get_connection" , mock_connection )
79
+
80
+ test_operator = pg_restore_schema ("login,password,host,schema" , "dump_schema" , "dump_dir" )
81
+
82
+ assert isinstance (test_operator , BashOperator )
83
+ assert test_operator .env ['PGHOST' ] == 'host'
84
+ assert test_operator .params ['dump_dir' ] == 'dump_dir'
0 commit comments