Skip to content

Commit 8d8b27b

Browse files
Adding deprecation message for db storage type as file in config (#559)
* Adding deprecation message for db storage type as file in config * Used Enum values in message
1 parent 4024d3d commit 8d8b27b

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

pebblo/app/config/config_validation.py

+16
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ def validate(self):
7878
if not os.path.exists(expand_path(str(default_location))):
7979
os.makedirs(expand_path(str(default_location)), exist_ok=True)
8080

81+
@staticmethod
82+
def validate_input(input_dict):
83+
deprecate_error = f"DeprecationWarning: '{StorageTypes.FILE.value}' in storage type is deprecated, use '{StorageTypes.DATABASE.value}' instead"
84+
85+
valid_storage_type = [storage_type.value for storage_type in StorageTypes]
86+
input_storage_type = input_dict.get("storage", {}).get("type")
87+
if input_storage_type not in valid_storage_type:
88+
raise Exception(
89+
f"Either '{StorageTypes.FILE.value}' or '{StorageTypes.DATABASE.value}' should be there in storage type"
90+
)
91+
92+
if StorageTypes.FILE.value in input_storage_type:
93+
print(deprecate_error)
94+
return input_dict
95+
8196

8297
def expand_path(file_path: str) -> str:
8398
# Expand user (~) and environment variables
@@ -177,6 +192,7 @@ def validate_input(input_dict):
177192
"""This function is used to validate input of config file"""
178193
validators = {
179194
"reports": ReportsConfig,
195+
"storage": StorageConfig,
180196
}
181197

182198
validation_errors = []

pebblo/app/enums/common.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class StorageTypes(Enum):
88

99
class DBStorageTypes(Enum):
1010
SQLITE = "sqlite"
11-
MONGODB = "mongodb"
1211

1312

1413
class ClassificationMode(Enum):

tests/app/config/test_config_validation.py

+40
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DaemonConfig,
99
LoggingConfig,
1010
ReportsConfig,
11+
StorageConfig,
1112
validate_config,
1213
)
1314

@@ -169,6 +170,45 @@ def test_classifier_config_validate():
169170
]
170171

171172

173+
def test_storage_config_validate():
174+
# Test with storage type `file` correct value
175+
storage = {"type": "file"}
176+
validator = StorageConfig(storage)
177+
validator.validate()
178+
assert validator.errors == []
179+
180+
# Test with storage type `db` correct value
181+
storage = {"type": "db", "db": "sqlite", "name": "pebblo_db"}
182+
validator = StorageConfig(storage)
183+
validator.validate()
184+
assert validator.errors == []
185+
186+
# Test with wrong storage type
187+
storage = {"type": "xyz"}
188+
validator = StorageConfig(storage)
189+
validator.validate()
190+
assert validator.errors == [
191+
"Error: Unsupported storage type 'xyz' specified in the configuration.Valid values are ['file', 'db']"
192+
]
193+
194+
# Test with storage type as `db` wrong `db` value
195+
storage = {"type": "db", "db": "db123", "name": "pebblo_db"}
196+
validator = StorageConfig(storage)
197+
validator.validate()
198+
assert validator.errors == [
199+
"Error: Unsupported db type 'db123' specified in the configuration.Valid values are ['sqlite']"
200+
]
201+
202+
# Test with storage type as `db` without `db` and `name`
203+
storage = {"type": "db"}
204+
validator = StorageConfig(storage)
205+
validator.validate()
206+
assert validator.errors == [
207+
"Error: Unsupported db type 'None' specified in the configuration.Valid values are ['sqlite']",
208+
"Error: Unsupported db name 'None specified in the configurationString values are allowed only",
209+
]
210+
211+
172212
def test_validate_config(setup_and_teardown):
173213
# Test with valid configuration
174214
config = {

0 commit comments

Comments
 (0)