forked from meltano/meltano
/
test_install.py
372 lines (312 loc) · 12.4 KB
/
test_install.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
from __future__ import annotations
import os
import shutil
import mock
import pytest
from asserts import assert_cli_runner
from meltano.cli import cli
from meltano.core.plugin import PluginType
from meltano.core.project_add_service import PluginAlreadyAddedException
class TestCliInstall:
@pytest.fixture(scope="class")
def tap_gitlab(self, project_add_service):
try:
return project_add_service.add(PluginType.EXTRACTORS, "tap-gitlab")
except PluginAlreadyAddedException as err:
return err.plugin
@pytest.mark.order(0)
def test_install(self, project, tap, tap_gitlab, target, dbt, cli_runner):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
result = cli_runner.invoke(cli, ["install"])
assert_cli_runner(result)
install_plugin_mock.assert_called_once_with(
project,
[tap, tap_gitlab, target, dbt],
parallelism=None,
clean=False,
force=False,
)
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
result = cli_runner.invoke(cli, ["install", "-"])
assert_cli_runner(result)
install_plugin_mock.assert_called_once_with(
project,
[tap, tap_gitlab, target, dbt],
parallelism=None,
clean=False,
force=False,
)
@pytest.mark.usefixtures("dbt")
def test_install_type(
self,
project,
tap,
tap_gitlab,
target,
mapper,
cli_runner,
):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock_e:
install_plugin_mock_e.return_value = True
result = cli_runner.invoke(cli, ["install", "extractors"])
assert_cli_runner(result)
install_plugin_mock_e.assert_called_once_with(
project,
[tap, tap_gitlab],
parallelism=None,
clean=False,
force=False,
)
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock_l:
install_plugin_mock_l.return_value = True
result = cli_runner.invoke(cli, ["install", "loaders"])
assert_cli_runner(result)
install_plugin_mock_l.assert_called_once_with(
project,
[target],
parallelism=None,
clean=False,
force=False,
)
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock_m:
install_plugin_mock_m.return_value = True
result = cli_runner.invoke(cli, ["install", "mappers"])
assert_cli_runner(result)
assert install_plugin_mock_m.call_count == 1
seen_plugins = install_plugin_mock_m.call_args[0][1]
assert len(seen_plugins) == 3
assert mapper in seen_plugins
mappings_seen = 0
for found in seen_plugins:
assert found == mapper
if found.extra_config.get("_mapping"):
mappings_seen += 1
assert mappings_seen == 2
@pytest.mark.usefixtures("tap_gitlab", "dbt")
def test_install_type_name(
self,
project,
tap,
target,
mapper,
cli_runner,
):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock_e:
install_plugin_mock_e.return_value = True
result = cli_runner.invoke(cli, ["install", "extractor", tap.name])
assert_cli_runner(result)
install_plugin_mock_e.assert_called_once_with(
project,
[tap],
parallelism=None,
clean=False,
force=False,
)
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock_l:
install_plugin_mock_l.return_value = True
result = cli_runner.invoke(cli, ["install", "loader", target.name])
assert_cli_runner(result)
install_plugin_mock_l.assert_called_once_with(
project,
[target],
parallelism=None,
clean=False,
force=False,
)
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock_m:
install_plugin_mock_m.return_value = True
result = cli_runner.invoke(cli, ["install", "mapper", mapper.name])
assert_cli_runner(result)
assert install_plugin_mock_m.call_count == 1
seen_plugins = install_plugin_mock_m.call_args[0][1]
assert len(seen_plugins) == 3
assert mapper in seen_plugins
mappings_seen = 0
for found in seen_plugins:
assert found == mapper
if found.extra_config.get("_mapping"):
mappings_seen += 1
assert mappings_seen == 2
@pytest.mark.usefixtures("target", "dbt")
def test_install_multiple(self, project, tap, tap_gitlab, cli_runner):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
result = cli_runner.invoke(
cli,
["install", "extractors", tap.name, tap_gitlab.name],
)
assert_cli_runner(result)
install_plugin_mock.assert_called_once_with(
project,
[tap, tap_gitlab],
parallelism=None,
clean=False,
force=False,
)
@pytest.mark.usefixtures("dbt")
def test_install_multiple_any_type(self, project, tap, target, dbt, cli_runner):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
result = cli_runner.invoke(
cli,
["install", "-", tap.name, target.name, dbt.name],
)
assert_cli_runner(result)
install_plugin_mock.assert_called_once_with(
project,
[tap, target, dbt],
parallelism=None,
clean=False,
force=False,
)
def test_install_parallel(
self,
project,
tap,
tap_gitlab,
target,
dbt,
mapper,
cli_runner,
):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
result = cli_runner.invoke(cli, ["install", "--parallelism=10"])
assert_cli_runner(result)
assert install_plugin_mock.call_count == 1
commands = [
args
for _, args, kwargs in install_plugin_mock.mock_calls
if args and isinstance(args, tuple)
]
kwargs = install_plugin_mock.mock_calls[0][2]
assert len(commands) == 1
assert commands[0][0] == project
for cli_arg in (dbt, tap_gitlab, target, tap, mapper):
assert cli_arg in commands[0][1]
assert kwargs["parallelism"] == 10
assert not kwargs["clean"]
mappers = [m for m in commands[0][1] if m == mapper]
assert len(mappers) == 3
def test_clean_install(
self,
project,
tap,
tap_gitlab,
target,
dbt,
mapper,
cli_runner,
):
with mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
result = cli_runner.invoke(cli, ["install", "--clean"])
assert_cli_runner(result)
assert install_plugin_mock.call_count == 1
commands = [
args
for _, args, kwargs in install_plugin_mock.mock_calls
if args and isinstance(args, tuple)
]
kwargs = install_plugin_mock.mock_calls[0][2]
assert len(commands) == 1
assert commands[0][0] == project
for cli_arg in (dbt, tap_gitlab, target, tap, mapper):
assert cli_arg in commands[0][1]
assert not kwargs["parallelism"]
assert kwargs["clean"]
mappers = [m for m in commands[0][1] if m == mapper]
assert len(mappers) == 3
@pytest.mark.usefixtures("tap_gitlab", "target")
def test_install_schedule(
self,
project,
tap_gitlab,
target,
dbt,
mapper,
cli_runner,
schedule_service,
job_schedule,
task_sets_service,
):
with mock.patch(
"meltano.cli.install.ScheduleService",
return_value=schedule_service,
), mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
schedule_service.task_sets_service = task_sets_service
from meltano.core.task_sets import TaskSets
mapping = mapper.extra_config.get("_mappings")[0].get("name")
task_sets_service.add(
TaskSets(
job_schedule.job,
[tap_gitlab.name, mapping, target.name, dbt.name],
),
)
result = cli_runner.invoke(
cli,
["install", "--schedule", job_schedule.name],
)
assert_cli_runner(result)
install_plugin_mock.assert_called_once()
assert install_plugin_mock.mock_calls[0].args[0] == project
plugins_installed = [
plugin.name for plugin in install_plugin_mock.mock_calls[0].args[1]
]
plugins_expected = [tap_gitlab.name, mapper.name, target.name, dbt.name]
assert sorted(plugins_installed) == sorted(plugins_expected)
assert install_plugin_mock.mock_calls[0].kwargs["parallelism"] is None
assert install_plugin_mock.mock_calls[0].kwargs["clean"] is False
assert install_plugin_mock.mock_calls[0].kwargs["force"] is False
def test_install_schedule_elt(
self,
project,
tap,
target,
cli_runner,
schedule_service,
elt_schedule,
task_sets_service,
):
with mock.patch(
"meltano.cli.install.ScheduleService",
return_value=schedule_service,
), mock.patch("meltano.cli.install.install_plugins") as install_plugin_mock:
install_plugin_mock.return_value = True
schedule_service.task_sets_service = task_sets_service
result = cli_runner.invoke(
cli,
["install", "--schedule", elt_schedule.name],
)
assert_cli_runner(result)
install_plugin_mock.assert_called_once()
assert install_plugin_mock.mock_calls[0].args[0] == project
plugins_installed = [
plugin.name for plugin in install_plugin_mock.mock_calls[0].args[1]
]
plugins_expected = [
tap.name,
target.name,
]
assert sorted(plugins_installed) == sorted(plugins_expected)
assert install_plugin_mock.mock_calls[0].kwargs["parallelism"] is None
assert install_plugin_mock.mock_calls[0].kwargs["clean"] is False
assert install_plugin_mock.mock_calls[0].kwargs["force"] is False
# un_engine_uri forces us to create a new project, we must do this before the
# project fixture creates the project see
# https://github.com/meltano/meltano/pull/6407#issuecomment-1200516464
# For more details
@pytest.mark.order(-1)
@pytest.mark.usefixtures("un_engine_uri", "project_function")
def test_new_folder_should_autocreate_on_install(cli_runner):
"""Be sure .meltano auto creates a db on install by default.
We had a case https://github.com/meltano/meltano/issues/6383
that caused the meltano db to not be recreated.
"""
shutil.rmtree(".meltano")
result = cli_runner.invoke(cli, ["install"])
assert result
assert os.path.exists(".meltano/meltano.db")