1
1
from parsons import Postgres , DBSync , Table , Redshift
2
+ import pytest
2
3
from parsons .databases .database_connector import DatabaseConnector
3
4
from abc import ABC
4
5
from test .test_databases .fakes import FakeDatabase
6
+
5
7
from test .utils import assert_matching_tables
6
8
from typing import Type
7
9
import unittest
@@ -41,7 +43,9 @@ def setUp(self):
41
43
f"{ self .temp_schema } .source_table" if self .temp_schema else "source_table"
42
44
)
43
45
self .destination_table = (
44
- f"{ self .temp_schema } .destination_table" if self .temp_schema else "destination_table"
46
+ f"{ self .temp_schema } .destination_table"
47
+ if self .temp_schema
48
+ else "destination_table"
45
49
)
46
50
47
51
# Create source table
@@ -64,7 +68,9 @@ def tearDown(self):
64
68
65
69
def assert_matching_tables (self ) -> None :
66
70
source = self .source_db .query (f"SELECT * FROM { self .source_table } " )
67
- destination = self .destination_db .query (f"SELECT * FROM { self .destination_table } " )
71
+ destination = self .destination_db .query (
72
+ f"SELECT * FROM { self .destination_table } "
73
+ )
68
74
assert_matching_tables (source , destination )
69
75
70
76
def table_sync_full (self , if_exists : str , ** kwargs ):
@@ -100,15 +106,19 @@ def test_table_sync_full_empty_table(self):
100
106
def test_table_sync_full_chunk (self ):
101
107
# Test chunking in full sync.
102
108
self .db_sync .chunk_size = 10
103
- self .db_sync .table_sync_full (self .source_table , self .destination_table , if_exists = "drop" )
109
+ self .db_sync .table_sync_full (
110
+ self .source_table , self .destination_table , if_exists = "drop"
111
+ )
104
112
self .assert_matching_tables ()
105
113
106
114
def test_table_sync_incremental (self ):
107
115
# Test that incremental sync
108
116
109
117
self .destination_db .copy (self .table1 , self .destination_table )
110
118
self .source_db .copy (self .table2 , self .source_table , if_exists = "append" )
111
- self .db_sync .table_sync_incremental (self .source_table , self .destination_table , "pk" )
119
+ self .db_sync .table_sync_incremental (
120
+ self .source_table , self .destination_table , "pk"
121
+ )
112
122
self .assert_matching_tables ()
113
123
114
124
def test_table_sync_incremental_chunk (self ):
@@ -117,13 +127,17 @@ def test_table_sync_incremental_chunk(self):
117
127
self .db_sync .chunk_size = 10
118
128
self .destination_db .copy (self .table1 , self .destination_table )
119
129
self .source_db .copy (self .table2 , self .source_table , if_exists = "append" )
120
- self .db_sync .table_sync_incremental (self .source_table , self .destination_table , "pk" )
130
+ self .db_sync .table_sync_incremental (
131
+ self .source_table , self .destination_table , "pk"
132
+ )
121
133
122
134
self .assert_matching_tables ()
123
135
124
136
def test_table_sync_incremental_create_destination_table (self ):
125
137
# Test that an incremental sync works if the destination table does not exist.
126
- self .db_sync .table_sync_incremental (self .source_table , self .destination_table , "pk" )
138
+ self .db_sync .table_sync_incremental (
139
+ self .source_table , self .destination_table , "pk"
140
+ )
127
141
self .assert_matching_tables ()
128
142
129
143
def test_table_sync_incremental_empty_table (self ):
@@ -182,9 +196,7 @@ def test_table_sync_full_write_chunk(self):
182
196
)
183
197
184
198
185
- # These tests interact directly with the Postgres database. In order to run, set the
186
- # env to LIVE_TEST='TRUE'.
187
- @unittest .skipIf (not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test" )
199
+ @pytest .mark .usefixtures ("postgres_container" )
188
200
class TestPostgresDBSync (TestDBSync ):
189
201
db = Postgres
190
202
setup_sql = f"""
@@ -198,6 +210,8 @@ class TestPostgresDBSync(TestDBSync):
198
210
199
211
# These tests interact directly with the Postgres database. In order to run, set the
200
212
# env to LIVE_TEST='TRUE'.
201
- @unittest .skipIf (not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test" )
213
+ @unittest .skipIf (
214
+ not os .environ .get ("LIVE_TEST" ), "Skipping because not running live test"
215
+ )
202
216
class TestRedshiftDBSync (TestPostgresDBSync ):
203
217
db = Redshift
0 commit comments