2
2
3
3
import pytest # noqa: F401
4
4
5
- from aws_lambda_powertools .utilities .feature_flags .exceptions import ConfigurationError
5
+ from aws_lambda_powertools .utilities .feature_flags .exceptions import SchemaValidationError
6
6
from aws_lambda_powertools .utilities .feature_flags .schema import (
7
7
CONDITION_ACTION ,
8
8
CONDITION_KEY ,
24
24
25
25
def test_invalid_features_dict ():
26
26
validator = SchemaValidator (schema = [])
27
- with pytest .raises (ConfigurationError ):
27
+ with pytest .raises (SchemaValidationError ):
28
28
validator .validate ()
29
29
30
30
@@ -45,7 +45,7 @@ def test_empty_features_not_fail():
45
45
)
46
46
def test_invalid_feature (schema ):
47
47
validator = SchemaValidator (schema )
48
- with pytest .raises (ConfigurationError ):
48
+ with pytest .raises (SchemaValidationError ):
49
49
validator .validate ()
50
50
51
51
@@ -73,7 +73,7 @@ def test_invalid_rule():
73
73
}
74
74
}
75
75
validator = SchemaValidator (schema )
76
- with pytest .raises (ConfigurationError ):
76
+ with pytest .raises (SchemaValidationError ):
77
77
validator .validate ()
78
78
79
79
# rules RULE_MATCH_VALUE is not bool
@@ -88,7 +88,7 @@ def test_invalid_rule():
88
88
}
89
89
}
90
90
validator = SchemaValidator (schema )
91
- with pytest .raises (ConfigurationError ):
91
+ with pytest .raises (SchemaValidationError ):
92
92
validator .validate ()
93
93
94
94
# missing conditions list
@@ -103,7 +103,7 @@ def test_invalid_rule():
103
103
}
104
104
}
105
105
validator = SchemaValidator (schema )
106
- with pytest .raises (ConfigurationError ):
106
+ with pytest .raises (SchemaValidationError ):
107
107
validator .validate ()
108
108
109
109
# condition list is empty
@@ -116,7 +116,7 @@ def test_invalid_rule():
116
116
}
117
117
}
118
118
validator = SchemaValidator (schema )
119
- with pytest .raises (ConfigurationError ):
119
+ with pytest .raises (SchemaValidationError ):
120
120
validator .validate ()
121
121
122
122
# condition is invalid type, not list
@@ -129,7 +129,7 @@ def test_invalid_rule():
129
129
}
130
130
}
131
131
validator = SchemaValidator (schema )
132
- with pytest .raises (ConfigurationError ):
132
+ with pytest .raises (SchemaValidationError ):
133
133
validator .validate ()
134
134
135
135
@@ -147,7 +147,7 @@ def test_invalid_condition():
147
147
}
148
148
}
149
149
validator = SchemaValidator (schema )
150
- with pytest .raises (ConfigurationError ):
150
+ with pytest .raises (SchemaValidationError ):
151
151
validator .validate ()
152
152
153
153
# missing condition key and value
@@ -163,7 +163,7 @@ def test_invalid_condition():
163
163
}
164
164
}
165
165
validator = SchemaValidator (schema )
166
- with pytest .raises (ConfigurationError ):
166
+ with pytest .raises (SchemaValidationError ):
167
167
validator .validate ()
168
168
169
169
# invalid condition key type, not string
@@ -183,7 +183,7 @@ def test_invalid_condition():
183
183
}
184
184
}
185
185
validator = SchemaValidator (schema )
186
- with pytest .raises (ConfigurationError ):
186
+ with pytest .raises (SchemaValidationError ):
187
187
validator .validate ()
188
188
189
189
@@ -229,8 +229,8 @@ def test_validate_condition_invalid_condition_type():
229
229
condition = {}
230
230
231
231
# WHEN calling validate_condition
232
- # THEN raise ConfigurationError
233
- with pytest .raises (ConfigurationError , match = "Feature rule condition must be a dictionary" ):
232
+ # THEN raise SchemaValidationError
233
+ with pytest .raises (SchemaValidationError , match = "Feature rule condition must be a dictionary" ):
234
234
ConditionsValidator .validate_condition (condition = condition , rule_name = "dummy" )
235
235
236
236
@@ -239,8 +239,8 @@ def test_validate_condition_invalid_condition_action():
239
239
condition = {"action" : "INVALID" , "key" : "tenant_id" , "value" : "12345" }
240
240
241
241
# WHEN calling validate_condition
242
- # THEN raise ConfigurationError
243
- with pytest .raises (ConfigurationError , match = "'action' value must be either" ):
242
+ # THEN raise SchemaValidationError
243
+ with pytest .raises (SchemaValidationError , match = "'action' value must be either" ):
244
244
ConditionsValidator .validate_condition_action (condition = condition , rule_name = "dummy" )
245
245
246
246
@@ -249,8 +249,8 @@ def test_validate_condition_invalid_condition_key():
249
249
condition = {"action" : RuleAction .EQUALS .value , "value" : "12345" }
250
250
251
251
# WHEN calling validate_condition
252
- # THEN raise ConfigurationError
253
- with pytest .raises (ConfigurationError , match = "'key' value must be a non empty string" ):
252
+ # THEN raise SchemaValidationError
253
+ with pytest .raises (SchemaValidationError , match = "'key' value must be a non empty string" ):
254
254
ConditionsValidator .validate_condition_key (condition = condition , rule_name = "dummy" )
255
255
256
256
@@ -262,21 +262,21 @@ def test_validate_condition_missing_condition_value():
262
262
}
263
263
264
264
# WHEN calling validate_condition
265
- with pytest .raises (ConfigurationError , match = "'value' key must not be empty" ):
265
+ with pytest .raises (SchemaValidationError , match = "'value' key must not be empty" ):
266
266
ConditionsValidator .validate_condition_value (condition = condition , rule_name = "dummy" )
267
267
268
268
269
269
def test_validate_rule_invalid_rule_type ():
270
270
# GIVEN an invalid rule type of empty list
271
271
# WHEN calling validate_rule
272
- # THEN raise ConfigurationError
273
- with pytest .raises (ConfigurationError , match = "Feature rule must be a dictionary" ):
272
+ # THEN raise SchemaValidationError
273
+ with pytest .raises (SchemaValidationError , match = "Feature rule must be a dictionary" ):
274
274
RulesValidator .validate_rule (rule = [], rule_name = "dummy" , feature_name = "dummy" )
275
275
276
276
277
277
def test_validate_rule_invalid_rule_name ():
278
278
# GIVEN a rule name is empty
279
279
# WHEN calling validate_rule_name
280
- # THEN raise ConfigurationError
281
- with pytest .raises (ConfigurationError , match = "Rule name key must have a non-empty string" ):
280
+ # THEN raise SchemaValidationError
281
+ with pytest .raises (SchemaValidationError , match = "Rule name key must have a non-empty string" ):
282
282
RulesValidator .validate_rule_name (rule_name = "" , feature_name = "dummy" )
0 commit comments