test_view_model.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import twitter_v2_facade as t2f
  2. """
  3. The big item to test here is tweet_model() which converts a Tweet into a UI view and action links.
  4. """
  5. def mock_url_for (route, *args, **kwargs):
  6. return 'URL:' + route
  7. def test_tweet_model ():
  8. tweet_api_resp = {
  9. 'data': [{
  10. 'id': 12345,
  11. 'text': 'A tweet!',
  12. 'created_at': 'a time',
  13. 'author_id': 456,
  14. 'conversation_id': 12345
  15. }
  16. ],
  17. 'includes': {
  18. 'tweets': [],
  19. 'users': [{
  20. 'id': 456,
  21. 'username': 'user456',
  22. 'name': 'User 456',
  23. 'verified': False,
  24. 'profile_image_url': 'pfp_url'
  25. }],
  26. 'media': []
  27. },
  28. 'meta': {
  29. 'result_count': 1,
  30. # 'next_token': 'AAA'
  31. }
  32. }
  33. includes = tweet_api_resp.get('includes')
  34. tweet_data = tweet_api_resp.get('data')[0]
  35. tweet = t2f.tweet_model (includes, tweet_data, 'TEST', my_url_for = mock_url_for)
  36. assert(tweet['id'] == 12345)
  37. assert(tweet['text'] == 'A tweet!')
  38. assert(tweet['author_id'] == 456)
  39. assert(tweet['display_name'] == 'User 456')