Skip to content

Commit

Permalink
Validation in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
bart0003 committed Dec 14, 2023
1 parent c1ddfb8 commit b0e2e97
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion smart_kit/testing/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from core.utils.utils import deep_update_dict
from scenarios.user.user_model import User
from smart_kit.compatibility.commands import combine_commands
from smart_kit.configs import get_app_config
from smart_kit.configs.settings import Settings
from smart_kit.message.smartapp_to_message import SmartAppToMessage
from smart_kit.message.validators.base_validator_with_resources import BaseMessageValidatorWithResources
from smart_kit.models.smartapp_model import SmartAppModel
from smart_kit.request.kafka_request import SmartKitKafkaRequest
from smart_kit.testing.utils import Environment
Expand Down Expand Up @@ -224,6 +226,14 @@ async def _run(self) -> bool:
headers = [('kafka_correlationId', 'test_123')]
message = self.create_message(request, headers=headers)

for v in message.validators:
if isinstance(v, BaseMessageValidatorWithResources):
v.resources = self.app_model.resources

if not message.validate():
print(f"[!] Incoming message {message.message_name} validation failed.")
return False

user = self.__user_cls(
id=message.uid, message=message, db_data=self.user_state, settings=self.settings,
descriptions=self.app_model.scenario_descriptions,
Expand Down Expand Up @@ -294,7 +304,7 @@ def create_message(self, data, headers=None):
defaults["payload"].update({"message": message})

defaults.update(data)
return self.__from_msg_cls(defaults, headers=headers)
return self.__from_msg_cls(defaults, headers=headers, validators=get_app_config().FROM_MSG_VALIDATORS)

def handle_predefined_fields_response(self, predefined_fields_resp, response):
predefined_fields_resp_data = self.storaged_predefined_fields[predefined_fields_resp]
Expand Down

0 comments on commit b0e2e97

Please sign in to comment.