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.
@@ -1,5 +1,15 @@
1
1
  """
2
- Unit test for the actions endpoint
2
+ Unit tests for the actions endpoint.
3
+
4
+ This module contains tests for the actions API endpoint functionality, including:
5
+ - Authorization checks for different user roles
6
+ - Validation of action listings
7
+ - Access control verification
8
+
9
+ Classes
10
+ -------
11
+ TestActionsListEndpoint
12
+ Tests for the actions list endpoint functionality
3
13
  """
4
14
 
5
15
  # Import from libraries
@@ -10,7 +20,24 @@ from cornflow.tests.custom_test_case import CustomTestCase
10
20
 
11
21
 
12
22
  class TestActionsListEndpoint(CustomTestCase):
23
+ """
24
+ Test cases for the actions list endpoint.
25
+
26
+ This class tests the functionality of listing available actions, including:
27
+ - Authorization checks for different user roles
28
+ - Validation of returned action data
29
+ - Access control for authorized and unauthorized roles
30
+ """
31
+
13
32
  def setUp(self):
33
+ """
34
+ Set up test environment before each test.
35
+
36
+ Initializes test data including:
37
+ - Base test case setup
38
+ - Roles with access permissions
39
+ - Test payload with action data
40
+ """
14
41
  super().setUp()
15
42
  self.roles_with_access = ActionListEndpoint.ROLES_WITH_ACCESS
16
43
  self.payload = [
@@ -19,9 +46,20 @@ class TestActionsListEndpoint(CustomTestCase):
19
46
  ]
20
47
 
21
48
  def tearDown(self):
49
+ """
50
+ Clean up test environment after each test.
51
+ """
22
52
  super().tearDown()
23
53
 
24
54
  def test_get_actions_authorized(self):
55
+ """
56
+ Test that authorized roles can access the actions list.
57
+
58
+ Verifies that users with proper roles can:
59
+ - Successfully access the actions endpoint
60
+ - Receive the correct list of actions
61
+ - Get properly formatted action data
62
+ """
25
63
  for role in self.roles_with_access:
26
64
  self.token = self.create_user_with_role(role)
