forked from bear/python-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unicode.py
More file actions
112 lines (91 loc) · 2.97 KB
/
test_unicode.py
File metadata and controls
112 lines (91 loc) · 2.97 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# encoding: utf-8
import json
import pickle
import re
import sys
import unittest
import warnings
import responses
from hypothesis import given, example
from hypothesis import strategies as st
import twitter
warnings.filterwarnings('ignore', category=DeprecationWarning)
DEFAULT_URL = re.compile(r'https?://.*\.twitter.com/1\.1/.*')
class ErrNull(object):
""" Suppress output of tests while writing to stdout or stderr. This just
takes in data and does nothing with it.
"""
def write(self, data):
pass
class ApiTest(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self.api = twitter.Api(
consumer_key='test',
consumer_secret='test',
access_token_key='test',
access_token_secret='test',
sleep_on_rate_limit=False)
self.base_url = 'https://api.twitter.com/1.1'
self._stderr = sys.stderr
sys.stderr = ErrNull()
def tearDown(self):
sys.stderr = self._stderr
pass
@given(text=st.text())
@example(text="#نفسك_تبيع_ايه_للسعوديه")
def test_trend_repr1(self, text):
trend = twitter.Trend(
name=text,
url="http://twitter.com/search?q=%23ChangeAConsonantSpoilAMovie",
timestamp='whatever')
try:
trend.__repr__()
except Exception as e:
self.fail(e)
@given(text=st.text())
@example(text="#N\u00e3oD\u00eaUnfTagueirosSdv")
def test_trend_repr2(self, text):
trend = twitter.Trend(
url='http://twitter.com/search?q=%23ChangeAConsonantSpoilAMovie',
timestamp='whatever')
try:
trend.__repr__()
except Exception as e:
self.fail(e)
@responses.activate
def test_trend_repr3(self):
with open('testdata/get_trends_current_unicode.json', 'r') as f:
resp_data = f.read()
responses.add(
responses.GET, DEFAULT_URL, body=resp_data, match_querystring=True)
resp = self.api.GetTrendsCurrent()
for r in resp:
try:
r.__repr__()
except Exception as e:
self.fail(e)
@given(text=st.text())
@responses.activate
def test_unicode_get_search(self, text):
responses.add(responses.GET, DEFAULT_URL, body=b'{}', status=200)
try:
self.api.GetSearch(term=text)
except Exception as e:
self.fail(e)
@given(text=st.text())
@example(text='可以倒着飞的飞机')
def test_constructed_status(self, text):
s = twitter.Status()
s.text = text
s.created_at = "016-02-13T23:00:00"
s.screen_name = "himawari8bot"
s.id = 1
try:
s.__repr__()
except Exception as e:
self.fail(e)
def test_post_with_bytes_string(self):
status = 'x'
length = twitter.twitter_utils.calc_expected_status_length(status)
assert length == 1