From 5c89ef330f178d6ae854072d6b871de29b28ccb0 Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Wed, 27 Nov 2019 11:23:42 +0700 Subject: [PATCH] Store event type on instance attribute event_type --- lintipy.py | 2 ++ tests/test_lintipy.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lintipy.py b/lintipy.py index dd8e448..cef4d51 100644 --- a/lintipy.py +++ b/lintipy.py @@ -45,6 +45,8 @@ def __call__(self, event, context): self.event = event self.context = context self.hook = json.loads(self.event['Records'][0]['Sns']['Message']) + self.event_type = self.event['Records'][0]['Sns']['Subject'] + logger.info('Received %s event', self.event_type) logger.debug(self.hook) @classmethod diff --git a/tests/test_lintipy.py b/tests/test_lintipy.py index 1d159c3..5dc4bd9 100644 --- a/tests/test_lintipy.py +++ b/tests/test_lintipy.py @@ -32,6 +32,7 @@ def handler(self): notice['Records'][0]['Sns']['Subject'] = subject notice['Records'][0]['Sns']['Message'] = message hnd.event = notice + hnd.event_type = subject hnd.hook = json.loads(message) hnd._session = requests.Session() return hnd @@ -81,9 +82,12 @@ def test_call(self, handler, caplog): content_type='application/json', ) handler.download_code = lambda: '.' + handler.event_type = None with caplog.at_level(logging.INFO, logger='lintipy'): handler(handler.event, {}) assert "linter exited with status code 0 in " in caplog.text + assert "Received check_run event" in caplog.text + assert handler.event_type == 'check_run' handler.cmd = 'tests.exit1' with caplog.at_level(logging.INFO, logger='lintipy'):