-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_config.py
249 lines (211 loc) · 8.37 KB
/
test_config.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
from eneel.config import *
import os
import pytest
from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv())
@pytest.fixture
def test_project_yml(tmp_path):
test_project_yml_path = tmp_path / "test_project.yml"
test_project_yml_path.write_text(
"""# Project info
id: project id # OPTIONAL and currently not used
name: project name # OPTIONAL and currently not used
owner: [email protected] # OPTIONAL and currently not used
temp_path: /tempfiles # The directory to use for temp csv files during load (OPTIONAL: default=run_path/temp )
csv_delimiter: "|" # The delimiter to use in the csv files (OPTIONAL: default=| )
# Connection details
source: postgres1 # A Connection name in connections.yml
target: sqlserver1 # A Connection name in connections.yml
# Source to Destination Schema mapping
schemas:
- source_schema: "public" # You can replicate from multiple schemas
target_schema: "public_tgt" # Target schema
table_prefix: "pre_" # Prefix for all created tables name (OPTIONAL)
table_suffix: "suf_" # Suffix for all created tables name (OPTIONAL)
tables: # List Tables to replicate
- table_name: "customer" # Source table name
replication_method: FULL_TABLE # FULL_TABLE replication. Will recreate the table on each load
- table_name: "payment"
replication_method: INCREMENTAL # INCREMENTAL replication. Will add new rows to the table
replication_key: "payment_date" # Incremental load needs replication key"""
)
yield str(test_project_yml_path)
@pytest.fixture
def test_config_yml(tmp_path):
test_config_yml_path = tmp_path / "test_connections.yml"
test_config_yml_path.write_text(
"""# Connection details to an Postgres database
postgres1:
type: postgres
read_only: False # Will disable SQL and DML modifications
outputs:
dev:
host: localhost
port: 5432
user: user_name
password: secret_password
database: my_db
limit_rows: 100 # Will limit all exports to 100 rows
prod:
host: prodserver_host
port: 5432
user: user_name
password: secret_password
database: my_db
target: dev # The profile that will be used when running the load
# Connection details to an SQL Server database
sqlserver1:
type: sqlserver
outputs:
dev:
driver: ODBC Driver 17 for SQL Server # Your ODBC driver
host: localhost
port: 1433
trusted_connection: True # Use logged in user for credentials
as_columnstore: True # Create tables as Clustered Columnstore Index (SQL Server only)
database: my_db
limit_rows: 100
prod:
driver: ODBC Driver 17 for SQL Server
host: prodserver_host
port: 1433
user: user_name
password: secret_password
database: my_db
target: dev # The profile that will be used when running the load
# Connection details to an Oracle database
oracle1:
type: oracle
outputs:
dev:
host: localhost
port: 1521
user: user_name
password: secret_password
database: my_db
limit_rows: 100 # Will limit all exports to 100 rows
prod:
host: prodserver_host
port: 1521
user: user_name
password: secret_password
database: my_db
target: dev # The profile that will be used when running the load"""
)
yield str(test_config_yml_path)
@pytest.fixture
def test_config_expanduser(tmp_path):
home_path = tmp_path / ".eneel"
home_path.mkdir()
test_config_yml_path = home_path / "connections.yml"
test_config_yml_path.write_text(
"""# Connection details to an Postgres database
postgres1:
type: postgres
read_only: False # Will disable SQL and DML modifications
outputs:
dev:
host: localhost
port: 5432
user: user_name
password: secret_password
database: my_db
limit_rows: 100 # Will limit all exports to 100 rows
prod:
host: prodserver_host
port: 5432
user: user_name
password: secret_password
database: my_db
target: dev # The profile that will be used when running the load
# Connection details to an SQL Server database
sqlserver1:
type: sqlserver
outputs:
dev:
driver: ODBC Driver 17 for SQL Server # Your ODBC driver
host: localhost
port: 1433
trusted_connection: True # Use logged in user for credentials
as_columnstore: True # Create tables as Clustered Columnstore Index (SQL Server only)
database: my_db
limit_rows: 100
prod:
driver: ODBC Driver 17 for SQL Server
host: prodserver_host
port: 1433
user: user_name
password: secret_password
database: my_db
target: dev # The profile that will be used when running the load
# Connection details to an Oracle database
oracle1:
type: oracle
outputs:
dev:
host: localhost
port: 1521
user: user_name
password: secret_password
database: my_db
limit_rows: 100 # Will limit all exports to 100 rows
prod:
host: prodserver_host
port: 1521
user: user_name
password: secret_password
database: my_db
target: dev # The profile that will be used when running the load"""
)
yield str(tmp_path)
def substitute_os_path_expanduser(test_config_expanduser):
return test_config_expanduser
class TestGetProject:
def test_get_project_from_path(self, test_project_yml):
project_config = get_project(test_project_yml)
assert type(project_config) == dict
def test_get_project(self, test_project_yml):
project_yml = test_project_yml[:-4]
project_config = get_project(project_yml)
assert type(project_config) == dict
class TestConnectionFromConfig:
def test_connection_from_config_postgres(self):
credentials = {
"host": os.getenv("POSTGRES_TEST_HOST"),
"port": os.getenv("POSTGRES_TEST_PORT"),
"user": os.getenv("POSTGRES_TEST_USER"),
"password": os.getenv("POSTGRES_TEST_PASS"),
"database": os.getenv("POSTGRES_TEST_DBNAME"),
}
connection_info = {
"name": "postgres1",
"type": "postgres",
"read_only": False,
"target": "prod",
"credentials": credentials,
}
connection = connection_from_config(connection_info)
assert connection._dialect == "postgres"
class TestConnections:
@pytest.mark.skip(reason="must get monkeypatch and fixture working")
def test_Connections(self, monkeypatch):
monkeypatch.setattr(os.path, "expanduser", substitute_os_path_expanduser)
connections = Connections()
assert connections.connections["postgres1"]["type"] == "postgres"
@pytest.mark.skip(reason="must get monkeypatch and fixture working")
def test_Connections_target(self, monkeypatch):
monkeypatch.setattr(os.path, "expanduser", substitute_os_path_expanduser)
connections = Connections(target="prod")
assert connections.connections["postgres1"]["type"] == "postgres"
def test_Connections_from_path(self, test_config_yml):
connections_path = os.path.abspath(test_config_yml)
connections = Connections(connections_path=connections_path)
assert connections.connections["postgres1"]["type"] == "postgres"
def test_Connections_from_path_target(self, test_config_yml):
connections_path = os.path.abspath(test_config_yml)
connections = Connections(connections_path=connections_path, target="prod")
assert connections.connections["postgres1"]["type"] == "postgres"
def test_Project(test_project_yml, test_config_yml):
connections = Connections(connections_path=test_config_yml)
project = Project(test_project_yml, connections.connections)
assert project.source_name == "postgres1"