test_api.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import responses
  2. from twitter_v2.api import ApiV2TweetSource
  3. @responses.activate
  4. def test_create_tweet ():
  5. fake_res = {
  6. 'id': 1234,
  7. 'text': 'Test Text'
  8. }
  9. responses.add(responses.POST, 'https://api.twitter.com/2/tweets',
  10. json=fake_res, status=200)
  11. tweet_source = ApiV2TweetSource('FAKE TOKEN')
  12. res = tweet_source.create_tweet('Test Text')
  13. assert len(responses.calls) == 1
  14. assert(res == fake_res)
  15. @responses.activate
  16. def test_get_timeline ():
  17. fake_res = {
  18. 'meta': 1234,
  19. 'text': 'Test Text'
  20. }
  21. responses.add(responses.GET, 'https://api.twitter.com/2/timeline/test',
  22. json=fake_res, status=200)
  23. tweet_source = ApiV2TweetSource('FAKE TOKEN')
  24. res = tweet_source.get_timeline('timeline/test', pagination_token='1234')
  25. assert len(responses.calls) == 1
  26. req = responses.calls[0].request
  27. assert req.params.get('pagination_token') == '1234'
  28. assert(res == fake_res)