This repository was archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 932
Expand file tree
/
Copy pathtest_status_place.py
More file actions
54 lines (43 loc) · 1.58 KB
/
Copy pathtest_status_place.py
File metadata and controls
54 lines (43 loc) · 1.58 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
import unittest
import re
import sys
import twitter
import responses
from responses import GET, POST
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 ApiPlaceTest(unittest.TestCase):
def setUp(self):
self.api = twitter.Api(
consumer_key='test',
consumer_secret='test',
access_token_key='test',
access_token_secret='test'
)
self.base_url = 'https://api.twitter.com/1.1'
self._stderr = sys.stderr
sys.stderr = ErrNull()
def tearDown(self):
sys.stderr = self._stderr
pass
@responses.activate
def testGetStatusWithPlace(self):
with open('testdata/get_status_with_place.json') as f:
resp_data = f.read()
responses.add(GET, DEFAULT_URL, body=resp_data)
resp = self.api.GetStatus(1051204790334746624)
self.assertTrue(isinstance(resp, twitter.Status))
self.assertTrue(isinstance(resp.place, twitter.Place))
self.assertEqual(resp.id, 1051204790334746624)
@responses.activate
def testPostUpdateWithPlace(self):
with open('testdata/post_update_with_place.json') as f:
resp_data = f.read()
responses.add(POST, DEFAULT_URL, body=resp_data, status=200)
post = self.api.PostUpdate('test place', place_id='07d9db48bc083000')
self.assertEqual(post.place.id, '07d9db48bc083000')