def test_handle_with_fine_text_returns_valid_response(event): body_text = '@{} $50 for reason'.format(const.USERNAME_FINED) event['body'] = utils.set_body_text(event['body'], body_text) event = utils.update_signature(event) dynamo.create_fine_table() result = fine.handle(event, {}) assert result['body'] == json.dumps(response.create_fine_response(const.USERNAME_FINED))
def test_handle_with_unknown_action_does_nothing(requests_mock, event_pb): event_pb['body'] = utils.set_interaction_action_id(event_pb['body'], 'random_action_id') event_pb = utils.update_signature(event_pb) requests_mock.post(interaction.OPEN_VIEW_POST_URL) interaction.handle(event_pb, {}) assert requests_mock.call_count == 0
def test_handle_with_fine_text_returns_valid_response(event): text = '@fake_user_2 $50 for reason' event['body'] = utils.set_body_text(event['body'], '') event = utils.update_signature(event) dynamo.create_fine_table() dynamo.add_fine(const.TEAM_ID, const.CHANNEL_ID, const.USERNAME, text, const.FINE_ID) result = fines.handle(event, {}) expected_fine = [{'finedBy': const.USERNAME, 'text': text, 'id': const.FINE_ID}] assert result['body'] == json.dumps(response.create_fines_response(expected_fine))
def test_handle_with_fine_text_saves_dynamo_item(event): text = '@fake_user_2 $50 for reason' event['body'] = utils.set_body_text(event['body'], text) event = utils.update_signature(event) dynamo.create_fine_table() fine.handle(event, {}) fine_item = dynamo.get_fines(const.TEAM_ID, const.CHANNEL_ID)[0] assert fine_item['finedBy'] == const.USERNAME assert fine_item['text'] == text assert fine_item['id'] is not None
def test_handle_with_pay_action_calls_slack_view_open(requests_mock, event_pb): event_pb['body'] = utils.set_interaction_action_id( event_pb['body'], interaction.ACTION_PAY_FINE) event_pb = utils.update_signature(event_pb) requests_mock.post(interaction.OPEN_VIEW_POST_URL) dynamo.create_token_table() dynamo.update_access_token({ 'id': const.TEAM_ID, 'name': const.TEAM_NAME }, const.BOT_ACCESS_TOKEN) interaction.handle(event_pb, {}) last_request = requests_mock.last_request assert requests_mock.call_count == 1 assert last_request.json() == response.create_pay_modal( const.TRIGGER_ID, const.CHANNEL_ID, const.FINE_ID) assert last_request.headers['Content-Type'] == interaction.CONTENT_TYPE assert last_request.headers['Authorization'] == 'Bearer {}'.format( const.BOT_ACCESS_TOKEN)
def test_handle_with_help_text_returns_help(event): event['body'] = utils.set_body_text(event['body'], 'help') event = utils.update_signature(event) result = fine.handle(event, {}) assert result['body'] == json.dumps(response.create_help_response())
def test_handle_with_no_text_returns_fallback(event): event['body'] = utils.set_body_text(event['body'], 'invalid_text') event = utils.update_signature(event) result = fine.handle(event, {}) assert result['body'] == json.dumps(response.create_fallback_response())
def event(mock_os): event_payload = [] with open('test/payloads/fine.json') as file: event_payload = json.load(file) return utils.update_signature(event_payload)
def test_handle_with_no_fines_returns_no_fines_response(event): event = utils.update_signature(event) dynamo.create_fine_table() result = fines.handle(event, {}) assert result['body'] == json.dumps(response.create_no_fines_response())
def event_vs(mock_os): event_payload = [] with open('test/payloads/view_submission.json') as event_file: event_payload = json.load(event_file) return utils.update_signature(event_payload)
def event_pb(mock_os): event_payload = [] with open('test/payloads/pay_button.json') as event_file: event_payload = json.load(event_file) return utils.update_signature(event_payload)