Skip to content

Commit

Permalink
add type validation to Auth module, start creating http client
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Dec 30, 2023
1 parent 6df3e2b commit ae69ee3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
13 changes: 7 additions & 6 deletions http_client/src/http_client/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
from pydantic import validate_call, Field
from typing import Optional

from pydantic import validate_call
from vonage_jwt.jwt import JwtClient

from .errors import JWTGenerationError
Expand All @@ -23,11 +24,11 @@ class Auth:
@validate_call
def __init__(
self,
api_key: str = None,
api_secret: str = None,
application_id: str = None,
private_key: str = None,
jwt_claims: dict = {},
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
application_id: Optional[str] = None,
private_key: Optional[str] = None,
jwt_claims: Optional[dict] = {},
) -> None:
self._api_key = api_key
self._api_secret = api_secret
Expand Down
5 changes: 2 additions & 3 deletions http_client/src/http_client/http_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
import aiohttp
import asyncio
import logging

import aiohttp
from http_client.auth import Auth


logger = logging.getLogger("vonage")


Expand Down
9 changes: 7 additions & 2 deletions http_client/tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from os.path import dirname, join
from unittest.mock import patch

from http_client.auth import Auth
from http_client.errors import JWTGenerationError
from pydantic import ValidationError
from pytest import raises
from vonage_jwt.jwt import JwtClient

from http_client.auth import Auth


def read_file(path):
with open(join(dirname(__file__), path)) as input_file:
Expand Down Expand Up @@ -35,6 +35,11 @@ def test_create_auth_class_and_get_objects():
assert type(auth._jwt_client) == JwtClient


def test_create_new_auth_invalid_type():
with raises(ValidationError):
Auth(api_key=1234)


def test_set_new_jwt_claims():
auth = Auth(application_id=application_id, private_key=private_key)
auth.jwt_claims = jwt_claims
Expand Down
3 changes: 2 additions & 1 deletion http_client/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from http_client.http_client import HttpClient
from http_client.auth import Auth

from http_client.http_client import HttpClient


def test_create_client():
client = HttpClient(Auth(), client_options={"qwer", "asdf"})
Expand Down
3 changes: 2 additions & 1 deletion vonage/src/vonage/vonage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from http_client.http_client import HttpClient
from http_client.auth import Auth

from http_client.http_client import HttpClient


class Vonage:
"""Main Server SDK class for using Vonage APIs.
Expand Down

0 comments on commit ae69ee3

Please sign in to comment.