def test_crypto_cmd(mock_requests):
    init_response(mock_requests)

    conn = MagicMock()
    conn.config = {}
    conn.bot = None

    event = CommandEvent(
        text="BTC USD",
        cmd_prefix=".",
        triggered_command="crypto",
        hook=MagicMock(),
        bot=conn.bot,
        conn=conn,
        channel="#foo",
        nick="foobaruser",
    )
    res = wrap_hook_response(cryptocurrency.crypto_command, event)

    assert res == [
        HookResult(
            return_type="return",
            value="BTC (bitcoin) // \x0307$50,000,000,000.00\x0f USD - 2.0000000 BTC // \x0303+18.9%\x0f change",
        )
    ]
Example #2
0
def test_crypto_cmd(mock_requests):
    init_response(mock_requests)

    conn = MagicMock()
    conn.config = {}
    conn.bot = None

    event = CommandEvent(
        text='BTC USD',
        cmd_prefix='.',
        triggered_command='crypto',
        hook=MagicMock(),
        bot=conn.bot,
        conn=conn,
        channel='#foo',
        nick='foobaruser',
    )
    res = wrap_hook_response(cryptocurrency.crypto_command, event)

    assert res == [
        HookResult(
            return_type='return',
            value=
            'BTC (bitcoin) // \x0307$50,000,000,000.00\x0f USD - 2.0000000 BTC // \x0303+18.9%\x0f change',
        )
    ]
def test_btc_alias_neg_change(mock_requests):
    init_response(mock_requests, pct_change=-14.5)

    res = _run_alias()

    assert res == [
        HookResult(
            return_type="return",
            value="BTC (bitcoin) // \x0307$50,000,000,000.00\x0f USD - 2.0000000 BTC // \x0305-14.5%\x0f change",
        )
    ]
Example #4
0
def test_btc_alias_no_change(mock_requests):
    init_response(mock_requests, pct_change=0)

    res = _run_alias()

    assert res == [
        HookResult(
            return_type='return',
            value=
            'BTC (bitcoin) // \x0307$50,000,000,000.00\x0f USD - 2.0000000 BTC // 0% change',
        )
    ]
def test_crypto_cmd_bad_fiat(mock_requests):
    init_response(mock_requests, quote=False)

    conn = MagicMock()
    conn.config = {}
    conn.bot = None

    event = CommandEvent(
        text="BTC ABC",
        cmd_prefix=".",
        triggered_command="crypto",
        hook=MagicMock(),
        bot=conn.bot,
        conn=conn,
        channel="#foo",
        nick="foobaruser",
    )
    res = wrap_hook_response(cryptocurrency.crypto_command, event)

    assert res == [HookResult("return", "Unknown fiat currency 'ABC'")]
Example #6
0
def test_crypto_cmd_bad_fiat(mock_requests):
    init_response(mock_requests, quote=False)

    conn = MagicMock()
    conn.config = {}
    conn.bot = None

    event = CommandEvent(
        text='BTC ABC',
        cmd_prefix='.',
        triggered_command='crypto',
        hook=MagicMock(),
        bot=conn.bot,
        conn=conn,
        channel='#foo',
        nick='foobaruser',
    )
    res = wrap_hook_response(cryptocurrency.crypto_command, event)

    assert res == [HookResult('return', "Unknown fiat currency 'ABC'")]
def test_cmd_api_error(mock_requests):
    init_response(mock_requests, error_msg="FooBar")
    conn = MagicMock()
    conn.config = {}
    conn.bot = None

    event = CommandEvent(
        text="BTC USD",
        cmd_prefix=".",
        triggered_command="crypto",
        hook=MagicMock(),
        bot=conn.bot,
        conn=conn,
        channel="#foo",
        nick="foobaruser",
    )
    res = []
    with pytest.raises(cryptocurrency.APIError, match="FooBar"):
        wrap_hook_response(cryptocurrency.crypto_command, event, res)

    assert res == [HookResult("message", ("#foo", "(foobaruser) Unknown API error"))]
Example #8
0
def test_cmd_api_error(mock_requests):
    init_response(mock_requests, error_msg='FooBar')
    conn = MagicMock()
    conn.config = {}
    conn.bot = None

    event = CommandEvent(
        text='BTC USD',
        cmd_prefix='.',
        triggered_command='crypto',
        hook=MagicMock(),
        bot=conn.bot,
        conn=conn,
        channel='#foo',
        nick='foobaruser',
    )
    res = []
    with pytest.raises(cryptocurrency.APIError, match='FooBar'):
        wrap_hook_response(cryptocurrency.crypto_command, event, res)

    assert res == [
        HookResult('message', ('#foo', '(foobaruser) Unknown API error'))
    ]