Skip to content

Commit 1c6e4d7

Browse files
author
Ilyas Gasanov
committed
split methods
1 parent 17774cb commit 1c6e4d7

File tree

13 files changed

+155
-303
lines changed

13 files changed

+155
-303
lines changed

tests/test_integration/test_run_transfer/test_clickhouse.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from tests.mocks import MockUser
1414
from tests.test_unit.utils import create_transfer
1515
from tests.utils import (
16-
prepare_dataframes_for_comparison,
16+
cast_dataframe_types,
1717
run_transfer_and_verify,
1818
split_df,
1919
)
@@ -131,7 +131,7 @@ async def test_run_transfer_postgres_to_clickhouse_with_full_strategy(
131131
)
132132
df = reader.run()
133133

134-
df, init_df = prepare_dataframes_for_comparison(df, init_df)
134+
df, init_df = cast_dataframe_types(df, init_df)
135135
assert df.sort("ID").collect() == init_df.sort("ID").collect()
136136

137137

@@ -169,7 +169,7 @@ async def test_run_transfer_postgres_to_clickhouse_mixed_naming_with_full_strate
169169
assert df.columns != init_df_with_mixed_column_naming.columns
170170
assert df.columns == [column.lower() for column in init_df_with_mixed_column_naming.columns]
171171

172-
df, init_df_with_mixed_column_naming = prepare_dataframes_for_comparison(df, init_df_with_mixed_column_naming)
172+
df, init_df_with_mixed_column_naming = cast_dataframe_types(df, init_df_with_mixed_column_naming)
173173
assert df.sort("ID").collect() == init_df_with_mixed_column_naming.sort("ID").collect()
174174

175175

@@ -205,14 +205,14 @@ async def test_run_transfer_postgres_to_clickhouse_with_incremental_strategy(
205205
)
206206
df = reader.run()
207207

208-
df, first_transfer_df = prepare_dataframes_for_comparison(df, first_transfer_df)
208+
df, first_transfer_df = cast_dataframe_types(df, first_transfer_df)
209209
assert df.sort("ID").collect() == first_transfer_df.sort("ID").collect()
210210

211211
fill_with_data(second_transfer_df)
212212
await run_transfer_and_verify(client, group_owner, postgres_to_clickhouse.id)
213213

214214
df_with_increment = reader.run()
215-
df_with_increment, init_df = prepare_dataframes_for_comparison(df_with_increment, init_df)
215+
df_with_increment, init_df = cast_dataframe_types(df_with_increment, init_df)
216216
assert df_with_increment.sort("ID").collect() == init_df.sort("ID").collect()
217217

218218

@@ -258,7 +258,7 @@ async def test_run_transfer_clickhouse_to_postgres_with_full_strategy(
258258
)
259259
df = reader.run()
260260

261-
df, init_df = prepare_dataframes_for_comparison(df, init_df)
261+
df, init_df = cast_dataframe_types(df, init_df)
262262
assert df.sort("ID").collect() == init_df.sort("ID").collect()
263263

264264

@@ -296,7 +296,7 @@ async def test_run_transfer_clickhouse_to_postgres_mixed_naming_with_full_strate
296296
assert df.columns != init_df_with_mixed_column_naming.columns
297297
assert df.columns == [column.lower() for column in init_df_with_mixed_column_naming.columns]
298298

299-
df, init_df_with_mixed_column_naming = prepare_dataframes_for_comparison(df, init_df_with_mixed_column_naming)
299+
df, init_df_with_mixed_column_naming = cast_dataframe_types(df, init_df_with_mixed_column_naming)
300300
assert df.sort("ID").collect() == init_df_with_mixed_column_naming.sort("ID").collect()
301301

302302

@@ -332,12 +332,12 @@ async def test_run_transfer_clickhouse_to_postgres_with_incremental_strategy(
332332
)
333333
df = reader.run()
334334

