From acf403ab766b542d28bef7072ce5290c212e4be6 Mon Sep 17 00:00:00 2001 From: Aleksandra Ovchinnikova Date: Fri, 28 Jul 2023 12:06:59 -0700 Subject: [PATCH] LITE-28203 Add check if statuses are empty --- .../core/validation/validators/eventsapp.py | 12 ++++++ .../validation/validators/test_eventsapp.py | 38 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/connect/eaas/core/validation/validators/eventsapp.py b/connect/eaas/core/validation/validators/eventsapp.py index 2b3becb..46a0ecf 100644 --- a/connect/eaas/core/validation/validators/eventsapp.py +++ b/connect/eaas/core/validation/validators/eventsapp.py @@ -115,6 +115,18 @@ def _validate_events(context): ), ) continue + if not event['statuses'] and definitions[event['event_type']]['object_statuses']: + messages.append( + ValidationItem( + level='ERROR', + message=( + f'The event *{event["event_type"]}* is not valid, event declaration ' + 'must contain not empty list of statuses.' + ), + **get_code_context(method, '@event'), + ), + ) + continue statuses = definitions[event['event_type']]['object_statuses'] if statuses: diff --git a/tests/connect/eaas/core/validation/validators/test_eventsapp.py b/tests/connect/eaas/core/validation/validators/test_eventsapp.py index 3240b0d..cf5f65a 100644 --- a/tests/connect/eaas/core/validation/validators/test_eventsapp.py +++ b/tests/connect/eaas/core/validation/validators/test_eventsapp.py @@ -216,6 +216,44 @@ def handle_event(self, request): assert item.code == 'code' +def test_validate_eventsapp_no_statuses(mocker): + class MyExt(EventsApplicationBase): + @event('test_event', statuses=[]) + def handle_event(self, request): + pass + + context = { + 'extension_classes': {'extension': MyExt}, + 'descriptor': {}, + 'extension_json_file': 'extension.json', + 'event_definitions': {'test_event': {'object_statuses': ['draft']}}, + } + + mocker.patch( + 'connect.eaas.core.validation.validators.eventsapp.get_code_context', + return_value={ + 'file': 'file', + 'start_line': 0, + 'lineno': 5, + 'code': 'code', + }, + ) + + result = validate_eventsapp(context) + + assert isinstance(result, ValidationResult) + assert result.must_exit is False + assert len(result.items) == 1 + item = result.items[0] + assert isinstance(item, ValidationItem) + assert item.level == 'ERROR' + assert 'event declaration must contain not empty list of statuses.' in item.message + assert item.file == 'file' + assert item.start_line == 0 + assert item.lineno == 5 + assert item.code == 'code' + + @pytest.mark.parametrize( ('object_statuses', 'event_statuses'), (