Skip to content

Commit 4d53afa

Browse files
committed
add pricing api testing
1 parent 4717e7d commit 4d53afa

9 files changed

+228
-4
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,35 @@ settings: SettingsResponse = vonage_client.account.update_default_sms_webhook(
158158
print(settings)
159159
```
160160

161+
### Get Service Pricing for a Specific Country
162+
163+
```python
164+
from vonage_account import GetCountryPricingRequest
165+
166+
response = vonage_client.account.get_country_pricing(
167+
GetCountryPricingRequest(type='sms', country_code='US')
168+
)
169+
print(response)
170+
```
171+
172+
### Get Service Pricing for All Countries
173+
174+
```python
175+
response = vonage_client.account.get_all_countries_pricing(service_type='sms')
176+
print(response)
177+
```
178+
179+
### Get Service Pricing by Dialing Prefix
180+
181+
```python
182+
from vonage_account import GetPrefixPricingRequest
183+
184+
response = client.account.get_prefix_pricing(
185+
GetPrefixPricingRequest(prefix='44', type='sms')
186+
)
187+
print(response)
188+
```
189+
161190
### List Secrets Associated with the Account
162191

163192
```python

account/CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# 1.0.3
1+
# 1.1.0
2+
- Add support for the [Vonage Pricing API](https://developer.vonage.com/en/api/pricing)
23
- Update dependency versions
34

45
# 1.0.2

account/src/vonage_account/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from .requests import GetCountryPricingRequest, GetPrefixPricingRequest, ServiceType
44
from .responses import (
55
Balance,
6-
GetPricingResponse,
76
GetMultiplePricingResponse,
7+
GetPricingResponse,
88
NetworkPricing,
99
SettingsResponse,
1010
TopUpResponse,
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.3'
1+
__version__ = '1.1.0'

account/src/vonage_account/requests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from pydantic import BaseModel
21
from enum import Enum
32

3+
from pydantic import BaseModel
4+
45

56
class ServiceType(str, Enum):
67
"""The service you wish to retrieve outbound pricing data about.

account/src/vonage_account/responses.py

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class NetworkPricing(BaseModel):
6565
network_name (str, Optional): The network name.
6666
price (str, Optional): The price for the service.
6767
type (str, Optional): The type of service.
68+
ranges (str, Optional): Number ranges.
6869
"""
6970

7071
aliases: Optional[list[str]] = None
@@ -75,6 +76,7 @@ class NetworkPricing(BaseModel):
7576
network_name: Optional[str] = Field(None, validation_alias='networkName')
7677
price: Optional[str] = None
7778
type: Optional[str] = None
79+
ranges: Optional[list[int]] = None
7880

7981

8082
class GetPricingResponse(BaseModel):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"dialingPrefix": "260",
3+
"defaultPrice": "0.28725000",
4+
"currency": "EUR",
5+
"countryDisplayName": "Zambia",
6+
"countryCode": "ZM",
7+
"countryName": "Zambia",
8+
"networks": [
9+
{
10+
"type": "landline_premium",
11+
"price": "0.28725000",
12+
"currency": "EUR",
13+
"ranges": [
14+
26090
15+
],
16+
"networkCode": "ZM-PREMIUM",
17+
"networkName": "Zambia Premium"
18+
},
19+
{
20+
"type": "mobile",
21+
"price": "0.28725000",
22+
"currency": "EUR",
23+
"ranges": [
24+
2607,
25+
26076,
26+
26096
27+
],
28+
"mcc": "645",
29+
"mnc": "02",
30+
"networkCode": "64502",
31+
"networkName": "MTN Zambia"
32+
},
33+
{
34+
"type": "mobile",
35+
"price": "0.28725000",
36+
"currency": "EUR",
37+
"ranges": [
38+
26077,
39+
26097
40+
],
41+
"mcc": "645",
42+
"mnc": "01",
43+
"networkCode": "64501",
44+
"networkName": "Airtel"
45+
},
46+
{
47+
"type": "landline_tollfree",
48+
"price": "0.28725000",
49+
"currency": "EUR",
50+
"ranges": [
51+
2608
52+
],
53+
"networkCode": "ZM-TOLL-FREE",
54+
"networkName": "Zambia Toll Free"
55+
},
56+
{
57+
"type": "landline",
58+
"price": "0.28725000",
59+
"currency": "EUR",
60+
"ranges": [
61+
2602
62+
],
63+
"networkCode": "ZM-FIXED",
64+
"networkName": "Zambia Landline"
65+
},
66+
{
67+
"type": "mobile",
68+
"price": "0.28725000",
69+
"currency": "EUR",
70+
"ranges": [
71+
26095
72+
],
73+
"mcc": "645",
74+
"mnc": "03",
75+
"networkCode": "64503",
76+
"networkName": "Zamtel"
77+
}
78+
]
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"count": 2,
3+
"countries": [
4+
{
5+
"dialingPrefix": "39",
6+
"defaultPrice": "0.08270000",
7+
"currency": "EUR",
8+
"countryDisplayName": "Italy",
9+
"countryCode": "IT",
10+
"countryName": "Italy",
11+
"networks": [
12+
{
13+
"type": "mobile",
14+
"price": "0.08270000",
15+
"currency": "EUR",
16+
"mcc": "222",
17+
"mnc": "07",
18+
"networkCode": "22207",
19+
"networkName": "Noverca Italia S.r.l."
20+
},
21+
{
22+
"type": "mobile",
23+
"price": "0.08270000",
24+
"currency": "EUR",
25+
"mcc": "222",
26+
"mnc": "08",
27+
"networkCode": "22208",
28+
"networkName": "FastWeb S.p.A."
29+
},
30+
{
31+
"type": "landline_premium",
32+
"price": "0.08270000",
33+
"currency": "EUR",
34+
"networkCode": "IT-PREMIUM",
35+
"networkName": "Italy Premium"
36+
}
37+
]
38+
},
39+
{
40+
"dialingPrefix": "39",
41+
"currency": "EUR",
42+
"countryDisplayName": "Vatican City",
43+
"countryCode": "VA",
44+
"countryName": "Vatican City"
45+
}
46+
]
47+
}

account/tests/test_account.py

+65
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
from pytest import raises
55
from vonage_account.account import Account
66
from vonage_account.errors import InvalidSecretError
7+
from vonage_account.requests import (
8+
GetCountryPricingRequest,
9+
GetPrefixPricingRequest,
10+
ServiceType,
11+
)
712
from vonage_http_client.errors import ForbiddenError
813
from vonage_http_client.http_client import HttpClient
914

@@ -70,6 +75,66 @@ def test_update_default_sms_webhook():
7075
assert settings_response.max_calls_per_second == 30
7176

7277

78+
@responses.activate
79+
def test_get_country_pricing():
80+
build_response(
81+
path,
82+
'GET',
83+
'https://rest.nexmo.com/account/get-pricing/outbound/sms',
84+
'get_country_pricing.json',
85+
)
86+
87+
response = account.get_country_pricing(
88+
GetCountryPricingRequest(country_code='ZM', type=ServiceType.SMS)
89+
)
90+
91+
assert response.dialing_prefix == '260'
92+
assert response.country_name == 'Zambia'
93+
assert response.default_price == '0.28725000'
94+
assert response.networks[0].network_name == 'Zambia Premium'
95+
assert response.networks[1].mcc == '645'
96+
97+
98+
@responses.activate
99+
def test_get_all_countries_pricing():
100+
build_response(
101+
path,
102+
'GET',
103+
'https://rest.nexmo.com/account/get-full-pricing/outbound/sms',
104+
'get_multiple_countries_pricing.json',
105+
)
106+
107+
response = account.get_all_countries_pricing(ServiceType.SMS)
108+
109+
assert response.count == 2
110+
assert response.countries[0].country_name == 'Italy'
111+
assert response.countries[1].country_name == 'Vatican City'
112+
assert response.countries[0].networks[0].network_name == 'Noverca Italia S.r.l.'
113+
assert response.countries[0].networks[0].price == '0.08270000'
114+
115+
116+
@responses.activate
117+
def test_get_prefix_pricing():
118+
build_response(
119+
path,
120+
'GET',
121+
'https://rest.nexmo.com/account/get-prefix-pricing/outbound/sms',
122+
'get_multiple_countries_pricing.json',
123+
)
124+
125+
response = account.get_prefix_pricing(
126+
GetPrefixPricingRequest(prefix='39', type=ServiceType.SMS)
127+
)
128+
129+
assert response.count == 2
130+
assert response.countries[0].country_name == 'Italy'
131+
assert response.countries[0].dialing_prefix == '39'
132+
assert response.countries[1].country_name == 'Vatican City'
133+
assert response.countries[1].dialing_prefix == '39'
134+
assert response.countries[0].networks[0].network_name == 'Noverca Italia S.r.l.'
135+
assert response.countries[0].networks[0].price == '0.08270000'
136+
137+
73138
@responses.activate
74139
def test_list_secrets():
75140
build_response(

0 commit comments

Comments
 (0)