def test_event_message_banana(requests_mock, create_team_user, client, app): create_team_user('TEAM', 'USER') create_team_user('TEAM', 'OTHER') post_message = requests_mock.post('https://slack.com/api/chat.postMessage', json={'ok': True}) def match_args(request): return 'user=OTHER' == request._request.body users_info = requests_mock.post( 'https://slack.com/api/users.info', additional_matcher=match_args, json={ 'user': { 'is_bot': False, 'profile': { 'display_name': 'Item User', }, }, } ) response = post_as_slack( client, app, { 'event': { 'channel': 'CHANNEL', 'channel_type': 'channel', 'text': '<@OTHER> :banana:', 'type': 'message', 'user': '******', }, 'team_id': 'TEAM', 'type': 'event_callback', } ) assert response.status_code == 200 assert post_message.called assert post_message.last_request.body == urlencode({ 'channel': 'CHANNEL', 'text': 'Done. Item User has 1 :banana:!', }) assert users_info.called user = get_team_user('TEAM', 'USER') assert user['given'] == 1 other = get_team_user('TEAM', 'OTHER') assert other['received'] == 1
def test_event_reaction_removed_banana(requests_mock, create_team_user, client, app): create_team_user('TEAM', 'USER', given=1) create_team_user('TEAM', 'ITEM_USER', received=1) def match_args(request): return 'user=ITEM_USER' == request._request.body users_info = requests_mock.post( 'https://slack.com/api/users.info', additional_matcher=match_args, json={ 'user': { 'is_bot': False, }, } ) response = post_as_slack( client, app, { 'event': { 'item_user': '******', 'reaction': 'banana', 'type': 'reaction_removed', 'user': '******', }, 'team_id': 'TEAM', 'type': 'event_callback', } ) assert response.status_code == 200 assert users_info.called user = get_team_user('TEAM', 'USER') assert user['given'] == 0 item_user = get_team_user('TEAM', 'ITEM_USER') assert item_user['received'] == 0