forked from Vonage/vonage-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_account.py
More file actions
230 lines (173 loc) · 7.01 KB
/
Copy pathtest_account.py
File metadata and controls
230 lines (173 loc) · 7.01 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import platform
from glom import glom
from util import *
import nexmo
@responses.activate
def test_get_balance(client, dummy_data):
stub(responses.GET, "https://rest.nexmo.com/account/get-balance")
assert isinstance(client.get_balance(), dict)
assert request_user_agent() == dummy_data.user_agent
@responses.activate
def test_application_info_options(dummy_data):
app_name, app_version = "ExampleApp", "X.Y.Z"
stub(responses.GET, "https://rest.nexmo.com/account/get-balance")
client = nexmo.Client(
key=dummy_data.api_key,
secret=dummy_data.api_secret,
app_name=app_name,
app_version=app_version,
)
user_agent = "nexmo-python/{} python/{} {}/{}".format(
nexmo.__version__,
platform.python_version(),
app_name,
app_version,
)
assert isinstance(client.get_balance(), dict)
assert request_user_agent() == user_agent
@responses.activate
def test_get_country_pricing(client, dummy_data):
stub(responses.GET, "https://rest.nexmo.com/account/get-pricing/outbound")
assert isinstance(client.get_country_pricing("GB"), dict)
assert request_user_agent() == dummy_data.user_agent
assert "country=GB" in request_query()
@responses.activate
def test_get_prefix_pricing(client, dummy_data):
stub(responses.GET, "https://rest.nexmo.com/account/get-prefix-pricing/outbound")
assert isinstance(client.get_prefix_pricing(44), dict)
assert request_user_agent() == dummy_data.user_agent
assert "prefix=44" in request_query()
@responses.activate
def test_get_sms_pricing(client, dummy_data):
stub(responses.GET, "https://rest.nexmo.com/account/get-phone-pricing/outbound/sms")
assert isinstance(client.get_sms_pricing("447525856424"), dict)
assert request_user_agent() == dummy_data.user_agent
assert "phone=447525856424" in request_query()
@responses.activate
def test_get_voice_pricing(client, dummy_data):
stub(
responses.GET, "https://rest.nexmo.com/account/get-phone-pricing/outbound/voice"
)
assert isinstance(client.get_voice_pricing("447525856424"), dict)
assert request_user_agent() == dummy_data.user_agent
assert "phone=447525856424" in request_query()
@responses.activate
def test_update_settings(client, dummy_data):
stub(responses.POST, "https://rest.nexmo.com/account/settings")
params = {"moCallBackUrl": "http://example.com/callback"}
assert isinstance(client.update_settings(params), dict)
assert request_user_agent() == dummy_data.user_agent
assert "moCallBackUrl=http%3A%2F%2Fexample.com%2Fcallback" in request_body()
@responses.activate
def test_topup(client, dummy_data):
stub(responses.POST, "https://rest.nexmo.com/account/top-up")
params = {"trx": "00X123456Y7890123Z"}
assert isinstance(client.topup(params), dict)
assert request_user_agent() == dummy_data.user_agent
assert "trx=00X123456Y7890123Z" in request_body()
@responses.activate
def test_get_account_numbers(client, dummy_data):
stub(responses.GET, "https://rest.nexmo.com/account/numbers")
assert isinstance(client.get_account_numbers(size=25), dict)
assert request_user_agent() == dummy_data.user_agent
assert request_params()["size"] == ["25"]
@responses.activate
def test_list_secrets(client):
stub(
responses.GET,
"https://api.nexmo.com/accounts/meaccountid/secrets",
fixture_path="account/secret_management/list.json",
)
secrets = client.list_secrets("meaccountid")
assert_basic_auth()
assert (
glom(secrets, "_embedded.secrets.0.id")
== "ad6dc56f-07b5-46e1-a527-85530e625800"
)
@responses.activate
def test_list_secrets_missing(client):
stub(
responses.GET,
"https://api.nexmo.com/accounts/meaccountid/secrets",
status_code=404,
fixture_path="account/secret_management/missing.json",
)
with pytest.raises(nexmo.ClientError) as ce:
client.list_secrets("meaccountid")
assert_basic_auth()
assert (
"""ClientError: Invalid API Key: API key 'ABC123' does not exist, or you do not have access (https://developer.nexmo.com/api-errors#invalid-api-key)"""
in str(ce)
)
@responses.activate
def test_get_secret(client):
stub(
responses.GET,
"https://api.nexmo.com/accounts/meaccountid/secrets/mahsecret",
fixture_path="account/secret_management/get.json",
)
secret = client.get_secret("meaccountid", "mahsecret")
assert_basic_auth()
assert secret["id"] == "ad6dc56f-07b5-46e1-a527-85530e625800"
@responses.activate
def test_delete_secret(client):
stub(
responses.DELETE, "https://api.nexmo.com/accounts/meaccountid/secrets/mahsecret"
)
client.delete_secret("meaccountid", "mahsecret")
assert_basic_auth()
@responses.activate
def test_delete_secret_last_secret(client):
stub(
responses.DELETE,
"https://api.nexmo.com/accounts/meaccountid/secrets/mahsecret",
status_code=403,
fixture_path="account/secret_management/last-secret.json",
)
with pytest.raises(nexmo.ClientError) as ce:
client.delete_secret("meaccountid", "mahsecret")
assert_basic_auth()
assert (
"""ClientError: Secret Deletion Forbidden: Can not delete the last secret. The account must always have at least 1 secret active at any time (https://developer.nexmo.com/api-errors/account/secret-management#delete-last-secret)"""
in str(ce)
)
@responses.activate
def test_create_secret(client):
stub(
responses.POST,
"https://api.nexmo.com/accounts/meaccountid/secrets",
fixture_path="account/secret_management/create.json",
)
secret = client.create_secret("meaccountid", "mahsecret")
assert_basic_auth()
assert secret["id"] == "ad6dc56f-07b5-46e1-a527-85530e625800"
@responses.activate
def test_create_secret_max_secrets(client):
stub(
responses.POST,
"https://api.nexmo.com/accounts/meaccountid/secrets",
status_code=403,
fixture_path="account/secret_management/max-secrets.json",
)
with pytest.raises(nexmo.ClientError) as ce:
client.create_secret("meaccountid", "mahsecret")
assert_basic_auth()
assert (
"""ClientError: Maxmimum number of secrets already met: This account has reached maximum number of '2' allowed secrets (https://developer.nexmo.com/api-errors/account/secret-management#maximum-secrets-allowed)"""
in str(ce)
)
@responses.activate
def test_create_secret_validation(client):
stub(
responses.POST,
"https://api.nexmo.com/accounts/meaccountid/secrets",
status_code=400,
fixture_path="account/secret_management/create-validation.json",
)
with pytest.raises(nexmo.ClientError) as ce:
client.create_secret("meaccountid", "mahsecret")
assert_basic_auth()
assert (
"""ClientError: Bad Request: The request failed due to validation errors (https://developer.nexmo.com/api-errors/account/secret-management#validation)"""
in str(ce)
)