Exemplo n.º 1
0
def test_timeout_reset(api):
    listener = RetweetListener(api)
    listener.timeout = 8

    listener.on_connect()

    assert listener.timeout == 1
Exemplo n.º 2
0
def test_listener_no_match(api):
    filterer = Mock(return_value=False)

    listener = RetweetListener(api, filterer=filterer)

    listener.on_status(create_tweet(123, 'hello world', 'BobBurnquist'))
    filterer.assert_called_once_with('hello world')
    api.retweet.assert_not_called()
Exemplo n.º 3
0
def test_extended_tweets(api):
    mock_extractor = Mock()
    listener = RetweetListener(api, mock_extractor, Mock(return_value=False))
    full_text = 'foo bar baz'
    tweet = create_tweet(123, 'foo', 'DeweyDuck', full_text)

    listener.on_status(tweet)

    mock_extractor.assert_called_once_with(full_text)
Exemplo n.º 4
0
def test_backoff(mock_logger, mock_sleep, api):
    listener = RetweetListener(api)
    listener.timeout = 4

    listener.on_error(420)
    mock_logger.info.assert_called_once_with('timing out for %s seconds', 240)
    mock_sleep.assert_called_once_with(240)

    assert listener.timeout == 8
Exemplo n.º 5
0
def test_listener_match(api):
    filterer = Mock(return_value=True)
    extractor = Mock(return_value='hello world')

    listener = RetweetListener(api=api, extractor=extractor, filterer=filterer)

    listener.on_status(create_tweet(123, 'foo bar baz', 'ClaraCoventry'))
    filterer.assert_called_once_with('hello world')
    extractor.assert_called_once_with('foo bar baz')
    api.retweet.assert_called_once_with(123)
Exemplo n.º 6
0
def test_unextended_tweets(api):
    mock_extractor = Mock()
    listener = RetweetListener(api, mock_extractor, Mock(return_value=False))
    short_text = 'foo'
    tweet = create_tweet(123, short_text, 'DeweyDuck', 'foo bar baz')
    del tweet.extended_tweet

    listener.on_status(tweet)

    mock_extractor.assert_called_once_with(short_text)
Exemplo n.º 7
0
def test_logging(mock_logger, api):
    listener = RetweetListener(api)

    listener.on_status(create_tweet(456, 'foo', 'AliceAnderson'))
    mock_logger.debug.assert_called_once_with(
        'received %r from @%s: %r',
        456,
        'AliceAnderson',
        'foo',
    )
    mock_logger.info.assert_called_once_with('retweeting %r %r', 456, 'foo')
Exemplo n.º 8
0
def test_error_logging(mock_logger, api):
    listener = RetweetListener(api)

    listener.on_error(404)
    mock_logger.error.assert_called_once_with('streaming error %s', 404)