Skip to content

Commit

Permalink
Store event type on instance attribute event_type
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Nov 27, 2019
1 parent 13bf46e commit 5c89ef3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lintipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/test_lintipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 5c89ef3

Please sign in to comment.