コード例 #1
0
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))
コード例 #2
0
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
コード例 #3
0
ファイル: test_fines.py プロジェクト: cbeardsmore/fined
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))
    
コード例 #4
0
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
    
コード例 #5
0
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)
コード例 #6
0
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())
コード例 #7
0
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())
コード例 #8
0
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)
コード例 #9
0
ファイル: test_fines.py プロジェクト: cbeardsmore/fined
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())
コード例 #10
0
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)
コード例 #11
0
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)