forked from bear/python-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tweet_length.py
74 lines (65 loc) · 4.17 KB
/
test_tweet_length.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# encoding: utf-8
import unittest
import twitter
class TestTweetLength(unittest.TestCase):
def setUp(self):
self.api = twitter.Api(consumer_key='test',
consumer_secret='test',
access_token_key='test',
access_token_secret='test')
self.api._config = {'short_url_length_https': 23}
def test_find_urls(self):
url = "http://example.com"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "https://example.com/path/to/resource?search=foo&lang=en"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "http://twitter.com/#!/twitter"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "HTTPS://www.ExaMPLE.COM/index.html"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
# url = "http://user:PASSW0RD@example.com:8080/login.php"
# self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "http://sports.yahoo.com/nfl/news;_ylt=Aom0;ylu=XyZ?slug=ap-superbowlnotebook"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
# url = "http://192.168.0.1/index.html?src=asdf"
# self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
# Have to figure out what a valid IPv6 range looks like, then
# uncomment this.
# url = "http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:80/index.html"
# self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "http://test_underscore.twitter.com"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "http://example.com?foo=$bar.;baz?BAZ&c=d-#top/?stories+"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "https://www.youtube.com/playlist?list=PL0ZPu8XSRTB7wZzn0mLHMvyzVFeRxbWn-"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "example.com"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "www.example.com"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "foo.co.jp foo.co.jp foo.co.jp"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "example.com/path/to/resource?search=foo&lang=en"
self.assertTrue(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "hello index.html my friend"
self.assertFalse(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
url = "run.on.sentence"
self.assertFalse(twitter.twitter_utils.is_url(url), "'{0}'".format(url))
def test_split_tweets(self):
test_tweet = (
"Anatole went out of the room and returned a few minutes later "
"wearing a fur coat girt with a silver belt, and a sable cap "
"jauntily set on one side and very becoming to his handsome face. "
"Having looked in a mirror, and standing before Dolokhov in the "
"same pose he had assumed before it, he lifted a glass of wine.")
tweets = self.api._TweetTextWrap(test_tweet)
self.assertEqual(
tweets[0],
"Anatole went out of the room and returned a few minutes later wearing a fur coat girt with a silver belt, and a sable cap jauntily set on one side and very becoming to his handsome face. Having looked in a mirror, and standing before Dolokhov in the same pose he had assumed")
self.assertEqual(
tweets[1],
"before it, he lifted a glass of wine.")
test_tweet = "t.co went t.co of t.co room t.co returned t.co few minutes later and then t.co went to t.co restroom and t.co was sad because t.co did not have any t.co toilet paper"
tweets = self.api._TweetTextWrap(test_tweet)
self.assertEqual(tweets[0], 't.co went t.co of t.co room t.co returned t.co few minutes later and then t.co went to t.co restroom and t.co was sad because')
self.assertEqual(tweets[1], 't.co did not have any t.co toilet paper')