Skip to content

Commit

Permalink
removed deprecated ApplicationV2 class
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Aug 26, 2023
1 parent ffe8a37 commit a14ec29
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 239 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Breaking changes:
- Removed redundant intermediary `Error` class
- Removed `Pay` action from NCCO builder
- Removed `Redact` class and support for the Redact API as it's a dev preview product that's unsupported in the SDK
- Removed `ApplicationV2` class. Use `Application` instead
- Removed `ApplicationV2` class as V1 has been end-of-life for a significant amount of time and this new naming is in line with other APIs. Please use `Application` instead

# 3.9.0
- Dropped support for Python 3.7 as it's end-of-life and no longer receiving security updates
Expand Down
90 changes: 0 additions & 90 deletions src/vonage/application.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,3 @@
from deprecated import deprecated


@deprecated(
version='3.0.0',
reason='Renamed to Application as V1 is out of support and this new \
naming is in line with other APIs. Please use Application instead.',
)
class ApplicationV2:
auth_type = 'header'

def __init__(self, client):
self._client = client

def create_application(self, application_data):
"""
Create an application using the provided `application_data`.
:param dict application_data: A JSON-style dict describing the application to be created.
>>> client.application.create_application({ 'name': 'My Cool App!' })
Details of the `application_data` dict are described at https://developer.vonage.com/api/application.v2#createApplication
"""
return self._client.post(
self._client.api_host(),
"/v2/applications",
application_data,
auth_type=ApplicationV2.auth_type,
)

def get_application(self, application_id):
"""
Get application details for the application with `application_id`.
The format of the returned dict is described at https://developer.vonage.com/api/application.v2#getApplication
:param str application_id: The application ID.
:rtype: dict
"""

return self._client.get(
self._client.api_host(),
f"/v2/applications/{application_id}",
auth_type=ApplicationV2.auth_type,
)

def update_application(self, application_id, params):
"""
Update the application with `application_id` using the values provided in `params`.
"""
return self._client.put(
self._client.api_host(),
f"/v2/applications/{application_id}",
params,
auth_type=ApplicationV2.auth_type,
)

def delete_application(self, application_id):
"""
Delete the application with `application_id`.
"""

self._client.delete(
self._client.api_host(),
f"/v2/applications/{application_id}",
auth_type=ApplicationV2.auth_type,
)

def list_applications(self, page_size=None, page=None):
"""
List all applications for your account.
Results are paged, so each page will need to be requested to see all applications.
:param int page_size: The number of items in the page to be returned
:param int page: The page number of the page to be returned.
"""
params = _filter_none_values({"page_size": page_size, "page": page})

return self._client.get(
self._client.api_host(),
"/v2/applications",
params=params,
auth_type=ApplicationV2.auth_type,
)


class Application:
auth_type = 'header'

Expand Down
2 changes: 1 addition & 1 deletion src/vonage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from vonage_jwt.jwt import JwtClient

from .account import Account
from .application import ApplicationV2, Application
from .application import Application
from .errors import *
from .meetings import Meetings
from .messages import Messages
Expand Down
7 changes: 0 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ def messages(client):
return vonage.Messages(client)


@pytest.fixture
def application_v2(client):
import vonage

return vonage.ApplicationV2(client)


@pytest.fixture
def meetings(client):
import vonage
Expand Down
File renamed without changes.
144 changes: 4 additions & 140 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,148 +4,12 @@
import vonage


@responses.activate
def test_deprecated_list_applications(application_v2, dummy_data):
stub(
responses.GET,
"https://api.nexmo.com/v2/applications",
fixture_path="applications/list_applications.json",
)

apps = application_v2.list_applications()
assert_basic_auth()
assert isinstance(apps, dict)
assert apps["total_items"] == 30
assert request_user_agent() == dummy_data.user_agent


@responses.activate
def test_deprecated_get_application(application_v2, dummy_data):
stub(
responses.GET,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
fixture_path="applications/get_application.json",
)

