def test_query_twitter(sleep, time, db_session, twitter): """ Database should be filled with tweets returned from Twython """ clear_tables() # make twitter return the sample tweets tweet_sequence = [{'statuses': [sample.tweets[0]]}, {'statuses': [sample.tweets[1]]}] twitter.search = Mock(side_effect=tweet_sequence) # make time.time return canned values and time.sleep do nothing time_sequence = [5, 5, 10, 15] time.side_effect = time_sequence search.query_twitter(7, 5) assert len(time.call_args_list) == len(time_sequence) assert sleep.call_args_list == [call(5), call(5)] assert len(twitter.search.call_args_list) == 2 sample.assert_matching_tweets(get_db_session().query(Tweet).all())
def db(): clear_tables() return get_db_session()