|
5 | 5 | from vonage_http_client.http_client import HttpClient |
6 | 6 | from vonage_number_insight.errors import NumberInsightError |
7 | 7 | from vonage_number_insight.number_insight import NumberInsight |
8 | | -from vonage_number_insight.requests import BasicInsightRequest |
| 8 | +from vonage_number_insight.requests import ( |
| 9 | + AdvancedAsyncInsightRequest, |
| 10 | + AdvancedSyncInsightRequest, |
| 11 | + BasicInsightRequest, |
| 12 | + StandardInsightRequest, |
| 13 | +) |
9 | 14 |
|
10 | 15 | from testutils import build_response, get_mock_api_key_auth |
11 | 16 |
|
@@ -47,4 +52,107 @@ def test_basic_insight_error(): |
47 | 52 | options = BasicInsightRequest(number='1234567890', country_code='US') |
48 | 53 | number_insight.basic_number_insight(options) |
49 | 54 | assert e.match('Invalid request :: Not valid number format detected') |
50 | | - assert 0 |
| 55 | + |
| 56 | + |
| 57 | +@responses.activate |
| 58 | +def test_standard_insight(): |
| 59 | + build_response( |
| 60 | + path, |
| 61 | + 'GET', |
| 62 | + 'https://api.nexmo.com/ni/standard/json', |
| 63 | + 'standard_insight.json', |
| 64 | + ) |
| 65 | + options = StandardInsightRequest(number='12345678900', country_code='US', cnam=True) |
| 66 | + response = number_insight.standard_number_insight(options) |
| 67 | + assert response.status == 0 |
| 68 | + assert response.status_message == 'Success' |
| 69 | + assert response.current_carrier.network_code == '23415' |
| 70 | + assert response.original_carrier.network_type == 'mobile' |
| 71 | + assert response.caller_identity.caller_name == 'John Smith' |
| 72 | + |
| 73 | + |
| 74 | +@responses.activate |
| 75 | +def test_advanced_async_insight(): |
| 76 | + build_response( |
| 77 | + path, |
| 78 | + 'GET', |
| 79 | + 'https://api.nexmo.com/ni/advanced/async/json', |
| 80 | + 'advanced_async_insight.json', |
| 81 | + ) |
| 82 | + options = AdvancedAsyncInsightRequest( |
| 83 | + callback='https://example.com/callback', |
| 84 | + number='447700900000', |
| 85 | + country_code='GB', |
| 86 | + cnam=True, |
| 87 | + ) |
| 88 | + response = number_insight.advanced_async_number_insight(options) |
| 89 | + assert response.status == 0 |
| 90 | + assert response.request_id == '434205b5-90ec-4ee2-a337-7b40d9683420' |
| 91 | + assert response.number == '447700900000' |
| 92 | + assert response.remaining_balance == '32.92665294' |
| 93 | + |
| 94 | + |
| 95 | +@responses.activate |
| 96 | +def test_advanced_async_insight_error(): |
| 97 | + build_response( |
| 98 | + path, |
| 99 | + 'GET', |
| 100 | + 'https://api.nexmo.com/ni/advanced/async/json', |
| 101 | + 'advanced_async_insight_error.json', |
| 102 | + ) |
| 103 | + |
| 104 | + options = AdvancedAsyncInsightRequest( |
| 105 | + callback='https://example.com/callback', |
| 106 | + number='447700900000', |
| 107 | + country_code='GB', |
| 108 | + cnam=True, |
| 109 | + ) |
| 110 | + with raises(NumberInsightError) as e: |
| 111 | + number_insight.advanced_async_number_insight(options) |
| 112 | + assert e.match('Invalid credentials') |
| 113 | + |
| 114 | + |
| 115 | +@responses.activate |
| 116 | +def test_advanced_async_insight_partial_error(caplog): |
| 117 | + build_response( |
| 118 | + path, |
| 119 | + 'GET', |
| 120 | + 'https://api.nexmo.com/ni/advanced/async/json', |
| 121 | + 'advanced_async_insight_partial_error.json', |
| 122 | + ) |
| 123 | + |
| 124 | + options = AdvancedAsyncInsightRequest( |
| 125 | + callback='https://example.com/callback', |
| 126 | + number='447700900000', |
| 127 | + country_code='GB', |
| 128 | + cnam=True, |
| 129 | + ) |
| 130 | + response = number_insight.advanced_async_number_insight(options) |
| 131 | + assert 'Not all parameters are available' in caplog.text |
| 132 | + assert response.status == 43 |
| 133 | + |
| 134 | + |
| 135 | +@responses.activate |
| 136 | +def test_advanced_sync_insight(caplog): |
| 137 | + build_response( |
| 138 | + path, |
| 139 | + 'GET', |
| 140 | + 'https://api.nexmo.com/ni/advanced/json', |
| 141 | + 'advanced_sync_insight.json', |
| 142 | + ) |
| 143 | + options = AdvancedSyncInsightRequest( |
| 144 | + number='12345678900', country_code='US', cnam=True, real_time_data=True |
| 145 | + ) |
| 146 | + response = number_insight.advanced_sync_number_insight(options) |
| 147 | + |
| 148 | + assert 'Not all parameters are available' in caplog.text |
| 149 | + assert response.status == 44 |
| 150 | + assert response.request_id == '97e973e7-2e27-4fd3-9e1a-972ea14dd992' |
| 151 | + assert response.current_carrier.network_code == '310090' |
| 152 | + assert response.first_name == 'John' |
| 153 | + assert response.last_name == 'Smith' |
| 154 | + assert response.lookup_outcome == 1 |
| 155 | + assert response.lookup_outcome_message == 'Partial success - some fields populated' |
| 156 | + assert response.roaming == 'unknown' |
| 157 | + assert response.status_message == 'Lookup Handler unable to handle request' |
| 158 | + assert response.valid_number == 'valid' |
0 commit comments