Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions examples/verify_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import messagebird

# ACCESS_KEY = ''
# VERIFY_ID = ''

try:
ACCESS_KEY
except NameError:
print('You need to set an ACCESS_KEY constant in this file')
sys.exit(1)

try:
VERIFY_ID
except NameError:
print('You need to set a VERIFY_ID constant in this file')
sys.exit(1)

try:
# Create a MessageBird client with the specified ACCESS_KEY.
client = messagebird.Client(ACCESS_KEY)

# Delete a Verification object.
client.verify_delete(VERIFY_ID)

except messagebird.client.ErrorException as e:
print('\nAn error occured while requesting a Verify object:\n')

for error in e.errors:
print(' code : %d' % error.code)
print(' description : %s' % error.description)
print(' parameter : %s\n' % error.parameter)
4 changes: 4 additions & 0 deletions messagebird/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def verify_verify(self, id, token):
"""Verify the token of a specific verification."""
return Verify().load(self.request('verify/' + str(id), params={'token': token}))

def verify_delete(self, id):
"""Delete an existing verification object."""
self.request_plain_text('verify/' + str(id), 'DELETE')

def contact(self, id):
"""Retrieve the information of a specific contact."""
return Contact().load(self.request('contacts/' + str(id)))
Expand Down
20 changes: 19 additions & 1 deletion tests/test_verify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from messagebird import Client
from messagebird import Client, ErrorException

try:
from unittest.mock import Mock
Expand Down Expand Up @@ -38,3 +38,21 @@ def test_verify_verify(self):
http_client.request.assert_called_once_with('verify/verify-id', 'GET', {'token': 'secret'})

self.assertEqual('verified', verify.status)

def test_verify_delete(self):
http_client = Mock()
http_client.request.return_value = ''

Client('', http_client).verify_delete('31612345678')

http_client.request.assert_called_once_with('verify/31612345678', 'DELETE', None)

def test_verify_delete_invalid(self):
http_client = Mock()
http_client.request.return_value = '{"errors": [{"code": 20,"description": "verification id not found","parameter": null}]}'

with self.assertRaises(ErrorException):
Client('', http_client).verify_delete('non-existent-verify-id')

http_client.request.assert_called_once_with('verify/non-existent-verify-id', 'DELETE', None)