Domanda

I just start to make an application using Tweepy to communicate with Twitter API.

I want to mock the Tweepy API to test my application and avoid a RaiseLimitError.

I found this : https://code.google.com/p/hailbot/source/browse/external/tweepy/tweepybot.py.
But it doesn't work and it hasn't been updated since 2011.

Do you know someting to mock the API?

È stato utile?

Soluzione

There's python mock

pip install mock

Or caliendo (a buzzfeed skunkswork project) offers some easy-to-use caching for services.

pip install caliendo

There is a lot of good documentation on both.

http://www.voidspace.org.uk/python/mock/

or

http://www.github.com/buzzfeed/caliendo

from caliendo.patch import patch
from caliendo import expected_value

class TestTweepyApi(unittest.TestCase):

    @patch('tweepy.api.update_status')
    def test_tweet(self):
        expected_value.is_equal_to(my_method_that_calls_tweepy_update_status())
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top