27
65
  response = self.client.get(
@@ -36,6 +74,13 @@ class TestActionsListEndpoint(CustomTestCase):
36
74
  self.assertCountEqual(self.payload, response.json)
37
75
 
38
76
  def test_get_actions_not_authorized(self):
77
+ """
78
+ Test that unauthorized roles cannot access the actions list.
79
+
80
+ Verifies that users without proper roles:
81
+ - Are denied access to the actions endpoint
82
+ - Receive appropriate error responses
83
+ """
39
84
  for role in ROLES_MAP:
40
85
  if role not in self.roles_with_access:
41
86
  self.token = self.create_user_with_role(role)
@@ -1,6 +1,17 @@
1
1
  """
2
+ Unit tests for the alarms endpoint.
2
3
 
4
+ This module contains tests for the alarms API endpoint functionality, including:
5
+ - Creating new alarms
6
+ - Retrieving alarm listings
7
+ - Validating alarm data and properties
8
+
9
+ Classes
10
+ -------
11
+ TestAlarmsEndpoint
12
+ Tests for the alarms endpoint functionality
3
13
  """
14
+
4
15
  # Imports from internal modules
5
16
  from cornflow.models import AlarmsModel
6
17
  from cornflow.tests.const import ALARMS_URL
@@ -8,7 +19,25 @@ from cornflow.tests.custom_test_case import CustomTestCase
8
19
 
9
20
 
10
21
  class TestAlarmsEndpoint(CustomTestCase):
22
+ """
23
+ Test cases for the alarms endpoint.
24
+
25
+ This class tests the functionality of managing alarms, including:
26
+ - Creating new alarms with various properties
27
+ - Retrieving and validating alarm data
28
+ - Checking alarm schema and criticality levels
29
+ """
30
+
11
31
  def setUp(self):
32
+ """
33
+ Set up test environment before each test.
34
+
35
+ Initializes test data including:
36
+ - Base test case setup
37
+ - URL endpoint configuration
38
+ - Model and response field definitions
39
+ - Test items to check
40
+ """
12
41
  super().setUp()
13
42
  self.url = ALARMS_URL
14
43
  self.model = AlarmsModel
@@ -16,24 +45,43 @@ class TestAlarmsEndpoint(CustomTestCase):
16
45
  self.items_to_check = ["name", "description", "schema", "criticality"]
17
46
 
18
47
  def test_post_alarm(self):
19
- payload = {"name": "Alarm 1", "description": "Description Alarm 1", "criticality": 1}
48
+ """
49
+ Test creating a new alarm.
50
+
51
+ Verifies that an alarm can be created with:
52
+ - A name
53
+ - A description
54
+ - A criticality level
55
+ """
56
+ payload = {
57
+ "name": "Alarm 1",
58
+ "description": "Description Alarm 1",
59
+ "criticality": 1,
60
+ }
20
61
  self.create_new_row(self.url, self.model, payload)
21
62
 
22
63
  def test_get_alarms(self):
64
+ """
65
+ Test retrieving multiple alarms.
66
+
67
+ Verifies:
68
+ - Retrieval of multiple alarms with different properties
69
+ - Proper handling of alarms with and without schema
70
+ - Correct validation of alarm data fields
71
+ """
23
72
  data = [
24
73
  {"name": "Alarm 1", "description": "Description Alarm 1", "criticality": 1},
25
- {"name": "Alarm 2", "description": "Description Alarm 2", "criticality": 2, "schema": "solve_model_dag"},
74
+ {
75
+ "name": "Alarm 2",
76
+ "description": "Description Alarm 2",
77
+ "criticality": 2,
78
+ "schema": "solve_model_dag",
79
+ },
26
80
  ]
27
- rows = self.get_rows(
28
- self.url,
29
- data,
30
- check_data=False
31
- )
81
+ rows = self.get_rows(self.url, data, check_data=False)
32
82
  rows_data = list(rows.json)
33
83
  for i in range(len(data)):
34
84
  for key in self.get_keys_to_check(data[i]):
35
85
  self.assertIn(key, rows_data[i])
36
86
  if key in data[i]:
37
87
  self.assertEqual(rows_data[i][key], data[i][key])
38
-
39
-
@@ -1,5 +1,15 @@
1
1
  """
2
- Unit test for the api views endpoint
2
+ Unit tests for the API views endpoint.
3
+
4
+ This module contains tests for the API views endpoint functionality, including:
5
+ - Authorization checks for different user roles
6
+ - Validation of API view listings
7
+ - Access control verification for endpoints
8
+
9
+ Classes
10
+ -------
11
+ TestApiViewListEndpoint
12
+ Tests for the API views list endpoint functionality
3
13
  """
4
14
 
5
15
  # Import from internal modules
@@ -10,7 +20,25 @@ from cornflow.tests.custom_test_case import CustomTestCase
10
20
 
11
21
 
12
22
  class TestApiViewListEndpoint(CustomTestCase):
23
+ """
24
+ Test cases for the API views list endpoint.
25
+
26
+ This class tests the functionality of listing available API views, including:
27
+ - Authorization checks for different user roles
28
+ - Validation of returned API view data
29
+ - Access control for authorized and unauthorized roles
30
+ """
31
+
13
32
  def setUp(self):
33
+ """
34
+ Set up test environment before each test.
35
+
36
+ Initializes test data including:
37
+ - Base test case setup
38
+ - Roles with access permissions
39
+ - Test payload with API view data
40
+ - Items to check in responses
41
+ """
14
42
  super().setUp()
15
43
  self.roles_with_access = ApiViewListEndpoint.ROLES_WITH_ACCESS
16
44
  self.payload = [
@@ -24,9 +52,18 @@ class TestApiViewListEndpoint(CustomTestCase):
24
52
  self.items_to_check = ["name", "description", "url_rule"]
25
53
 
26
54
  def tearDown(self):
55
+ """Clean up test environment after each test."""
27
56
  super().tearDown()
28
57
 
29
58
  def test_get_api_view_authorized(self):
59
+ """
60
+ Test that authorized roles can access the API views list.
61
+
62
+ Verifies that users with proper roles can:
63
+ - Successfully access the API views endpoint
64
+ - Receive the correct list of views
65
+ - Get properly formatted view data with all required fields
66
+ """
30
67
  for role in self.roles_with_access:
31
68
  self.token = self.create_user_with_role(role)
32
69
  response = self.client.get(
@@ -45,6 +82,13 @@ class TestApiViewListEndpoint(CustomTestCase):
45
82
  )
46
83
 
47
84
  def test_get_api_view_not_authorized(self):
85
+ """
86
+ Test that unauthorized roles cannot access the API views list.
87
+
88
+ Verifies that users without proper roles:
89
+ - Are denied access to the API views endpoint
90
+ - Receive appropriate error responses with 403 status code
91
+ """
48
92
  for role in ROLES_MAP:
49
93
  if role not in self.roles_with_access:
50
94
  self.token = self.create_user_with_role(role)
@@ -0,0 +1,60 @@
1
+ """
2
+ File to test different application configurations
3
+ """
4
+
5
+ import json
6
+ import logging as log
7
+
8
+ from flask import current_app
9
+
10
+ from cornflow.app import create_app
11
+ from cornflow.models import UserModel
12
+ from cornflow.commands.access import access_init_command
13
+ from cornflow.commands.dag import register_deployed_dags_command_test
14
+ from cornflow.shared import db
15
+ from cornflow.tests.const import LOGIN_URL
16
+ from cornflow.tests.custom_test_case import CustomTestCase
17
+
18
+
19
+ class TestApplicationRoot(CustomTestCase):
20
+
21
+ def create_app(self):
22
+ return create_app("testing-root")
23
+
24
+ def setUp(self):
25
+ log.root.setLevel(current_app.config["LOG_LEVEL"])
26
+ db.create_all()
27
+ access_init_command(verbose=False)
28
+ register_deployed_dags_command_test(verbose=False)
29
+ self.data = {
30
+ "username": "testname",
31
+ "email": "test@test.com",
32
+ "password": "Testpassword1!",
33
+ }
34
+
35
+ user = UserModel(self.data)
36
+ user.save()
37
+
38
+ self.data.pop("email")
39
+
40
+ def tearDown(self):
41
+ db.session.remove()
42
+ db.drop_all()
43
+
44
+ def test_wrong_route(self):
45
+ response = self.client.post(
46
+ LOGIN_URL,
47
+ data=json.dumps(self.data),
48
+ follow_redirects=True,
49
+ headers={"Content-Type": "application/json"},
50
+ )
51
+ self.assertEqual(response.status_code, 404)
52
+
53
+ def test_correct_route(self):
54
+ response = self.client.post(
55
+ f"{current_app.config['APPLICATION_ROOT']}{LOGIN_URL}",
56
+ data=json.dumps(self.data),
57
+ follow_redirects=True,
58
+ headers={"Content-Type": "application/json"},
59
+ )
60
+ self.assertEqual(response.status_code, 200)