X Tutup
Skip to content

Commit 2be0b5e

Browse files
committed
add tests for tweet changes
1 parent 2506bc4 commit 2be0b5e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"contributors": null, "in_reply_to_status_id_str": null, "lang": "en", "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>", "in_reply_to_user_id": null, "possibly_sensitive_appealable": false, "coordinates": null, "truncated": true, "retweet_count": 0, "retweeted": false, "possibly_sensitive": false, "in_reply_to_user_id_str": null, "entities": {"symbols": [], "user_mentions": [], "urls": [{"expanded_url": "https://twitter.com/i/web/status/782737772490600448", "indices": [117, 140], "url": "https://t.co/et3OTOxWSa", "display_url": "twitter.com/i/web/status/7\u2026"}], "hashtags": []}, "geo": null, "is_quote_status": false, "favorite_count": 0, "id_str": "782737772490600448", "id": 782737772490600448, "created_at": "Mon Oct 03 00:23:22 +0000 2016", "text": "has more details about these changes. Thanks for making more expressive!writing requirements to python_twitt pytho\u2026 https://t.co/et3OTOxWSa", "place": null, "in_reply_to_screen_name": null, "in_reply_to_status_id": null, "favorited": false, "user": {"follow_request_sent": false, "protected": true, "default_profile_image": true, "profile_sidebar_fill_color": "000000", "favourites_count": 1, "utc_offset": null, "has_extended_profile": false, "lang": "en", "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "friends_count": 2, "profile_text_color": "000000", "geo_enabled": true, "profile_banner_url": "https://pbs.twimg.com/profile_banners/4012966701/1453123196", "verified": false, "listed_count": 1, "is_translator": false, "location": "", "entities": {"description": {"urls": []}}, "name": "notinourselves", "is_translation_enabled": false, "time_zone": null, "id_str": "4012966701", "profile_background_tile": false, "followers_count": 1, "profile_sidebar_border_color": "000000", "contributors_enabled": false, "following": false, "description": "", "url": null, "statuses_count": 84, "default_profile": false, "profile_link_color": "000000", "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "notifications": false, "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/736320724164448256/LgaAQoav.jpg", "screen_name": "notinourselves", "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/736320724164448256/LgaAQoav.jpg", "id": 4012966701, "profile_use_background_image": true, "created_at": "Wed Oct 21 23:53:04 +0000 2015", "profile_background_color": "000000"}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"contributors": null, "in_reply_to_status_id_str": null, "lang": "en", "in_reply_to_user_id_str": null, "in_reply_to_user_id": null, "possibly_sensitive_appealable": false, "coordinates": null, "full_text": "has more details about these changes. Thanks for making more expressive!writing requirements to python_twitt python_twitter.egg-info/SOURCE https://t.co/JWSPztfoyt", "truncated": false, "retweet_count": 0, "retweeted": false, "possibly_sensitive": false, "entities": {"symbols": [], "media": [{"id_str": "782737766455119872", "type": "photo", "media_url_https": "https://pbs.twimg.com/media/CtzX2fnXEAAMAjK.jpg", "display_url": "pic.twitter.com/JWSPztfoyt", "sizes": {"large": {"w": 1024, "resize": "fit", "h": 1024}, "thumb": {"w": 150, "resize": "crop", "h": 150}, "small": {"w": 680, "resize": "fit", "h": 680}, "medium": {"w": 1024, "resize": "fit", "h": 1024}}, "expanded_url": "https://twitter.com/notinourselves/status/782737772490600448/photo/1", "indices": [141, 164], "id": 782737766455119872, "url": "https://t.co/JWSPztfoyt", "media_url": "http://pbs.twimg.com/media/CtzX2fnXEAAMAjK.jpg"}], "user_mentions": [], "urls": [], "hashtags": []}, "geo": null, "is_quote_status": false, "favorite_count": 0, "id_str": "782737772490600448", "extended_entities": {"media": [{"id_str": "782737766455119872", "type": "photo", "media_url_https": "https://pbs.twimg.com/media/CtzX2fnXEAAMAjK.jpg", "display_url": "pic.twitter.com/JWSPztfoyt", "sizes": {"large": {"w": 1024, "resize": "fit", "h": 1024}, "thumb": {"w": 150, "resize": "crop", "h": 150}, "small": {"w": 680, "resize": "fit", "h": 680}, "medium": {"w": 1024, "resize": "fit", "h": 1024}}, "expanded_url": "https://twitter.com/notinourselves/status/782737772490600448/photo/1", "indices": [141, 164], "id": 782737766455119872, "url": "https://t.co/JWSPztfoyt", "media_url": "http://pbs.twimg.com/media/CtzX2fnXEAAMAjK.jpg", "ext_alt_text": null}]}, "created_at": "Mon Oct 03 00:23:22 +0000 2016", "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>", "place": null, "favorited": false, "in_reply_to_screen_name": null, "in_reply_to_status_id": null, "id": 782737772490600448, "display_text_range": [0, 140], "user": {"follow_request_sent": false, "protected": true, "default_profile_image": true, "profile_sidebar_fill_color": "000000", "favourites_count": 1, "utc_offset": null, "has_extended_profile": false, "lang": "en", "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "friends_count": 2, "profile_text_color": "000000", "geo_enabled": true, "profile_banner_url": "https://pbs.twimg.com/profile_banners/4012966701/1453123196", "verified": false, "listed_count": 1, "is_translator": false, "location": "", "entities": {"description": {"urls": []}}, "name": "notinourselves", "is_translation_enabled": false, "time_zone": null, "id_str": "4012966701", "profile_background_tile": false, "followers_count": 1, "profile_sidebar_border_color": "000000", "contributors_enabled": false, "following": false, "description": "", "url": null, "statuses_count": 84, "default_profile": false, "profile_link_color": "000000", "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "notifications": false, "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/736320724164448256/LgaAQoav.jpg", "screen_name": "notinourselves", "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/736320724164448256/LgaAQoav.jpg", "id": 4012966701, "profile_use_background_image": true, "created_at": "Wed Oct 21 23:53:04 +0000 2015", "profile_background_color": "000000"}}

tests/test_tweet_changes.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import re
6+
import sys
7+
import unittest
8+
import warnings
9+
10+
import twitter
11+
12+
warnings.filterwarnings('ignore', category=DeprecationWarning)
13+
14+
import responses
15+
from responses import GET
16+
17+
DEFAULT_URL = re.compile(r'https?://.*\.twitter.com/1\.1/.*')
18+
19+
20+
class ModelsChangesTest(unittest.TestCase):
21+
"""Test how changes to tweets affect model creation"""
22+
23+
def setUp(self):
24+
self.api = twitter.Api(
25+
consumer_key='test',
26+
consumer_secret='test',
27+
access_token_key='test',
28+
access_token_secret='test',
29+
sleep_on_rate_limit=False)
30+
31+
@responses.activate
32+
def test_extended_in_compat_mode(self):
33+
"""API is in compatibility mode, but we call GetStatus on a tweet that
34+
was written in extended mode.
35+
36+
The tweet in question is exactly 140 characters and attaches a photo.
37+
38+
"""
39+
with open('testdata/3.2/extended_tweet_in_compat_mode.json') as f:
40+
resp_data = f.read()
41+
status = twitter.Status.NewFromJsonDict(json.loads(resp_data))
42+
self.assertTrue(status)
43+
self.assertEqual(status.id, 782737772490600448)
44+
self.assertEqual(status.text, "has more details about these changes. Thanks for making more expressive!writing requirements to python_twitt pytho… https://t.co/et3OTOxWSa")
45+
self.assertEqual(status.tweet_mode, 'compatibility')
46+
self.assertTrue(status.truncated)
47+
48+
@responses.activate
49+
def test_extended_in_extended_mode(self):
50+
"""API is in extended mode, and we call GetStatus on a tweet that
51+
was written in extended mode.
52+
53+
The tweet in question is exactly 140 characters and attaches a photo.
54+
55+
"""
56+
with open('testdata/3.2/extended_tweet_in_extended_mode.json') as f:
57+
resp_data = f.read()
58+
status = twitter.Status.NewFromJsonDict(json.loads(resp_data))
59+
self.assertTrue(status)
60+
self.assertEqual(status.id, 782737772490600448)
61+
self.assertEqual(status.full_text, "has more details about these changes. Thanks for making more expressive!writing requirements to python_twitt python_twitter.egg-info/SOURCE https://t.co/JWSPztfoyt")
62+
self.assertEqual(status.tweet_mode, 'extended')
63+
self.assertFalse(status.truncated)

0 commit comments

Comments
 (0)
X Tutup