-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtest_messages.py
More file actions
109 lines (92 loc) · 4.26 KB
/
Copy pathtest_messages.py
File metadata and controls
109 lines (92 loc) · 4.26 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
# -*- coding: utf-8 -*-
from plivo import exceptions
from tests.base import PlivoResourceTestCase
from tests.decorators import with_response
class MessageTest(PlivoResourceTestCase):
def test_send_message(self):
expected_response = {'message_uuid': 'adsdafkjadshf123123'}
self.client.set_expected_response(
status_code=202, data_to_return=expected_response)
test_message = self.client.messages.create(
src='1234', dst='12345', text='Abcd')
self.assertEqual(
self.client.current_request.url,
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Message/')
self.assertEqual(self.client.current_request.method, 'POST')
self.assertEqual(test_message.message_uuid,
expected_response['message_uuid'])
def test_send_message_with_allow_dtmf(self):
expected_response = {'message_uuid': 'adsdafkjadshf123123'}
self.client.set_expected_response(
status_code=202, data_to_return=expected_response)
test_message = self.client.messages.create(
src='1234', dst='12345', text='Abcd', allow_dtmf=True)
self.assertEqual(
self.client.current_request.url,
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Message/')
self.assertEqual(self.client.current_request.method, 'POST')
self.assertEqual(test_message.message_uuid,
expected_response['message_uuid'])
def test_send_message_same_src_dst(self):
self.assertRaises(
exceptions.ValidationError,
self.client.messages.create,
src='1234',
dst='1234',
text='Abcd')
def test_send_message_with_powerpack(self):
expected_response = {'message_uuid': 'adsdafkjadshf123123'}
self.client.set_expected_response(
status_code=202, data_to_return=expected_response)
test_message = self.client.messages.create(
powerpack_uuid='1234', dst='12345', text='Abcd')
self.assertEqual(
self.client.current_request.url,
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Message/')
self.assertEqual(self.client.current_request.method, 'POST')
self.assertEqual(test_message.message_uuid,
expected_response['message_uuid'])
def test_send_message_with_both_src_powerpack(self):
self.assertRaises(
exceptions.ValidationError,
self.client.messages.create,
powerpack_uuid='1234',
src='1234',
dst='1234',
text='Abcd')
def test_send_message_with_no_src_powerpack(self):
self.assertRaises(
exceptions.ValidationError,
self.client.messages.create,
dst='1234',
text='Abcd')
@with_response(200)
def test_get(self):
message_uuid = 'message_uuid'
message = self.client.messages.get(message_uuid)
self.assertResponseMatches(message)
self.assertUrlEqual(self.client.current_request.url,
self.get_url('Message', message_uuid))
self.assertEqual(self.client.current_request.method, 'GET')
@with_response(200)
def test_list_media(self):
message_uuid = 'message_uuid'
message = self.client.messages.get(message_uuid).listMedia()
self.assertResponseMatches(message)
self.assertUrlEqual(self.client.current_request.url,
self.get_url('Message', message_uuid, 'Media'))
self.assertEqual(self.client.current_request.method, 'GET')
@with_response(200, method_name='get')
def test_response_has_user_agent(self):
message_uuid = 'message_uuid'
self.client.messages.get(message_uuid)
self.assertIn('plivo-python',
self.client.current_request.headers['User-Agent'])
@with_response(200)
def test_list(self):
messages = self.client.messages.list()
# Test if ListResponseObject's __iter__ is working correctly
self.assertEqual(len(list(messages)), 20)
self.assertUrlEqual(self.client.current_request.url,
self.get_url('Message'))
self.assertEqual(self.client.current_request.method, 'GET')