335-
df, first_transfer_df = prepare_dataframes_for_comparison(df, first_transfer_df)
335+
df, first_transfer_df = cast_dataframe_types(df, first_transfer_df)
336336
assert df.sort("ID").collect() == first_transfer_df.sort("ID").collect()
337337

338338
fill_with_data(second_transfer_df)
339339
await run_transfer_and_verify(client, group_owner, clickhouse_to_postgres.id)
340340

341341
df_with_increment = reader.run()
342-
df_with_increment, init_df = prepare_dataframes_for_comparison(df_with_increment, init_df)
342+
df_with_increment, init_df = cast_dataframe_types(df_with_increment, init_df)
343343
assert df_with_increment.sort("ID").collect() == init_df.sort("ID").collect()

tests/test_integration/test_run_transfer/test_ftp.py

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
from tests.test_unit.utils import create_transfer
1919
from tests.utils import (
2020
add_increment_to_files_and_upload,
21-
prepare_dataframes_for_comparison,
21+
cast_dataframe_types,
2222
run_transfer_and_verify,
2323
split_df,
24+
truncate_datetime_to_seconds,
2425
verify_file_name_template,
2526
)
2627

@@ -181,12 +182,10 @@ async def test_run_transfer_ftp_to_postgres_with_full_strategy(
181182
)
182183
df = reader.run()
183184

184-
df, init_df = prepare_dataframes_for_comparison(
185-
df,
186-
init_df,
187-
file_format=file_format,
188-
transfer_direction="file_to_db",
189-
)
185+
if file_format == "excel":
186+
df, init_df = truncate_datetime_to_seconds(df, init_df, transfer_direction="file_to_db")
187+
188+
df, init_df = cast_dataframe_types(df, init_df)
190189
assert df.sort("id").collect() == init_df.sort("id").collect()
191190

192191

@@ -225,12 +224,7 @@ async def test_run_transfer_ftp_to_postgres_with_incremental_strategy(
225224
)
226225
df = reader.run()
227226

228-
df, init_df = prepare_dataframes_for_comparison(
229-
df,
230-
init_df,
231-
file_format=file_format,
232-
transfer_direction="file_to_db",
233-
)
227+
df, init_df = cast_dataframe_types(df, init_df)
234228
assert df.sort("id").collect() == init_df.sort("id").collect()
235229

