-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_cli_usage.py
More file actions
365 lines (330 loc) · 13.6 KB
/
test_cli_usage.py
File metadata and controls
365 lines (330 loc) · 13.6 KB
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
"""Tests for Ralph cli usage strings."""
import logging
from click.testing import CliRunner
from ralph.cli import cli
test_logger = logging.getLogger("ralph")
def test_cli_auth_command_usage():
"""Test ralph auth command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["auth", "--help"])
assert result.exit_code == 0
assert all(
text in result.output
for text in [
"Options:",
"-u, --username TEXT",
"-p, --password TEXT",
"-s, --scope TEXT",
"-M, --agent-ifi-mbox TEXT",
"-S, --agent-ifi-mbox-sha1sum TEXT",
"-O, --agent-ifi-openid TEXT",
"-A, --agent-ifi-account TEXT",
"-N, --agent-name TEXT",
"-w, --write-to-disk",
]
)
result = runner.invoke(cli, ["auth"])
assert result.exit_code > 0
assert "Error: Missing option '-u' / '--username'." in result.output
def test_cli_extract_command_usage():
"""Test ralph extract command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["extract", "--help"])
assert result.exit_code == 0
assert (
"Options:\n"
" -p, --parser [gelf|es] Container format parser used to extract events\n"
" [required]\n"
) in result.output
result = runner.invoke(cli, ["extract"])
assert result.exit_code > 0
assert (
"Error: Missing option '-p' / '--parser'. Choose from:\n\tgelf,\n\tes\n"
) in result.output
def test_cli_validate_command_usage():
"""Test ralph validate command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["validate", "--help"])
assert result.exit_code == 0
assert (
"Options:\n"
" -f, --format [edx|xapi|xapi.profile]\n"
" Input data format to validate [required]\n"
" -I, --ignore-errors Continue validating regardless of raised\n"
" errors\n"
" -F, --fail-on-unknown Stop validating at first unknown record\n"
) in result.output
result = runner.invoke(cli, ["validate"])
assert result.exit_code > 0
assert (
"Error: Missing option '-f' / '--format'. Choose from:\n"
"\tedx,\n"
"\txapi,\n"
"\txapi.profile\n"
) in result.output
def test_cli_convert_command_usage():
"""Test ralph convert command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["convert", "--help"])
assert result.exit_code == 0
assert (
"Options:\n"
" From edX to xAPI converter options: \n"
" -u, --uuid-namespace TEXT The UUID namespace to use for the `ID` "
"field\n"
" generation\n"
" -p, --platform-url TEXT The `actor.account.homePage` to use in"
" the\n"
" xAPI statements [required]\n"
" -f, --from [edx] Input events format to convert [required]\n"
" -t, --to [xapi] Output events format [required]\n"
" -I, --ignore-errors Continue writing regardless of raised "
"errors\n"
" -F, --fail-on-unknown Stop converting at first unknown event\n"
) in result.output
result = runner.invoke(cli, ["convert"])
assert result.exit_code > 0
assert "Error: Missing option '-p' / '--platform-url'" in result.output
def test_cli_read_command_usage():
"""Test ralph read command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["read", "--help"])
assert result.exit_code == 0
assert (
"Options:\n"
" -b, --backend [es|mongo|clickhouse|lrs|ldp|fs|swift|s3|ws]\n"
" Backend [required]\n"
" ws backend: \n"
" --ws-uri TEXT\n"
" s3 backend: \n"
" --s3-endpoint-url TEXT\n"
" --s3-bucket-name TEXT\n"
" --s3-default-region TEXT\n"
" --s3-session-token TEXT\n"
" --s3-secret-access-key TEXT\n"
" --s3-access-key-id TEXT\n"
" swift backend: \n"
" --swift-os-identity-api-version TEXT\n"
" --swift-os-auth-url TEXT\n"
" --swift-os-project-domain-name TEXT\n"
" --swift-os-user-domain-name TEXT\n"
" --swift-os-storage-url TEXT\n"
" --swift-os-region-name TEXT\n"
" --swift-os-password TEXT\n"
" --swift-os-username TEXT\n"
" --swift-os-tenant-name TEXT\n"
" --swift-os-tenant-id TEXT\n"
" fs backend: \n"
" --fs-path TEXT\n"
" ldp backend: \n"
" --ldp-stream-id TEXT\n"
" --ldp-service-name TEXT\n"
" --ldp-consumer-key TEXT\n"
" --ldp-application-secret TEXT\n"
" --ldp-application-key TEXT\n"
" --ldp-endpoint TEXT\n"
" lrs backend: \n"
" --lrs-statements-endpoint TEXT\n"
" --lrs-status-endpoint TEXT\n"
" --lrs-headers KEY=VALUE,KEY=VALUE\n"
" --lrs-password TEXT\n"
" --lrs-username TEXT\n"
" --lrs-base-url TEXT\n"
" clickhouse backend: \n"
" --clickhouse-client-options KEY=VALUE,KEY=VALUE\n"
" --clickhouse-password TEXT\n"
" --clickhouse-username TEXT\n"
" --clickhouse-event-table-name TEXT\n"
" --clickhouse-database TEXT\n"
" --clickhouse-port INTEGER\n"
" --clickhouse-host TEXT\n"
" mongo backend: \n"
" --mongo-client-options KEY=VALUE,KEY=VALUE\n"
" --mongo-collection TEXT\n"
" --mongo-database TEXT\n"
" --mongo-connection-uri TEXT\n"
" es backend: \n"
" --es-op-type TEXT\n"
" --es-client-options KEY=VALUE,KEY=VALUE\n"
" --es-index TEXT\n"
" --es-hosts VALUE1,VALUE2,VALUE3\n"
" -c, --chunk-size INTEGER Get events by chunks of size #\n"
" -t, --target TEXT Endpoint from which to read events (e.g.\n"
" `/statements`)\n"
' -q, --query \'{"KEY": "VALUE", "KEY": "VALUE"}\'\n'
" Query object as a JSON string (database "
"and\n"
" HTTP backends ONLY)\n"
) in result.output
logging.warning(result.output)
result = runner.invoke(cli, ["read"])
assert result.exit_code > 0
assert (
"Error: Missing option '-b' / '--backend'. "
"Choose from:\n\tes,\n\tmongo,\n\tclickhouse,\n\tlrs,\n\tldp,\n\tfs,\n\tswift,"
"\n\ts3,\n\tws\n"
) in result.output
def test_cli_list_command_usage():
"""Test ralph list command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["list", "--help"])
assert result.exit_code == 0
assert (
"Options:\n"
" -b, --backend [ldp|fs|swift|s3]\n"
" Backend [required]\n"
" s3 backend: \n"
" --s3-endpoint-url TEXT\n"
" --s3-bucket-name TEXT\n"
" --s3-default-region TEXT\n"
" --s3-session-token TEXT\n"
" --s3-secret-access-key TEXT\n"
" --s3-access-key-id TEXT\n"
" swift backend: \n"
" --swift-os-identity-api-version TEXT\n"
" --swift-os-auth-url TEXT\n"
" --swift-os-project-domain-name TEXT\n"
" --swift-os-user-domain-name TEXT\n"
" --swift-os-storage-url TEXT\n"
" --swift-os-region-name TEXT\n"
" --swift-os-password TEXT\n"
" --swift-os-username TEXT\n"
" --swift-os-tenant-name TEXT\n"
" --swift-os-tenant-id TEXT\n"
" fs backend: \n"
" --fs-path TEXT\n"
" ldp backend: \n"
" --ldp-stream-id TEXT\n"
" --ldp-service-name TEXT\n"
" --ldp-consumer-key TEXT\n"
" --ldp-application-secret TEXT\n"
" --ldp-application-key TEXT\n"
" --ldp-endpoint TEXT\n"
" -n, --new / -a, --all List not fetched (or all) archives\n"
" -D, --details / -I, --ids Get archives detailed output (JSON)\n"
) in result.output
result = runner.invoke(cli, ["list"])
assert result.exit_code > 0
assert (
"Error: Missing option '-b' / '--backend'. Choose from:\n\tldp,\n\tfs,\n\t"
"swift,\n\ts3\n"
) in result.output
def test_cli_write_command_usage():
"""Test ralph write command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["write", "--help"])
assert result.exit_code == 0
expected_output = (
"Usage: ralph write [OPTIONS] [ARCHIVE]\n"
"\n"
" Write an archive to a configured backend.\n"
"\n"
"Options:\n"
" -b, --backend [es|mongo|clickhouse|ldp|fs|swift|s3|lrs]\n"
" Backend [required]\n"
" lrs backend: \n"
" --lrs-statements-endpoint TEXT\n"
" --lrs-status-endpoint TEXT\n"
" --lrs-headers KEY=VALUE,KEY=VALUE\n"
" --lrs-password TEXT\n"
" --lrs-username TEXT\n"
" --lrs-base-url TEXT\n"
" s3 backend: \n"
" --s3-endpoint-url TEXT\n"
" --s3-bucket-name TEXT\n"
" --s3-default-region TEXT\n"
" --s3-session-token TEXT\n"
" --s3-secret-access-key TEXT\n"
" --s3-access-key-id TEXT\n"
" swift backend: \n"
" --swift-os-identity-api-version TEXT\n"
" --swift-os-auth-url TEXT\n"
" --swift-os-project-domain-name TEXT\n"
" --swift-os-user-domain-name TEXT\n"
" --swift-os-storage-url TEXT\n"
" --swift-os-region-name TEXT\n"
" --swift-os-password TEXT\n"
" --swift-os-username TEXT\n"
" --swift-os-tenant-name TEXT\n"
" --swift-os-tenant-id TEXT\n"
" fs backend: \n"
" --fs-path TEXT\n"
" ldp backend: \n"
" --ldp-stream-id TEXT\n"
" --ldp-service-name TEXT\n"
" --ldp-consumer-key TEXT\n"
" --ldp-application-secret TEXT\n"
" --ldp-application-key TEXT\n"
" --ldp-endpoint TEXT\n"
" clickhouse backend: \n"
" --clickhouse-client-options KEY=VALUE,KEY=VALUE\n"
" --clickhouse-password TEXT\n"
" --clickhouse-username TEXT\n"
" --clickhouse-event-table-name TEXT\n"
" --clickhouse-database TEXT\n"
" --clickhouse-port INTEGER\n"
" --clickhouse-host TEXT\n"
" mongo backend: \n"
" --mongo-client-options KEY=VALUE,KEY=VALUE\n"
" --mongo-collection TEXT\n"
" --mongo-database TEXT\n"
" --mongo-connection-uri TEXT\n"
" es backend: \n"
" --es-op-type TEXT\n"
" --es-client-options KEY=VALUE,KEY=VALUE\n"
" --es-index TEXT\n"
" --es-hosts VALUE1,VALUE2,VALUE3\n"
" -c, --chunk-size INTEGER Get events by chunks of size #\n"
" -f, --force Overwrite existing archives or records\n"
" -I, --ignore-errors Continue writing regardless of raised "
"errors\n"
" -s, --simultaneous With HTTP backend, POST all chunks\n"
" simultaneously (instead of sequentially)\n"
" -m, --max-num-simultaneous INTEGER\n"
" The maximum number of chunks to send at "
"once,\n"
" when using `--simultaneous`. Use `-1` to "
"not\n"
" set a limit.\n"
" -t, --target TEXT Endpoint in which to write events (e.g.\n"
" `statements`)\n"
" --help Show this message and exit.\n"
)
assert expected_output in result.output
result = runner.invoke(cli, ["write"])
assert result.exit_code > 0
assert (
"Missing option '-b' / '--backend'. Choose from:\n\tes,\n\tmongo,"
"\n\tclickhouse,\n\tldp,\n\tfs,\n\tswift,\n\ts3,\n\tlrs\n"
) in result.output
def test_cli_runserver_command_usage():
"""Test ralph runserver command usage."""
runner = CliRunner()
result = runner.invoke(cli, ["runserver", "--help"])
expected_output = (
"Options:\n"
" -b, --backend [es|mongo|clickhouse]\n"
" Backend [required]\n"
" clickhouse backend: \n"
" --clickhouse-client-options KEY=VALUE,KEY=VALUE\n"
" --clickhouse-password TEXT\n"
" --clickhouse-username TEXT\n"
" --clickhouse-event-table-name TEXT\n"
" --clickhouse-database TEXT\n"
" --clickhouse-port INTEGER\n"
" --clickhouse-host TEXT\n"
" mongo backend: \n"
" --mongo-client-options KEY=VALUE,KEY=VALUE\n"
" --mongo-collection TEXT\n"
" --mongo-database TEXT\n"
" --mongo-connection-uri TEXT\n"
" es backend: \n"
" --es-op-type TEXT\n"
" --es-client-options KEY=VALUE,KEY=VALUE\n"
" --es-index TEXT\n"
" --es-hosts VALUE1,VALUE2,VALUE3\n"
" -h, --host TEXT LRS server host name\n"
" -p, --port INTEGER LRS server port\n"
)
assert result.exit_code == 0
assert expected_output in result.output