forked from bear/python-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_direct_messages.py
73 lines (56 loc) · 2.17 KB
/
test_direct_messages.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import json
import os
import re
import sys
from tempfile import NamedTemporaryFile
import unittest
try:
from unittest.mock import patch
except ImportError:
from mock import patch
import warnings
import twitter
import responses
from responses import GET, POST
DEFAULT_URL = re.compile(r'https?://.*\.twitter.com/1\.1/.*')
global api
api = twitter.Api('test', 'test', 'test', 'test', tweet_mode='extended')
@responses.activate
def test_get_direct_messages():
with open('testdata/direct_messages/get_direct_messages.json') as f:
resp_data = f.read()
responses.add(GET, DEFAULT_URL, body=resp_data)
resp = api.GetDirectMessages()
direct_message = resp[0]
assert isinstance(resp, list)
assert isinstance(direct_message, twitter.DirectMessage)
assert direct_message.id == 678629245946433539
@responses.activate
def test_get_sent_direct_messages():
with open('testdata/direct_messages/get_sent_direct_messages.json') as f:
resp_data = f.read()
responses.add(GET, DEFAULT_URL, body=resp_data)
resp = api.GetSentDirectMessages()
direct_message = resp[0]
assert isinstance(resp, list)
assert isinstance(direct_message, twitter.DirectMessage)
assert direct_message.id == 678629283007303683
assert [dm.sender_screen_name == 'notinourselves' for dm in resp]
@responses.activate
def test_post_direct_message():
with open('testdata/direct_messages/post_post_direct_message.json', 'r') as f:
responses.add(POST, DEFAULT_URL, body=f.read())
resp = api.PostDirectMessage(screen_name='TheGIFingBot',
text='https://t.co/L4MIplKUwR')
assert isinstance(resp, twitter.DirectMessage)
assert resp.text == 'https://t.co/L4MIplKUwR'
@responses.activate
def test_destroy_direct_message():
with open('testdata/direct_messages/post_destroy_direct_message.json', 'r') as f:
responses.add(POST, DEFAULT_URL, body=f.read())
resp = api.DestroyDirectMessage(message_id=855194351294656515)
assert isinstance(resp, twitter.DirectMessage)
assert resp.id == 855194351294656515