|
2 | 2 | import unittest
|
3 | 3 | from messagebird import Client, ErrorException
|
4 | 4 | from messagebird.base import Base
|
| 5 | +from messagebird.client import VOICE_TYPE |
5 | 6 |
|
6 | 7 | try:
|
7 | 8 | from unittest.mock import Mock
|
@@ -47,6 +48,68 @@ def test_call(self):
|
47 | 48 |
|
48 | 49 | self.assertEqual('ended', call.data.status)
|
49 | 50 |
|
| 51 | + def test_call_list(self): |
| 52 | + http_client = Mock() |
| 53 | + http_client.request.return_value = """ |
| 54 | + { |
| 55 | + "data":[ |
| 56 | + { |
| 57 | + "id":"dda20377-72da-4846-9b2c-0fea3ad4bcb6", |
| 58 | + "status":"no_answer", |
| 59 | + "source":"16479311111", |
| 60 | + "destination":"1416555555", |
| 61 | + "createdAt":"2019-08-06T13:17:06Z", |
| 62 | + "updatedAt":"2019-08-06T13:17:39Z", |
| 63 | + "endedAt":"2019-08-06T13:17:39Z", |
| 64 | + "_links":{ |
| 65 | + "legs":"/calls/dda20377-72da-4846-9b2c-0fea3ad4bcb6/legs", |
| 66 | + "self":"/calls/dda20377-72da-4846-9b2c-0fea3ad4bcb6" |
| 67 | + } |
| 68 | + }, |
| 69 | + { |
| 70 | + "id":"1541535b-9b80-4002-bde5-ed05b5ebed76", |
| 71 | + "status":"ended", |
| 72 | + "source":"16479311111", |
| 73 | + "destination":"1416555556", |
| 74 | + "createdAt":"2019-08-06T13:17:06Z", |
| 75 | + "updatedAt":"2019-08-06T13:17:39Z", |
| 76 | + "endedAt":"2019-08-06T13:17:39Z", |
| 77 | + "_links":{ |
| 78 | + "legs":"/calls/1541535b-9b80-4002-bde5-ed05b5ebed76/legs", |
| 79 | + "self":"/calls/1541535b-9b80-4002-bde5-ed05b5ebed76" |
| 80 | + } |
| 81 | + } |
| 82 | + ], |
| 83 | + "_links": { |
| 84 | + "self": "/calls?page=1" |
| 85 | + }, |
| 86 | + "pagination":{ |
| 87 | + "totalCount":2, |
| 88 | + "pageCount":1, |
| 89 | + "currentPage":1, |
| 90 | + "perPage":10 |
| 91 | + } |
| 92 | + } |
| 93 | + """ |
| 94 | + |
| 95 | + callList = Client('', http_client).call_list(page=1) |
| 96 | + |
| 97 | + http_client.request.assert_called_once_with('calls/?page=1', 'GET', None) |
| 98 | + |
| 99 | + # check data is processed |
| 100 | + self.assertEqual('no_answer', callList.data[0].status) |
| 101 | + self.assertEqual('ended', callList.data[1].status) |
| 102 | + |
| 103 | + # check pagination is passed to object |
| 104 | + self.assertEqual(2, callList.totalCount) |
| 105 | + self.assertEqual(1, callList.pageCount) |
| 106 | + self.assertEqual(1, callList.currentPage) |
| 107 | + self.assertEqual(10, callList.perPage) |
| 108 | + self.assertEqual(10, callList.pagination['perPage'], 'Check it also supports API pagination format.') |
| 109 | + |
| 110 | + self.assertEqual(0, callList.offset, 'Check it correctly calculates offset.') |
| 111 | + self.assertEqual(10, callList.limit, 'Check it correctly calculates limit.') |
| 112 | + |
50 | 113 | def test_call_create(self):
|
51 | 114 | api_response = {
|
52 | 115 | "data": [
|
@@ -102,6 +165,14 @@ def test_call_create(self):
|
102 | 165 | # check it can be formatted as string
|
103 | 166 | self.assertTrue(len(str(call_creation_response)) > 0, 'Check returned call can be formatted as string.')
|
104 | 167 |
|
| 168 | + def test_call_delete(self): |
| 169 | + http_client = Mock() |
| 170 | + http_client.request.return_value = '' |
| 171 | + call_id_to_delete = '21025ed1-cc1d-4554-ac05-043fa6c84e00' |
| 172 | + Client('', http_client).call_delete(call_id_to_delete) |
| 173 | + |
| 174 | + http_client.request.assert_called_once_with('calls/%s' % call_id_to_delete, 'DELETE', None) |
| 175 | + |
105 | 176 | @staticmethod
|
106 | 177 | def create_expected_call_data_based_on_api_response(api_response):
|
107 | 178 | expected_data = api_response['data'][0]
|
|
0 commit comments