236230
add_increment_to_files_and_upload(
@@ -242,12 +236,7 @@ async def test_run_transfer_ftp_to_postgres_with_incremental_strategy(
242236
await run_transfer_and_verify(client, group_owner, ftp_to_postgres.id)
243237

244238
df_with_increment = reader.run()
245-
df_with_increment, init_df = prepare_dataframes_for_comparison(
246-
df_with_increment,
247-
init_df,
248-
file_format=file_format,
249-
transfer_direction="file_to_db",
250-
)
239+
df_with_increment, init_df = cast_dataframe_types(df_with_increment, init_df)
251240
assert df_with_increment.sort("id").collect() == init_df.union(init_df).sort("id").collect()
252241

253242

@@ -337,12 +326,10 @@ async def test_run_transfer_postgres_to_ftp_with_full_strategy(
337326
)
338327
df = reader.run()
339328

340-
df, init_df = prepare_dataframes_for_comparison(
341-
df,
342-
init_df,
343-
file_format=format_name,
344-
transfer_direction="db_to_file",
345-
)
329+
if format_name == "excel":
330+
df, init_df = truncate_datetime_to_seconds(df, init_df, transfer_direction="db_to_file")
331+
332+
df, init_df = cast_dataframe_types(df, init_df)
346333
assert df.sort("id").collect() == init_df.sort("id").collect()
347334

348335

@@ -399,12 +386,7 @@ async def test_run_transfer_postgres_to_ftp_with_incremental_strategy(
399386
)
400387
df = reader.run()
401388

402-
df, first_transfer_df = prepare_dataframes_for_comparison(
403-
df,
404-
first_transfer_df,
405-
file_format=format_name,
406-
transfer_direction="db_to_file",
407-
)
389+
df, first_transfer_df = cast_dataframe_types(df, first_transfer_df)
408390
assert df.sort("id").collect() == first_transfer_df.sort("id").collect()
409391

410392
fill_with_data(second_transfer_df)
@@ -414,10 +396,5 @@ async def test_run_transfer_postgres_to_ftp_with_incremental_strategy(
414396
verify_file_name_template(os.listdir(tmp_path), expected_extension)
415397

416398
df_with_increment = reader.run()
417-
df_with_increment, second_transfer_df = prepare_dataframes_for_comparison(
418-
df_with_increment,
419-
second_transfer_df,
420-
file_format=format_name,
421-
transfer_direction="db_to_file",
422-
)
399+
df_with_increment, second_transfer_df = cast_dataframe_types(df_with_increment, second_transfer_df)
423400
assert df_with_increment.sort("id").collect() == init_df.sort("id").collect()

tests/test_integration/test_run_transfer/test_ftps.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from tests.test_unit.utils import create_transfer
1919
from tests.utils import (
2020
add_increment_to_files_and_upload,
21-
prepare_dataframes_for_comparison,
21+
cast_dataframe_types,
2222
run_transfer_and_verify,
2323
split_df,
2424
verify_file_name_template,
@@ -145,12 +145,7 @@ async def test_run_transfer_ftps_to_postgres_with_full_strategy(
145145
)
146146
df = reader.run()
147147

148-
df, init_df = prepare_dataframes_for_comparison(
149-
df,
150-
init_df,
151-
file_format=file_format,
152-
transfer_direction="file_to_db",
153-
)
148+
df, init_df = cast_dataframe_types(df, init_df)
154149
assert df.sort("id").collect() == init_df.sort("id").collect()
155150

156151

@@ -189,12 +184,7 @@ async def test_run_transfer_ftps_to_postgres_with_incremental_strategy(
189184
)
190185
df = reader.run()
191186

192-
df, init_df = prepare_dataframes_for_comparison(
193-
df,
194-
init_df,
195-
file_format=file_format,
196-
transfer_direction="file_to_db",
197-
)
187+
df, init_df = cast_dataframe_types(df, init_df)
198188
assert df.sort("id").collect() == init_df.sort("id").collect()
199189

200190
add_increment_to_files_and_upload(
@@ -206,12 +196,7 @@ async def test_run_transfer_ftps_to_postgres_with_incremental_strategy(
206196
await run_transfer_and_verify(client, group_owner, ftps_to_postgres.id)
207197

208198
df_with_increment = reader.run()
209-
df_with_increment, init_df = prepare_dataframes_for_comparison(
210-
df_with_increment,
211-
init_df,
212-
file_format=file_format,
213-
transfer_direction="file_to_db",
214-
)
199+
df_with_increment, init_df = cast_dataframe_types(df_with_increment, init_df)
215200
assert df_with_increment.sort("id").collect() == init_df.union(init_df).sort("id").collect()
216201

217202

@@ -266,12 +251,7 @@ async def test_run_transfer_postgres_to_ftps_with_full_strategy(
266251
)
267252
df = reader.run()
268253

269-
df, init_df = prepare_dataframes_for_comparison(
270-
df,
271-
init_df,
272-
file_format=format_name,
273-
transfer_direction="db_to_file",
274-
)
254+
df, init_df = cast_dataframe_types(df, init_df)
275255
assert df.sort("id").collect() == init_df.sort("id").collect()
276256

277257

@@ -328,12 +308,7 @@ async def test_run_transfer_postgres_to_ftps_with_incremental_strategy(
328308
)
329309
df = reader.run()
330310

331-
df, first_transfer_df = prepare_dataframes_for_comparison(
332-
df,
333-
first_transfer_df,
334-
file_format=format_name,
335-
transfer_direction="db_to_file",
336-
)
311+
df, first_transfer_df = cast_dataframe_types(df, first_transfer_df)
337312
assert df.sort("id").collect() == first_transfer_df.sort("id").collect()
338313

339314
fill_with_data(second_transfer_df)
@@ -343,10 +318,5 @@ async def test_run_transfer_postgres_to_ftps_with_incremental_strategy(
343318
verify_file_name_template(os.listdir(tmp_path), expected_extension)
344319

345320
df_with_increment = reader.run()
346-
df_with_increment, second_transfer_df = prepare_dataframes_for_comparison(
347-
df_with_increment,
348-
second_transfer_df,
349-
file_format=format_name,
350-
transfer_direction="db_to_file",
351-
)
321+
df, second_transfer_df = cast_dataframe_types(df, second_transfer_df)
352322
assert df_with_increment.sort("id").collect() == init_df.sort("id").collect()

tests/test_integration/test_run_transfer/test_hdfs.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
from tests.mocks import MockUser
1717
from tests.test_unit.utils import create_transfer
1818
from tests.utils import (
19-
prepare_dataframes_for_comparison,
19+
cast_dataframe_types,
2020
run_transfer_and_verify,
2121
split_df,
22+
truncate_datetime_to_seconds,
2223
verify_file_name_template,
2324
)
2425

@@ -169,12 +170,10 @@ async def test_run_transfer_hdfs_to_postgres_with_full_strategy(
169170
)
170171
df = reader.run()
171172

172-
df, init_df = prepare_dataframes_for_comparison(
173-
df,
174-
init_df,
175-
file_format=file_format,
176-
transfer_direction="file_to_db",
177-
)
173+
if file_format == "excel":
174+
truncate_datetime_to_seconds(df, init_df, transfer_direction="file_to_db")
175+
176+
df, init_df = cast_dataframe_types(df, init_df)
178177
assert df.sort("id").collect() == init_df.sort("id").collect()
179178

180179

@@ -259,12 +258,10 @@ async def test_run_transfer_postgres_to_hdfs_with_full_strategy(
259258
)
260259
df = reader.run()
261260

262-
df, init_df = prepare_dataframes_for_comparison(
263-
df,
264-
init_df,
265-
file_format=format_name,
266-
transfer_direction="db_to_file",
267-
)
261+
if format_name == "excel":
262+
truncate_datetime_to_seconds(df, init_df, transfer_direction="db_to_file")
263+
264+
df, init_df = cast_dataframe_types(df, init_df)
268265
assert df.sort("id").collect() == init_df.sort("id").collect()
269266

270267

@@ -315,12 +312,7 @@ async def test_run_transfer_postgres_to_hdfs_with_incremental_strategy(
315312
)
316313
df = reader.run()
317314

318-
df, first_transfer_df = prepare_dataframes_for_comparison(
319-
df,
320-
first_transfer_df,
321-
file_format=format_name,
322-
transfer_direction="db_to_file",
323-
)
315+
df, first_transfer_df = cast_dataframe_types(df, first_transfer_df)
324316
assert df.sort("id").collect() == first_transfer_df.sort("id").collect()
325317

326318
fill_with_data(second_transfer_df)
@@ -330,10 +322,5 @@ async def test_run_transfer_postgres_to_hdfs_with_incremental_strategy(
330322
verify_file_name_template(files, expected_extension)
331323

332324
df_with_increment = reader.run()
333-
df_with_increment, init_df = prepare_dataframes_for_comparison(
334-
df_with_increment,
335-
init_df,
336-
file_format=format_name,
337-
transfer_direction="db_to_file",
338-
)
325+
df_with_increment, init_df = cast_dataframe_types(df_with_increment, init_df)
339326
assert df_with_increment.sort("id").collect() == init_df.sort("id").collect()

0 commit comments

Comments
 (0)