1
+ """
2
+ Module contains the functions to validate the test
3
+ configuration data and populate user data for tests.
4
+ """
1
5
from copy import deepcopy
2
6
from .logger import logger
7
+ from .utils import update_values
3
8
4
9
5
- def overwrite_user_params ( list1 : list [ dict ], list2 : list [ dict ]) -> list [ dict ] :
10
+ def validate_config_file_data ( test_config_data : dict ) :
6
11
"""
7
- Update values in list1 based on the corresponding "name" values in list2 .
12
+ Validates the provided test configuration data .
8
13
9
14
Args:
10
- list1 (list of dict): The list of dictionaries to be updated.
11
- list2 (list of dict): The list of dictionaries containing values to update from.
15
+ test_config_data (dict): The test configuration data to be validated.
12
16
13
17
Returns:
14
- list of dict: The updated list1 with values from list2.
15
-
16
- Example:
17
- ```python
18
- list1 = [{'name': 'id', 'value': 67}, {'name': 'email', 'value': '[email protected] '}]
19
- list2 = [{'name': 'id', 'value': 10}, {'name': 'email', 'value': '[email protected] '}]
20
- updated_list = update_values(list1, list2)
21
- print(updated_list)
22
- # Output: [{'name': 'id', 'value': 10}, {'name': 'email', 'value': '[email protected] '}]
23
- ```
24
- """
25
- # Create a dictionary for faster lookup
26
- lookup_dict = {item ['name' ]: item ['value' ] for item in list2 }
27
-
28
- # Update values in list1 using index lookup
29
- for item in list1 :
30
- if item ['name' ] in lookup_dict :
31
- item ['value' ] = lookup_dict [item ['name' ]]
32
-
33
- return list1
18
+ bool or dict: Returns False if the data is invalid, otherwise returns the validated test configuration data.
34
19
35
-
36
- def validate_config_file_data (test_config_data : dict ):
20
+ """
37
21
if not isinstance (test_config_data , dict ):
38
22
logger .warning ('Invalid data format' )
39
23
return False
@@ -42,9 +26,7 @@ def validate_config_file_data(test_config_data: dict):
42
26
logger .warning ('Error Occurred While reading file: %s' , test_config_data )
43
27
return False
44
28
45
- if not test_config_data .get (
46
- 'actors' ,
47
- ):
29
+ if not test_config_data .get ('actors' ):
48
30
logger .warning ('actors are required' )
49
31
return False
50
32
@@ -57,6 +39,17 @@ def validate_config_file_data(test_config_data: dict):
57
39
58
40
59
41
def populate_user_data (actor_data : dict , actor_name : str , tests : list [dict ]):
42
+ """
43
+ Populates user data for tests.
44
+
45
+ Args:
46
+ actor_data (dict): The data of the actor.
47
+ actor_name (str): The name of the actor.
48
+ tests (list[dict]): The list of tests.
49
+
50
+ Returns:
51
+ list[dict]: The updated list of tests.
52
+ """
60
53
tests = deepcopy (tests )
61
54
headers = actor_data .get ('request_headers' , [])
62
55
body_params = actor_data .get ('body' , [])
@@ -69,15 +62,11 @@ def populate_user_data(actor_data: dict, actor_name: str, tests: list[dict]):
69
62
request_headers [header .get ('name' )] = header .get ('value' )
70
63
71
64
for test in tests :
72
- test ['body_params' ] = overwrite_user_params (
73
- deepcopy (test ['body_params' ]), body_params
74
- )
75
- test ['query_params' ] = overwrite_user_params (
65
+ test ['body_params' ] = update_values (deepcopy (test ['body_params' ]), body_params )
66
+ test ['query_params' ] = update_values (
76
67
deepcopy (test ['query_params' ]), query_params
77
68
)
78
- test ['path_params' ] += overwrite_user_params (
79
- deepcopy (test ['path_params' ]), path_params
80
- )
69
+ test ['path_params' ] += update_values (deepcopy (test ['path_params' ]), path_params )
81
70
# for post test processing tests such as broken authentication
82
71
test ['test_actor_name' ] = actor_name
83
72
if test .get ('kwargs' , {}).get ('headers' , {}).items ():
0 commit comments