From 6890802b2ae528557fdb1a528b4efd17470b5702 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Tue, 22 Aug 2017 13:55:22 +0100 Subject: [PATCH] Add test for missing `symbols` in entities If a tweet has no `symbols` in its `entities` then `html_for_tweet()` was failing. I'm not sure how common this is but, for example, tweets in a downloaded archive do not have `symbols` for some reason. The previous change (b366ab5) fixed this, but I'm adding a test for this case. --- tests/test_core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_core.py b/tests/test_core.py index 45d856e..2a30df5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -334,6 +334,18 @@ class TwythonAPITestCase(unittest.TestCase): self.assertTrue('$AAPL' in tweet_text) self.assertTrue('$ANOTHER' not in tweet_text) + def test_html_for_tweet_no_symbols(self): + """Should still work if tweet object has no symbols list""" + tweet = test_tweet_symbols_object + # Save a copy: + symbols = tweet['entities']['symbols'] + del tweet['entities']['symbols'] + tweet_text = self.api.html_for_tweet(tweet) + self.assertTrue('symbols: $AAPL and' in tweet_text) + self.assertTrue('and $ANOTHER and $A.' in tweet_text) + # Put the symbols back: + test_tweet_symbols_object['entities']['symbols'] = symbols + def test_html_for_tweet_compatmode(self): tweet_text = self.api.html_for_tweet(test_tweet_compat_object) # link to compat web status link