Skip to content

Commit

Permalink
add pricing api testing
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Nov 6, 2024
1 parent 4717e7d commit 4d53afa
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 4 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,35 @@ settings: SettingsResponse = vonage_client.account.update_default_sms_webhook(
print(settings)
```

### Get Service Pricing for a Specific Country

```python
from vonage_account import GetCountryPricingRequest

response = vonage_client.account.get_country_pricing(
GetCountryPricingRequest(type='sms', country_code='US')
)
print(response)
```

### Get Service Pricing for All Countries

```python
response = vonage_client.account.get_all_countries_pricing(service_type='sms')
print(response)
```

### Get Service Pricing by Dialing Prefix

```python
from vonage_account import GetPrefixPricingRequest

response = client.account.get_prefix_pricing(
GetPrefixPricingRequest(prefix='44', type='sms')
)
print(response)
```

### List Secrets Associated with the Account

```python
Expand Down
3 changes: 2 additions & 1 deletion account/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 1.0.3
# 1.1.0
- Add support for the [Vonage Pricing API](https://developer.vonage.com/en/api/pricing)
- Update dependency versions

# 1.0.2
Expand Down
2 changes: 1 addition & 1 deletion account/src/vonage_account/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from .requests import GetCountryPricingRequest, GetPrefixPricingRequest, ServiceType
from .responses import (
Balance,
GetPricingResponse,
GetMultiplePricingResponse,
GetPricingResponse,
NetworkPricing,
SettingsResponse,
TopUpResponse,
Expand Down
2 changes: 1 addition & 1 deletion account/src/vonage_account/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.3'
__version__ = '1.1.0'
3 changes: 2 additions & 1 deletion account/src/vonage_account/requests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydantic import BaseModel
from enum import Enum

from pydantic import BaseModel


class ServiceType(str, Enum):
"""The service you wish to retrieve outbound pricing data about.
Expand Down
2 changes: 2 additions & 0 deletions account/src/vonage_account/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class NetworkPricing(BaseModel):
network_name (str, Optional): The network name.
price (str, Optional): The price for the service.
type (str, Optional): The type of service.
ranges (str, Optional): Number ranges.
"""

aliases: Optional[list[str]] = None
Expand All @@ -75,6 +76,7 @@ class NetworkPricing(BaseModel):
network_name: Optional[str] = Field(None, validation_alias='networkName')
price: Optional[str] = None
type: Optional[str] = None
ranges: Optional[list[int]] = None


class GetPricingResponse(BaseModel):
Expand Down
79 changes: 79 additions & 0 deletions account/tests/data/get_country_pricing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"dialingPrefix": "260",
"defaultPrice": "0.28725000",
"currency": "EUR",
"countryDisplayName": "Zambia",
"countryCode": "ZM",
"countryName": "Zambia",
"networks": [
{
"type": "landline_premium",
"price": "0.28725000",
"currency": "EUR",
"ranges": [
26090
],
"networkCode": "ZM-PREMIUM",
"networkName": "Zambia Premium"
},
{
"type": "mobile",
"price": "0.28725000",
"currency": "EUR",
"ranges": [
2607,
26076,
26096
],
"mcc": "645",
"mnc": "02",
"networkCode": "64502",
"networkName": "MTN Zambia"
},
{
"type": "mobile",
"price": "0.28725000",
"currency": "EUR",
"ranges": [
26077,
26097
],
"mcc": "645",
"mnc": "01",
"networkCode": "64501",
"networkName": "Airtel"
},
{
"type": "landline_tollfree",
"price": "0.28725000",
"currency": "EUR",
"ranges": [
2608
],
"networkCode": "ZM-TOLL-FREE",
"networkName": "Zambia Toll Free"
},
{
"type": "landline",
"price": "0.28725000",
"currency": "EUR",
"ranges": [
2602
],
"networkCode": "ZM-FIXED",
"networkName": "Zambia Landline"
},
{
"type": "mobile",
"price": "0.28725000",
"currency": "EUR",
"ranges": [
26095
],
"mcc": "645",
"mnc": "03",
"networkCode": "64503",
"networkName": "Zamtel"
}
]
}
47 changes: 47 additions & 0 deletions account/tests/data/get_multiple_countries_pricing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"count": 2,
"countries": [
{
"dialingPrefix": "39",
"defaultPrice": "0.08270000",
"currency": "EUR",
"countryDisplayName": "Italy",
"countryCode": "IT",
"countryName": "Italy",
"networks": [
{
"type": "mobile",
"price": "0.08270000",
"currency": "EUR",
"mcc": "222",
"mnc": "07",
"networkCode": "22207",
"networkName": "Noverca Italia S.r.l."
},
{
"type": "mobile",
"price": "0.08270000",
"currency": "EUR",
"mcc": "222",
"mnc": "08",
"networkCode": "22208",
"networkName": "FastWeb S.p.A."
},
{
"type": "landline_premium",
"price": "0.08270000",
"currency": "EUR",
"networkCode": "IT-PREMIUM",
"networkName": "Italy Premium"
}
]
},
{
"dialingPrefix": "39",
"currency": "EUR",
"countryDisplayName": "Vatican City",
"countryCode": "VA",
"countryName": "Vatican City"
}
]
}
65 changes: 65 additions & 0 deletions account/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from pytest import raises
from vonage_account.account import Account
from vonage_account.errors import InvalidSecretError
from vonage_account.requests import (
GetCountryPricingRequest,
GetPrefixPricingRequest,
ServiceType,
)
from vonage_http_client.errors import ForbiddenError
from vonage_http_client.http_client import HttpClient

Expand Down Expand Up @@ -70,6 +75,66 @@ def test_update_default_sms_webhook():
assert settings_response.max_calls_per_second == 30


@responses.activate
def test_get_country_pricing():
build_response(
path,
'GET',
'https://rest.nexmo.com/account/get-pricing/outbound/sms',
'get_country_pricing.json',
)

response = account.get_country_pricing(
GetCountryPricingRequest(country_code='ZM', type=ServiceType.SMS)
)

assert response.dialing_prefix == '260'
assert response.country_name == 'Zambia'
assert response.default_price == '0.28725000'
assert response.networks[0].network_name == 'Zambia Premium'
assert response.networks[1].mcc == '645'


@responses.activate
def test_get_all_countries_pricing():
build_response(
path,
'GET',
'https://rest.nexmo.com/account/get-full-pricing/outbound/sms',
'get_multiple_countries_pricing.json',
)

response = account.get_all_countries_pricing(ServiceType.SMS)

assert response.count == 2
assert response.countries[0].country_name == 'Italy'
assert response.countries[1].country_name == 'Vatican City'
assert response.countries[0].networks[0].network_name == 'Noverca Italia S.r.l.'
assert response.countries[0].networks[0].price == '0.08270000'


@responses.activate
def test_get_prefix_pricing():
build_response(
path,
'GET',
'https://rest.nexmo.com/account/get-prefix-pricing/outbound/sms',
'get_multiple_countries_pricing.json',
)

response = account.get_prefix_pricing(
GetPrefixPricingRequest(prefix='39', type=ServiceType.SMS)
)

assert response.count == 2
assert response.countries[0].country_name == 'Italy'
assert response.countries[0].dialing_prefix == '39'
assert response.countries[1].country_name == 'Vatican City'
assert response.countries[1].dialing_prefix == '39'
assert response.countries[0].networks[0].network_name == 'Noverca Italia S.r.l.'
assert response.countries[0].networks[0].price == '0.08270000'


@responses.activate
def test_list_secrets():
build_response(
Expand Down

0 comments on commit 4d53afa

Please sign in to comment.