app = application_v2.get_application("xx-xx-xx-xx")
assert_basic_auth()
assert isinstance(app, dict)
assert app["name"] == "My Test Application"
assert request_user_agent() == dummy_data.user_agent


@responses.activate
def test_deprecated_create_application(application_v2, dummy_data):
stub(
responses.POST,
"https://api.nexmo.com/v2/applications",
fixture_path="applications/create_application.json",
)

params = {"name": "Example App", "type": "voice"}

app = application_v2.create_application(params)
assert_basic_auth()
assert isinstance(app, dict)
assert app["name"] == "My Test Application"
assert request_user_agent() == dummy_data.user_agent
body_data = json.loads(request_body().decode("utf-8"))
assert body_data["type"] == "voice"


@responses.activate
def test_deprecated_update_application(application_v2, dummy_data):
stub(
responses.PUT,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
fixture_path="applications/update_application.json",
)

params = {"answer_url": "https://example.com/ncco"}

app = application_v2.update_application("xx-xx-xx-xx", params)
assert_basic_auth()
assert isinstance(app, dict)
assert request_user_agent() == dummy_data.user_agent
assert request_content_type() == "application/json"
assert b'"answer_url": "https://example.com/ncco"' in request_body()

assert app["name"] == "A Better Name"


@responses.activate
def test_deprecated_delete_application(application_v2, dummy_data):
responses.add(
responses.DELETE,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
status=204,
)

assert application_v2.delete_application("xx-xx-xx-xx") is None
assert_basic_auth()
assert request_user_agent() == dummy_data.user_agent


@responses.activate
def test_deprecated_authentication_error(application_v2):
responses.add(
responses.DELETE,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
status=401,
)
with pytest.raises(vonage.AuthenticationError):
application_v2.delete_application("xx-xx-xx-xx")


@responses.activate
def test_deprecated_client_error(application_v2):
responses.add(
responses.DELETE,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
status=430,
body=json.dumps(
{
"type": "nope_error",
"title": "Nope",
"detail": "You really shouldn't have done that",
}
),
)
with pytest.raises(vonage.ClientError) as exc_info:
application_v2.delete_application("xx-xx-xx-xx")
assert str(exc_info.value) == "Nope: You really shouldn't have done that (nope_error)"


@responses.activate
def test_deprecated_client_error_no_decode(application_v2):
responses.add(
responses.DELETE,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
status=430,
body="{this: isnot_json",
)
with pytest.raises(vonage.ClientError) as exc_info:
application_v2.delete_application("xx-xx-xx-xx")
assert str(exc_info.value) == "430 response from api.nexmo.com"


@responses.activate
def test_deprecated_server_error(application_v2):
responses.add(
responses.DELETE,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
status=500,
)
with pytest.raises(vonage.ServerError):
application_v2.delete_application("xx-xx-xx-xx")


@responses.activate
def test_list_applications(client, dummy_data):
stub(
responses.GET,
"https://api.nexmo.com/v2/applications",
fixture_path="applications/list_applications.json",
fixture_path="application/list_applications.json",
)

apps = client.application.list_applications()
Expand All @@ -160,7 +24,7 @@ def test_get_application(client, dummy_data):
stub(
responses.GET,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
fixture_path="applications/get_application.json",
fixture_path="application/get_application.json",
)

app = client.application.get_application("xx-xx-xx-xx")
Expand All @@ -175,7 +39,7 @@ def test_create_application(client, dummy_data):
stub(
responses.POST,
"https://api.nexmo.com/v2/applications",
fixture_path="applications/create_application.json",
fixture_path="application/create_application.json",
)

params = {"name": "Example App", "type": "voice"}
Expand All @@ -194,7 +58,7 @@ def test_update_application(client, dummy_data):
stub(
responses.PUT,
"https://api.nexmo.com/v2/applications/xx-xx-xx-xx",
fixture_path="applications/update_application.json",
fixture_path="application/update_application.json",
)

params = {"answer_url": "https://example.com/ncco"}
Expand Down

0 comments on commit a14ec29

Please sign in to comment.