cornflow 1.1.2__py3-none-any.whl → 1.1.5a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cornflow/app.py +8 -0
- cornflow/config.py +43 -5
- cornflow/endpoints/login.py +86 -35
- cornflow/schemas/user.py +18 -2
- cornflow/shared/authentication/auth.py +10 -4
- cornflow/shared/exceptions.py +9 -8
- cornflow/tests/custom_test_case.py +342 -0
- cornflow/tests/unit/test_actions.py +46 -1
- cornflow/tests/unit/test_alarms.py +57 -9
- cornflow/tests/unit/test_apiview.py +45 -1
- cornflow/tests/unit/test_application.py +60 -0
- cornflow/tests/unit/test_cases.py +483 -5
- cornflow/tests/unit/test_cli.py +233 -0
- cornflow/tests/unit/test_commands.py +230 -2
- cornflow/tests/unit/test_dags.py +139 -11
- cornflow/tests/unit/test_data_checks.py +134 -2
- cornflow/tests/unit/test_log_in.py +481 -3
- {cornflow-1.1.2.dist-info → cornflow-1.1.5a1.dist-info}/METADATA +23 -19
- {cornflow-1.1.2.dist-info → cornflow-1.1.5a1.dist-info}/RECORD +22 -21
- {cornflow-1.1.2.dist-info → cornflow-1.1.5a1.dist-info}/WHEEL +1 -1
- {cornflow-1.1.2.dist-info → cornflow-1.1.5a1.dist-info}/entry_points.txt +0 -1
- {cornflow-1.1.2.dist-info → cornflow-1.1.5a1.dist-info}/top_level.txt +0 -0
cornflow/tests/unit/test_cli.py
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
"""
|
2
|
+
Unit tests for the Cornflow CLI commands.
|
3
|
+
|
4
|
+
This module contains tests for the command-line interface functionality, including:
|
5
|
+
|
6
|
+
- Entry point commands and help messages
|
7
|
+
- Actions management commands
|
8
|
+
- Configuration management commands
|
9
|
+
- Roles management commands
|
10
|
+
- Views management commands
|
11
|
+
- Permissions management commands
|
12
|
+
- Service management commands
|
13
|
+
- User management commands
|
14
|
+
|
15
|
+
The tests verify both the command structure and the actual functionality
|
16
|
+
of each command, ensuring proper database operations and state changes.
|
17
|
+
"""
|
18
|
+
|
1
19
|
import configparser
|
2
20
|
import os
|
3
21
|
|
@@ -18,18 +36,61 @@ from cornflow.shared.exceptions import NoPermission, ObjectDoesNotExist
|
|
18
36
|
|
19
37
|
|
20
38
|
class CLITests(TestCase):
|
39
|
+
"""
|
40
|
+
Test suite for Cornflow CLI functionality.
|
41
|
+
|
42
|
+
This class tests all CLI commands and their effects on the system, including:
|
43
|
+
|
44
|
+
- Command help messages and documentation
|
45
|
+
- Actions initialization and management
|
46
|
+
- Configuration variable handling
|
47
|
+
- Role management and initialization
|
48
|
+
- View registration and management
|
49
|
+
- Permission system setup and validation
|
50
|
+
- Service initialization
|
51
|
+
- User creation and management
|
52
|
+
|
53
|
+
Each test method focuses on a specific command or group of related commands,
|
54
|
+
verifying both the command interface and its actual effects on the system.
|
55
|
+
"""
|
56
|
+
|
21
57
|
def setUp(self):
|
58
|
+
"""
|
59
|
+
Set up test environment before each test.
|
60
|
+
|
61
|
+
Creates all database tables required for testing.
|
62
|
+
"""
|
22
63
|
db.create_all()
|
23
64
|
|
24
65
|
def tearDown(self):
|
66
|
+
"""
|
67
|
+
Clean up test environment after each test.
|
68
|
+
|
69
|
+
Removes database session and drops all tables.
|
70
|
+
"""
|
25
71
|
db.session.remove()
|
26
72
|
db.drop_all()
|
27
73
|
|
28
74
|
def create_app(self):
|
75
|
+
"""
|
76
|
+
Create and configure the Flask application for testing.
|
77
|
+
|
78
|
+
:return: The configured Flask application instance
|
79
|
+
:rtype: Flask
|
80
|
+
"""
|
29
81
|
app = create_app("testing")
|
30
82
|
return app
|
31
83
|
|
32
84
|
def test_entry_point(self):
|
85
|
+
"""
|
86
|
+
Test the main CLI entry point and help command.
|
87
|
+
|
88
|
+
Verifies:
|
89
|
+
|
90
|
+
- Command execution success
|
91
|
+
- Presence of all main command groups
|
92
|
+
- Help message content and formatting
|
93
|
+
"""
|
33
94
|
runner = CliRunner()
|
34
95
|
result = runner.invoke(cli, ["--help"])
|
35
96
|
self.assertEqual(result.exit_code, 0)
|
@@ -53,6 +114,15 @@ class CLITests(TestCase):
|
|
53
114
|
self.assertIn("Commands to manage the views", result.output)
|
54
115
|
|
55
116
|
def test_actions_entry_point(self):
|
117
|
+
"""
|
118
|
+
Test the actions command group entry point.
|
119
|
+
|
120
|
+
Verifies:
|
121
|
+
|
122
|
+
- Actions command help message
|
123
|
+
- Presence of init subcommand
|
124
|
+
- Command description accuracy
|
125
|
+
"""
|
56
126
|
runner = CliRunner()
|
57
127
|
result = runner.invoke(cli, ["actions", "--help"])
|
58
128
|
self.assertEqual(result.exit_code, 0)
|
@@ -61,6 +131,15 @@ class CLITests(TestCase):
|
|
61
131
|
self.assertIn("Initialize the actions", result.output)
|
62
132
|
|
63
133
|
def test_actions(self):
|
134
|
+
"""
|
135
|
+
Test the actions initialization command.
|
136
|
+
|
137
|
+
Verifies:
|
138
|
+
|
139
|
+
- Successful action initialization
|
140
|
+
- Correct number of actions created
|
141
|
+
- Database state after initialization
|
142
|
+
"""
|
64
143
|
runner = CliRunner()
|
65
144
|
result = runner.invoke(cli, ["actions", "init", "-v"])
|
66
145
|
self.assertEqual(result.exit_code, 0)
|
@@ -68,6 +147,15 @@ class CLITests(TestCase):
|
|
68
147
|
self.assertEqual(len(actions), 5)
|
69
148
|
|
70
149
|
def test_config_entrypoint(self):
|
150
|
+
"""
|
151
|
+
Test the config command group entry point.
|
152
|
+
|
153
|
+
Verifies:
|
154
|
+
|
155
|
+
- Config command help message
|
156
|
+
- Presence of all config subcommands
|
157
|
+
- Command descriptions
|
158
|
+
"""
|
71
159
|
runner = CliRunner()
|
72
160
|
result = runner.invoke(cli, ["config", "--help"])
|
73
161
|
self.assertEqual(result.exit_code, 0)
|
@@ -80,6 +168,15 @@ class CLITests(TestCase):
|
|
80
168
|
self.assertIn("Save the configuration variables to a file", result.output)
|
81
169
|
|
82
170
|
def test_config_list(self):
|
171
|
+
"""
|
172
|
+
Test the config list command.
|
173
|
+
|
174
|
+
Verifies:
|
175
|
+
|
176
|
+
- Successful listing of configuration variables
|
177
|
+
- Presence of key configuration items
|
178
|
+
- Correct values in testing environment
|
179
|
+
"""
|
83
180
|
runner = CliRunner()
|
84
181
|
result = runner.invoke(cli, ["config", "list"])
|
85
182
|
self.assertEqual(result.exit_code, 0)
|
@@ -87,12 +184,29 @@ class CLITests(TestCase):
|
|
87
184
|
self.assertIn("testing", result.output)
|
88
185
|
|
89
186
|
def test_config_get(self):
|
187
|
+
"""
|
188
|
+
Test the config get command.
|
189
|
+
|
190
|
+
Verifies:
|
191
|
+
|
192
|
+
- Successful retrieval of specific config value
|
193
|
+
- Correct value returned for ENV variable
|
194
|
+
"""
|
90
195
|
runner = CliRunner()
|
91
196
|
result = runner.invoke(cli, ["config", "get", "-k", "ENV"])
|
92
197
|
self.assertEqual(result.exit_code, 0)
|
93
198
|
self.assertIn("testing", result.output)
|
94
199
|
|
95
200
|
def test_config_save(self):
|
201
|
+
"""
|
202
|
+
Test the config save command.
|
203
|
+
|
204
|
+
Verifies:
|
205
|
+
|
206
|
+
- Successful configuration file creation
|
207
|
+
- Correct content in saved file
|
208
|
+
- Proper file cleanup after test
|
209
|
+
"""
|
96
210
|
runner = CliRunner()
|
97
211
|
result = runner.invoke(cli, ["config", "save", "-p", "./"])
|
98
212
|
self.assertEqual(result.exit_code, 0)
|
@@ -104,6 +218,15 @@ class CLITests(TestCase):
|
|
104
218
|
os.remove("config.cfg")
|
105
219
|
|
106
220
|
def test_roles_entrypoint(self):
|
221
|
+
"""
|
222
|
+
Test the roles command group entry point.
|
223
|
+
|
224
|
+
Verifies:
|
225
|
+
|
226
|
+
- Roles command help message
|
227
|
+
- Presence of init subcommand
|
228
|
+
- Command description accuracy
|
229
|
+
"""
|
107
230
|
runner = CliRunner()
|
108
231
|
result = runner.invoke(cli, ["roles", "--help"])
|
109
232
|
self.assertEqual(result.exit_code, 0)
|
@@ -112,6 +235,15 @@ class CLITests(TestCase):
|
|
112
235
|
self.assertIn("Initializes the roles with the default roles", result.output)
|
113
236
|
|
114
237
|
def test_roles_init_command(self):
|
238
|
+
"""
|
239
|
+
Test the roles initialization command.
|
240
|
+
|
241
|
+
Verifies:
|
242
|
+
|
243
|
+
- Successful role initialization
|
244
|
+
- Correct number of default roles created
|
245
|
+
- Database state after initialization
|
246
|
+
"""
|
115
247
|
runner = CliRunner()
|
116
248
|
result = runner.invoke(cli, ["roles", "init", "-v"])
|
117
249
|
self.assertEqual(result.exit_code, 0)
|
@@ -119,6 +251,15 @@ class CLITests(TestCase):
|
|
119
251
|
self.assertEqual(len(roles), 4)
|
120
252
|
|
121
253
|
def test_views_entrypoint(self):
|
254
|
+
"""
|
255
|
+
Test the views command group entry point.
|
256
|
+
|
257
|
+
Verifies:
|
258
|
+
|
259
|
+
- Views command help message
|
260
|
+
- Presence of init subcommand
|
261
|
+
- Command description accuracy
|
262
|
+
"""
|
122
263
|
runner = CliRunner()
|
123
264
|
result = runner.invoke(cli, ["views", "--help"])
|
124
265
|
self.assertEqual(result.exit_code, 0)
|
@@ -127,6 +268,15 @@ class CLITests(TestCase):
|
|
127
268
|
self.assertIn("Initialize the views", result.output)
|
128
269
|
|
129
270
|
def test_views_init_command(self):
|
271
|
+
"""
|
272
|
+
Test the views initialization command.
|
273
|
+
|
274
|
+
Verifies:
|
275
|
+
|
276
|
+
- Successful view initialization
|
277
|
+
- Correct number of views created
|
278
|
+
- Database state after initialization
|
279
|
+
"""
|
130
280
|
runner = CliRunner()
|
131
281
|
result = runner.invoke(cli, ["views", "init", "-v"])
|
132
282
|
self.assertEqual(result.exit_code, 0)
|
@@ -134,6 +284,15 @@ class CLITests(TestCase):
|
|
134
284
|
self.assertEqual(len(views), 49)
|
135
285
|
|
136
286
|
def test_permissions_entrypoint(self):
|
287
|
+
"""
|
288
|
+
Test the permissions command group entry point.
|
289
|
+
|
290
|
+
Verifies:
|
291
|
+
|
292
|
+
- Permissions command help message
|
293
|
+
- Presence of all subcommands
|
294
|
+
- Command descriptions
|
295
|
+
"""
|
137
296
|
runner = CliRunner()
|
138
297
|
result = runner.invoke(cli, ["permissions", "--help"])
|
139
298
|
self.assertEqual(result.exit_code, 0)
|
@@ -146,6 +305,15 @@ class CLITests(TestCase):
|
|
146
305
|
self.assertIn("Initialize the base permissions", result.output)
|
147
306
|
|
148
307
|
def test_permissions_init(self):
|
308
|
+
"""
|
309
|
+
Test the permissions initialization command.
|
310
|
+
|
311
|
+
Verifies:
|
312
|
+
|
313
|
+
- Successful initialization of all permission components
|
314
|
+
- Correct number of actions, roles, views, and permissions
|
315
|
+
- Database state after initialization
|
316
|
+
"""
|
149
317
|
runner = CliRunner()
|
150
318
|
result = runner.invoke(cli, ["permissions", "init", "-v"])
|
151
319
|
self.assertEqual(result.exit_code, 0)
|
@@ -159,6 +327,15 @@ class CLITests(TestCase):
|
|
159
327
|
self.assertEqual(len(permissions), 546)
|
160
328
|
|
161
329
|
def test_permissions_base_command(self):
|
330
|
+
"""
|
331
|
+
Test the base permissions initialization command.
|
332
|
+
|
333
|
+
Verifies:
|
334
|
+
|
335
|
+
- Successful initialization of base permissions
|
336
|
+
- Correct setup of all permission components
|
337
|
+
- Database state consistency
|
338
|
+
"""
|
162
339
|
runner = CliRunner()
|
163
340
|
runner.invoke(cli, ["actions", "init", "-v"])
|
164
341
|
runner.invoke(cli, ["roles", "init", "-v"])
|
@@ -175,6 +352,15 @@ class CLITests(TestCase):
|
|
175
352
|
self.assertEqual(len(permissions), 546)
|
176
353
|
|
177
354
|
def test_service_entrypoint(self):
|
355
|
+
"""
|
356
|
+
Test the service command group entry point.
|
357
|
+
|
358
|
+
Verifies:
|
359
|
+
|
360
|
+
- Service command help message
|
361
|
+
- Presence of init subcommand
|
362
|
+
- Command description accuracy
|
363
|
+
"""
|
178
364
|
runner = CliRunner()
|
179
365
|
result = runner.invoke(cli, ["service", "--help"])
|
180
366
|
self.assertEqual(result.exit_code, 0)
|
@@ -183,6 +369,15 @@ class CLITests(TestCase):
|
|
183
369
|
self.assertIn("Initialize the service", result.output)
|
184
370
|
|
185
371
|
def test_users_entrypoint(self):
|
372
|
+
"""
|
373
|
+
Test the users command group entry point.
|
374
|
+
|
375
|
+
Verifies:
|
376
|
+
|
377
|
+
- Users command help message
|
378
|
+
- Presence of create subcommand
|
379
|
+
- Command description accuracy
|
380
|
+
"""
|
186
381
|
runner = CliRunner()
|
187
382
|
result = runner.invoke(cli, ["users", "--help"])
|
188
383
|
self.assertEqual(result.exit_code, 0)
|
@@ -191,6 +386,15 @@ class CLITests(TestCase):
|
|
191
386
|
self.assertIn("Create a user", result.output)
|
192
387
|
|
193
388
|
def test_users_create_entrypoint(self):
|
389
|
+
"""
|
390
|
+
Test the users create command entry point.
|
391
|
+
|
392
|
+
Verifies:
|
393
|
+
|
394
|
+
- Create command help message
|
395
|
+
- Presence of service subcommand
|
396
|
+
- Command description accuracy
|
397
|
+
"""
|
194
398
|
runner = CliRunner()
|
195
399
|
result = runner.invoke(cli, ["users", "create", "--help"])
|
196
400
|
self.assertEqual(result.exit_code, 0)
|
@@ -198,6 +402,15 @@ class CLITests(TestCase):
|
|
198
402
|
self.assertIn("Create a service user", result.output)
|
199
403
|
|
200
404
|
def test_service_user_help(self):
|
405
|
+
"""
|
406
|
+
Test the service user creation help command.
|
407
|
+
|
408
|
+
Verifies:
|
409
|
+
|
410
|
+
- Help message content
|
411
|
+
- Required parameter descriptions
|
412
|
+
- Parameter documentation accuracy
|
413
|
+
"""
|
201
414
|
runner = CliRunner()
|
202
415
|
result = runner.invoke(cli, ["users", "create", "service", "--help"])
|
203
416
|
self.assertEqual(result.exit_code, 0)
|
@@ -209,6 +422,16 @@ class CLITests(TestCase):
|
|
209
422
|
self.assertIn("email", result.output)
|
210
423
|
|
211
424
|
def test_service_user_command(self):
|
425
|
+
"""
|
426
|
+
Test service user creation command.
|
427
|
+
|
428
|
+
Verifies:
|
429
|
+
|
430
|
+
- Successful service user creation
|
431
|
+
- Correct user attributes
|
432
|
+
- Service role assignment
|
433
|
+
- Service user status verification
|
434
|
+
"""
|
212
435
|
runner = CliRunner()
|
213
436
|
self.test_roles_init_command()
|
214
437
|
result = runner.invoke(
|
@@ -233,6 +456,16 @@ class CLITests(TestCase):
|
|
233
456
|
self.assertTrue(user.is_service_user())
|
234
457
|
|
235
458
|
def test_viewer_user_command(self):
|
459
|
+
"""
|
460
|
+
Test viewer user creation command.
|
461
|
+
|
462
|
+
Verifies:
|
463
|
+
|
464
|
+
- Successful viewer user creation
|
465
|
+
- Correct user attributes
|
466
|
+
- Viewer role assignment
|
467
|
+
- Service user status check
|
468
|
+
"""
|
236
469
|
runner = CliRunner()
|
237
470
|
self.test_roles_init_command()
|
238
471
|
result = runner.invoke(
|