8000 Support for deleting and redacting Messages · Twilio-api/twilio-python@b000528 · GitHub
[go: up one dir, main page]

Skip to content

Commit b000528

Browse files
committed
Support for deleting and redacting Messages
1 parent 684fc12 commit b000528

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

tests/test_messages.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date
22
import unittest
33

4-
from mock import Mock
4+
from mock import Mock, patch
55
from six import u
66

77
from twilio.rest.resources import Messages
@@ -21,34 +21,44 @@ def setUp(self):
2121
self.params = DEFAULT.copy()
2222

2323
def test_list_on(self):
24-
self.resource.get_instances = Mock()
25-
self.resource.list(date_sent=date(2011, 1, 1))
26-
self.params['DateSent'] = "2011-01-01"
27-
self.resource.get_instances.assert_called_with(self.params)
24+
with patch.object(self.resource, 'get_instances') as mock:
25+
self.resource.list(date_sent=date(2011, 1, 1))
26+
self.params['DateSent'] = "2011-01-01"
27+
mock.assert_called_with(self.params)
2828

2929
def test_list_after(self):
30-
self.resource.get_instances = Mock()
31-
self.resource.list(after=date(2011, 1, 1))
32-
self.params['DateSent>'] = "2011-01-01"
33-
self.resource.get_instances.assert_called_with(self.params)
30+
with patch.object(self.resource, 'get_instances') as mock:
31+
self.resource.list(after=date(2011, 1, 1))
32+
self.params['DateSent>'] = "2011-01-01"
33+
mock.assert_called_with(self.params)
3434

3535
def test_list_before(self):
36-
self.resource.get_instances = Mock()
37-
self.resource.list(before=date(2011, 1, 1))
38-
self.params['DateSent<'] = "2011-01-01"
39-
self.resource.get_instances.assert_called_with(self.params)
36+
with patch.object(self.resource, 'get_instances') as mock:
37+
self.resource.list(before=date(2011, 1, 1))
38+
self.params['DateSent<'] = "2011-01-01"
39+
mock.assert_called_with(self.params)
4040

4141
def test_create(self):
42-
self.resource.create_instance = Mock()
43-
self.resource.create(
44-
from_='+14155551234',
45-
to='+14155556789',
46-
body=u('ahoy hoy'),
47-
)
48-
self.resource.create_instance.assert_called_with(
49-
{
50-
'from': '+14155551234',
51-
'to': '+14155556789',
52-
'body': u('ahoy hoy'),
53-
},
54-
)
42+
with patch.object(self.resource, 'create_instance') as mock:
43+
self.resource.create(
44+
from_='+14155551234',
45+
to='+14155556789',
46+
body=u('ahoy hoy'),
47+
)
48+
mock.assert_called_with(
49+
{
50+
'from': '+14155551234',
51+
'to': '+14155556789',
52+
'body': u('ahoy hoy'),
53+
},
54+
)
55+
56+
def test_delete(self):
57+
with patch.object(self.resource, 'delete_instance') as mock:
58+
self.resource.delete('MM123')
59+
mock.assert_called_with('MM123')
60+
61+
def test_redact(self):
62+
with patch.object(self.resource, 'update_instance') as mock:
63+
self.resource.redact('MM123')
64+
mock.assert_called_with('MM123', {'Body': ''})

twilio/rest/resources/messages.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ class Message(InstanceResource):
8686

8787
subresources = [MediaList]
8888

89+
def delete(self):
90+
"""Delete this Message record from Twilio."""
91+
return self.parent.delete(self.sid)
92+
93+
def redact(self):
94+
"""Redact this Message's `body` field from Twilio while preserving
95+
the record itself and related metadata.
96+
"""
97+
return self.parent.redact(self.sid)
98+
8999

90100
class Messages(ListResource):
91101
name = "Messages"
@@ -137,3 +147,11 @@ def update(self, sid, **kwargs):
137147
:param sid: The sid of the message to update.
138148
"""
139149
return self.update_instance(sid, kwargs)
150+
151+
def delete(self, sid):
152+
"""Delete the specified Message record from Twilio."""
153+
return self.delete_instance(sid)
154+
155+
def redact(self, sid):
156+
"""Redact the specified Message record's Body field."""
157+
return self.update_instance(sid, {'Body': ''})

0 commit comments

Comments
 (0)
0