diff --git a/.manifest.json b/.manifest.json new file mode 100644 index 0000000..cd3f1a4 --- /dev/null +++ b/.manifest.json @@ -0,0 +1,147 @@ +{ + "liblabVersion": "1.1.40", + "date": "2024-03-12T11:36:24.298Z", + "config": { + "authentication": { + "access": { + "prefix": "Bearer" + } + }, + "deliveryType": "zip", + "languages": [ + "python" + ], + "inputFileName": "/tmp/resources/spec/open-api-spec.json", + "environmentVariables": [], + "fileOutput": "/tmp", + "tempDir": "/tmp/liblab-codegen-1.1.40-DQXv5m", + "inferServiceNames": false, + "httpLibrary": { + "name": "axios", + "packages": { + "axios": "^1.0.0" + }, + "languages": [ + "javascript", + "typescript" + ] + }, + "auth": [ + "bearer" + ], + "privateRepo": false, + "githubRef": "", + "baseUrl": "http://localhost:8080", + "sdkName": "Llamastore", + "sdkVersion": "0.0.3", + "retry": { + "enabled": true, + "maxAttempts": 3, + "retryDelay": 150 + }, + "customQueries": { + "paths": [], + "rawQueries": [], + "queriesData": [] + }, + "generateEnv": true, + "license": { + "type": "MIT", + "name": "MIT", + "url": "https://opensource.org/licenses/MIT" + }, + "alwaysInitializeOptionals": true, + "pypiPackageName": "LlamaStore", + "environments": [], + "reservedKeywords": {}, + "deliveryMethods": [], + "bundle": false, + "exportClassDefault": false, + "responseHeaders": false, + "renameIllegalModelProperties": false, + "devContainer": true, + "strictVersion": false, + "authors": [], + "classifiers": [], + "projectUrls": {}, + "homepage": "", + "enforceRequestValidation": false, + "denoteCommon": false, + "includeOptionalSnippetParameters": true, + "hooks": { + "enabled": true, + "sourceDir": "/tmp/resources/hooks" + }, + "spec": { + "type": "openapi", + "version": "3.1" + }, + "usesFormData": false + }, + "files": [ + ".devcontainer/devcontainer.json", + ".env.example", + ".gitignore", + "LICENSE", + "README.md", + "examples/.env.example", + "examples/README.md", + "examples/install.cmd", + "examples/install.sh", + "examples/install_py3.sh", + "examples/sample.py", + "install.cmd", + "install.sh", + "pyproject.toml", + "requirements.txt", + "src/llamastore/README.md", + "src/llamastore/__init__.py", + "src/llamastore/hooks/__init__.py", + "src/llamastore/hooks/hook.py", + "src/llamastore/models/ApiToken.py", + "src/llamastore/models/CreateApiTokenRequest.py", + "src/llamastore/models/CreateLlamaRequest.py", + "src/llamastore/models/GetLlamasResponse.py", + "src/llamastore/models/Llama.py", + "src/llamastore/models/LlamaColor.py", + "src/llamastore/models/LlamaId.py", + "src/llamastore/models/README.md", + "src/llamastore/models/RegisterUserRequest.py", + "src/llamastore/models/UpdateLlamaRequest.py", + "src/llamastore/models/User.py", + "src/llamastore/models/__init__.py", + "src/llamastore/models/base.py", + "src/llamastore/net/__init__.py", + "src/llamastore/net/environment.py", + "src/llamastore/net/http_client.py", + "src/llamastore/net/http_content_types.py", + "src/llamastore/net/query_serializer.py", + "src/llamastore/net/utils.py", + "src/llamastore/sdk.py", + "src/llamastore/services/README.md", + "src/llamastore/services/__init__.py", + "src/llamastore/services/base.py", + "src/llamastore/services/llama.py", + "src/llamastore/services/llama_picture.py", + "src/llamastore/services/token.py", + "src/llamastore/services/user.py", + "src/llamastore/setup.py", + "test/__init__.py", + "test/models/__init__.py", + "test/models/test_api_token.py", + "test/models/test_base.py", + "test/models/test_create_api_token_request.py", + "test/models/test_create_llama_request.py", + "test/models/test_llama.py", + "test/models/test_llama_id.py", + "test/models/test_register_user_request.py", + "test/models/test_update_llama_request.py", + "test/models/test_user.py", + "test/services/__init__.py", + "test/services/test_base.py", + "test/services/test_llama.py", + "test/services/test_llama_picture.py", + "test/services/test_token.py", + "test/services/test_user.py" + ] +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index cb511c8..4dc8223 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2023 +Copyright (c) 2024 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9c71c26..101afe3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Llamastore Python SDK 0.0.1 +# Llamastore Python SDK 0.0.3 A Python SDK for Llamastore. The llama store API! Get details on all your favorite llamas. ## To use this API - You will need to register a user, once done you can request an API token. - You can then use your API token to get details about the llamas. ## User registration To register a user, send a POST request to `/user` with the following body: ```json { email : , password : } ``` This API has a maximum of 1000 current users. Once this is exceeded, older users will be deleted. If your user is deleted, you will need to register again. ## Get an API token To get an API token, send a POST request to `/token` with the following body: ```json { email : , password : } ``` This will return a token that you can use to authenticate with the API: ```json { access_token : , token_type : bearer } ``` ## Use the API token To use the API token, add it to the `Authorization` header of your request: ``` Authorization: Bearer ``` -- API version: 0.0.1 -- SDK version: 0.0.1 +- API version: 0.0.3 +- SDK version: 0.0.3 ## Table of Contents - [Requirements](#requirements) @@ -58,7 +58,7 @@ sdk.llama.set_access_token('YOUR_BEARER_TOKEN') ## API Endpoint Services -All URIs are relative to http://localhost:8000. +All URIs are relative to http://localhost:8080. Click the service name for a full list of the service methods. @@ -176,7 +176,7 @@ sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) request_body = {} results = sdk.llama_picture.create_llama_picture( request_input = request_body, - llama_id = 1 + llama_id = 2 ) pprint(vars(results)) @@ -262,7 +262,7 @@ sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) request_body = {} results = sdk.llama_picture.update_llama_picture( request_input = request_body, - llama_id = 1 + llama_id = 2 ) pprint(vars(results)) @@ -278,7 +278,7 @@ Create Llama **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [LlamaCreate](/src/llamastore/models/README.md#llamacreate) | Required | Request body. | +| request_input | [CreateLlamaRequest](/src/llamastore/models/README.md#createllamarequest) | Required | Request body. | **Return Type** @@ -377,7 +377,7 @@ from pprint import pprint from llamastore import Llamastore sdk = Llamastore() sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) -results = sdk.llama.delete_llama(llama_id = 1) +results = sdk.llama.delete_llama(llama_id = 2) pprint(vars(results)) @@ -392,7 +392,7 @@ Update Llama | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| | llama_id | int | Required | The llama's ID | -| request_input | [LlamaCreate](/src/llamastore/models/README.md#llamacreate) | Required | Request body. | +| request_input | [UpdateLlamaRequest](/src/llamastore/models/README.md#updatellamarequest) | Required | Request body. | **Return Type** @@ -429,7 +429,7 @@ Create Api Token **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [ApiTokenRequest](/src/llamastore/models/README.md#apitokenrequest) | Required | Request body. | +| request_input | [CreateApiTokenRequest](/src/llamastore/models/README.md#createapitokenrequest) | Required | Request body. | **Return Type** @@ -474,7 +474,7 @@ from pprint import pprint from llamastore import Llamastore sdk = Llamastore() sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) -results = sdk.user.get_user_by_email(email = 'tIAimCb@N.sUaR].pV') +results = sdk.user.get_user_by_email(email = 'jS$@O.q!B') pprint(vars(results)) @@ -488,7 +488,7 @@ Register User **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [UserRegistration](/src/llamastore/models/README.md#userregistration) | Required | Request body. | +| request_input | [RegisterUserRequest](/src/llamastore/models/README.md#registeruserrequest) | Required | Request body. | **Return Type** diff --git a/examples/.env.example b/examples/.env.example new file mode 100644 index 0000000..ebe4cdc --- /dev/null +++ b/examples/.env.example @@ -0,0 +1 @@ +LLAMASTORE_BEARER_TOKEN= diff --git a/examples/README.md b/examples/README.md index fb20047..778678f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,7 +5,7 @@ A basic example of how to use the llamastore package. If `llamastore` is published to pypi: ```sh -pip install llamastore==0.0.1 +pip install llamastore==0.0.3 ``` In the event `llamastore` is not published to pypi, you can install it locally by running the following command in the example folder: diff --git a/examples/install.cmd b/examples/install.cmd new file mode 100644 index 0000000..97ddc71 --- /dev/null +++ b/examples/install.cmd @@ -0,0 +1,5 @@ +python -m venv .venv +call .venv\Scripts\activate +pip install build +python -m build --outdir dist ..\ +pip install dist\llamastore-0.0.3-py3-none-any.whl --force-reinstall \ No newline at end of file diff --git a/examples/install.sh b/examples/install.sh index e46ed73..38aaad8 100644 --- a/examples/install.sh +++ b/examples/install.sh @@ -2,4 +2,4 @@ python -m venv .venv source .venv/bin/activate pip install build python -m build --outdir dist ../ -pip install dist/llamastore-0.0.1-py3-none-any.whl +pip install dist/llamastore-0.0.3-py3-none-any.whl --force-reinstall diff --git a/examples/install_py3.sh b/examples/install_py3.sh index cb87392..925b1c3 100644 --- a/examples/install_py3.sh +++ b/examples/install_py3.sh @@ -2,4 +2,4 @@ python3 -m venv .venv source .venv/bin/activate pip3 install build python3 -m build --outdir dist ../ -pip3 install dist/llamastore-0.0.1-py3-none-any.whl \ No newline at end of file +pip3 install dist/llamastore-0.0.3-py3-none-any.whl --force-reinstall \ No newline at end of file diff --git a/install.cmd b/install.cmd new file mode 100644 index 0000000..5172a0c --- /dev/null +++ b/install.cmd @@ -0,0 +1,3 @@ +pip install -r requirements.txt +pip install -e src\llamastore\ +python -m unittest discover -p "test*.py" diff --git a/pyproject.toml b/pyproject.toml index 97cee35..87ebae8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,15 +4,18 @@ build-backend = "setuptools.build_meta" [project] name = "llamastore" -version = "0.0.1" +version = "0.0.3" license = { text = "MIT" } description = """The llama store API! Get details on all your favorite llamas. ## To use this API - You will need to register a user, once done you can request an API token. - You can then use your API token to get details about the llamas. ## User registration To register a user, send a POST request to `/user` with the following body: ```json { email : , password : } ``` This API has a maximum of 1000 current users. Once this is exceeded, older users will be deleted. If your user is deleted, you will need to register again. ## Get an API token To get an API token, send a POST request to `/token` with the following body: ```json { email : , password : } ``` This will return a token that you can use to authenticate with the API: ```json { access_token : , token_type : bearer } ``` ## Use the API token To use the API token, add it to the `Authorization` header of your request: ``` Authorization: Bearer ``` """ readme = "README.md" requires-python = ">=3.7" dependencies = [ "requests", - "http-exceptions", + "http-exceptions" +] + +[project.optional-dependencies] +test = [ "pytest", "responses" ] - diff --git a/src/llamastore/README.md b/src/llamastore/README.md index 9c71c26..101afe3 100644 --- a/src/llamastore/README.md +++ b/src/llamastore/README.md @@ -1,10 +1,10 @@ -# Llamastore Python SDK 0.0.1 +# Llamastore Python SDK 0.0.3 A Python SDK for Llamastore. The llama store API! Get details on all your favorite llamas. ## To use this API - You will need to register a user, once done you can request an API token. - You can then use your API token to get details about the llamas. ## User registration To register a user, send a POST request to `/user` with the following body: ```json { email : , password : } ``` This API has a maximum of 1000 current users. Once this is exceeded, older users will be deleted. If your user is deleted, you will need to register again. ## Get an API token To get an API token, send a POST request to `/token` with the following body: ```json { email : , password : } ``` This will return a token that you can use to authenticate with the API: ```json { access_token : , token_type : bearer } ``` ## Use the API token To use the API token, add it to the `Authorization` header of your request: ``` Authorization: Bearer ``` -- API version: 0.0.1 -- SDK version: 0.0.1 +- API version: 0.0.3 +- SDK version: 0.0.3 ## Table of Contents - [Requirements](#requirements) @@ -58,7 +58,7 @@ sdk.llama.set_access_token('YOUR_BEARER_TOKEN') ## API Endpoint Services -All URIs are relative to http://localhost:8000. +All URIs are relative to http://localhost:8080. Click the service name for a full list of the service methods. @@ -176,7 +176,7 @@ sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) request_body = {} results = sdk.llama_picture.create_llama_picture( request_input = request_body, - llama_id = 1 + llama_id = 2 ) pprint(vars(results)) @@ -262,7 +262,7 @@ sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) request_body = {} results = sdk.llama_picture.update_llama_picture( request_input = request_body, - llama_id = 1 + llama_id = 2 ) pprint(vars(results)) @@ -278,7 +278,7 @@ Create Llama **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [LlamaCreate](/src/llamastore/models/README.md#llamacreate) | Required | Request body. | +| request_input | [CreateLlamaRequest](/src/llamastore/models/README.md#createllamarequest) | Required | Request body. | **Return Type** @@ -377,7 +377,7 @@ from pprint import pprint from llamastore import Llamastore sdk = Llamastore() sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) -results = sdk.llama.delete_llama(llama_id = 1) +results = sdk.llama.delete_llama(llama_id = 2) pprint(vars(results)) @@ -392,7 +392,7 @@ Update Llama | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| | llama_id | int | Required | The llama's ID | -| request_input | [LlamaCreate](/src/llamastore/models/README.md#llamacreate) | Required | Request body. | +| request_input | [UpdateLlamaRequest](/src/llamastore/models/README.md#updatellamarequest) | Required | Request body. | **Return Type** @@ -429,7 +429,7 @@ Create Api Token **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [ApiTokenRequest](/src/llamastore/models/README.md#apitokenrequest) | Required | Request body. | +| request_input | [CreateApiTokenRequest](/src/llamastore/models/README.md#createapitokenrequest) | Required | Request body. | **Return Type** @@ -474,7 +474,7 @@ from pprint import pprint from llamastore import Llamastore sdk = Llamastore() sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) -results = sdk.user.get_user_by_email(email = 'tIAimCb@N.sUaR].pV') +results = sdk.user.get_user_by_email(email = 'jS$@O.q!B') pprint(vars(results)) @@ -488,7 +488,7 @@ Register User **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [UserRegistration](/src/llamastore/models/README.md#userregistration) | Required | Request body. | +| request_input | [RegisterUserRequest](/src/llamastore/models/README.md#registeruserrequest) | Required | Request body. | **Return Type** diff --git a/src/llamastore/hooks/hook.py b/src/llamastore/hooks/hook.py index 8b13789..baf2072 100644 --- a/src/llamastore/hooks/hook.py +++ b/src/llamastore/hooks/hook.py @@ -1 +1,36 @@ +class Request: + def __init__(self, method, url, headers, body=""): + self.method = method + self.url = url + self.headers = headers + self.body = body + def __str__(self): + return f"method={self.method}, url={self.url}, headers={self.headers}, body={self.body})" + + +class Response: + def __init__(self, status, headers, body): + self.status = status + self.headers = headers + self.body = body + + def __str__(self): + return "Response(status={}, headers={}, body={})".format( + self.status, self.headers, self.body + ) + + +class CustomHook: + def before_request(self, request: Request): + print( + f"Before request on URL {request.url} with method {request.method.upper()}" + ) + + def after_response(self, request: Request, response: Response): + print( + f"After response on URL {request.url} with method {request.method.upper()}, returning status {response.status}" + ) + + def on_error(self, error: Exception, request: Request, response: Response): + print(f"On error - {error}") diff --git a/src/llamastore/models/ApiToken.py b/src/llamastore/models/ApiToken.py index 712121e..a4c2da6 100644 --- a/src/llamastore/models/ApiToken.py +++ b/src/llamastore/models/ApiToken.py @@ -12,7 +12,9 @@ def __init__(self, access_token: str, token_type: str = None, **kwargs): Parameters: ---------- access_token: str + The bearer token to use with the API. Pass this in the Authorization header as a bearer token. token_type: str + The type of token. This will always be bearer. """ self.access_token = access_token self.token_type = token_type diff --git a/src/llamastore/models/CreateApiTokenRequest.py b/src/llamastore/models/CreateApiTokenRequest.py new file mode 100644 index 0000000..2eded65 --- /dev/null +++ b/src/llamastore/models/CreateApiTokenRequest.py @@ -0,0 +1,20 @@ +from .base import BaseModel + + +class CreateApiTokenRequest(BaseModel): + """ + A request to get an API token for a given user. + """ + + def __init__(self, password: str, email: str, **kwargs): + """ + Initialize CreateApiTokenRequest + Parameters: + ---------- + password: str + The password of the user. This must be at least 8 characters long, and contain at least one letter, one number, and one special character. + email: str + The email address of the user. This must be unique across all users. + """ + self.password = password + self.email = self._pattern_matching(email, ".+\@.+\..+", "email") diff --git a/src/llamastore/models/CreateLlamaRequest.py b/src/llamastore/models/CreateLlamaRequest.py new file mode 100644 index 0000000..791c436 --- /dev/null +++ b/src/llamastore/models/CreateLlamaRequest.py @@ -0,0 +1,26 @@ +from .base import BaseModel +from .LlamaColor import LlamaColor + + +class CreateLlamaRequest(BaseModel): + """ + A new llama for the llama store. + """ + + def __init__(self, rating: int, color: LlamaColor, age: int, name: str, **kwargs): + """ + Initialize CreateLlamaRequest + Parameters: + ---------- + rating: int + The rating of the llama from 1 to 5. + color: LlamaColor + age: int + The age of the llama in years. + name: str + The name of the llama. This must be unique across all llamas. + """ + self.rating = rating + self.color = self._enum_matching(color, LlamaColor.list(), "color") + self.age = age + self.name = name diff --git a/src/llamastore/models/Llama.py b/src/llamastore/models/Llama.py index d03270e..a404291 100644 --- a/src/llamastore/models/Llama.py +++ b/src/llamastore/models/Llama.py @@ -15,10 +15,14 @@ def __init__( Parameters: ---------- id: int + The ID of the llama. rating: int + The rating of the llama from 1 to 5. color: LlamaColor age: int + The age of the llama in years. name: str + The name of the llama. This must be unique across all llamas. """ self.id = id self.rating = rating diff --git a/src/llamastore/models/LlamaId.py b/src/llamastore/models/LlamaId.py index a1e340b..3019232 100644 --- a/src/llamastore/models/LlamaId.py +++ b/src/llamastore/models/LlamaId.py @@ -12,5 +12,6 @@ def __init__(self, id: int, **kwargs): Parameters: ---------- id: int + The ID of the llama. """ self.id = id diff --git a/src/llamastore/models/README.md b/src/llamastore/models/README.md index 46baafe..cd5508f 100644 --- a/src/llamastore/models/README.md +++ b/src/llamastore/models/README.md @@ -2,32 +2,35 @@ A list of all models. - [GetLlamasResponse](#getllamasresponse) -- [ApiToken](#apitoken) -- [ApiTokenRequest](#apitokenrequest) +- [CreateLlamaRequest](#createllamarequest) +- [UpdateLlamaRequest](#updatellamarequest) +- [CreateApiTokenRequest](#createapitokenrequest) +- [RegisterUserRequest](#registeruserrequest) +- [LlamaId](#llamaid) - [Llama](#llama) - [LlamaColor](#llamacolor) -- [LlamaCreate](#llamacreate) -- [LlamaId](#llamaid) +- [ApiToken](#apitoken) - [User](#user) -- [UserRegistration](#userregistration) ## GetLlamasResponse -## ApiToken +## CreateLlamaRequest + +## UpdateLlamaRequest + +## CreateApiTokenRequest -## ApiTokenRequest +## RegisterUserRequest + +## LlamaId ## Llama ## LlamaColor -## LlamaCreate - -## LlamaId +## ApiToken ## User -## UserRegistration - diff --git a/src/llamastore/models/RegisterUserRequest.py b/src/llamastore/models/RegisterUserRequest.py new file mode 100644 index 0000000..82c362f --- /dev/null +++ b/src/llamastore/models/RegisterUserRequest.py @@ -0,0 +1,20 @@ +from .base import BaseModel + + +class RegisterUserRequest(BaseModel): + """ + A new user of the llama store. + """ + + def __init__(self, password: str, email: str, **kwargs): + """ + Initialize RegisterUserRequest + Parameters: + ---------- + password: str + The password of the user. This must be at least 8 characters long, and contain at least one letter, one number, and one special character. + email: str + The email address of the user. This must be unique across all users. + """ + self.password = password + self.email = self._pattern_matching(email, ".+\@.+\..+", "email") diff --git a/src/llamastore/models/UpdateLlamaRequest.py b/src/llamastore/models/UpdateLlamaRequest.py new file mode 100644 index 0000000..feda8f6 --- /dev/null +++ b/src/llamastore/models/UpdateLlamaRequest.py @@ -0,0 +1,26 @@ +from .base import BaseModel +from .LlamaColor import LlamaColor + + +class UpdateLlamaRequest(BaseModel): + """ + A new llama for the llama store. + """ + + def __init__(self, rating: int, color: LlamaColor, age: int, name: str, **kwargs): + """ + Initialize UpdateLlamaRequest + Parameters: + ---------- + rating: int + The rating of the llama from 1 to 5. + color: LlamaColor + age: int + The age of the llama in years. + name: str + The name of the llama. This must be unique across all llamas. + """ + self.rating = rating + self.color = self._enum_matching(color, LlamaColor.list(), "color") + self.age = age + self.name = name diff --git a/src/llamastore/models/User.py b/src/llamastore/models/User.py index 455717d..8a369e3 100644 --- a/src/llamastore/models/User.py +++ b/src/llamastore/models/User.py @@ -12,7 +12,9 @@ def __init__(self, id: int, email: str, **kwargs): Parameters: ---------- id: int + The ID of the user. This is unique across all users. email: str + The email address of the user. This must be unique across all users. """ self.id = id self.email = self._pattern_matching(email, ".+\@.+\..+", "email") diff --git a/src/llamastore/models/__init__.py b/src/llamastore/models/__init__.py index 9492fa4..62f56bc 100644 --- a/src/llamastore/models/__init__.py +++ b/src/llamastore/models/__init__.py @@ -1,9 +1,10 @@ from .GetLlamasResponse import GetLlamasResponse -from .ApiToken import ApiToken -from .ApiTokenRequest import ApiTokenRequest +from .CreateLlamaRequest import CreateLlamaRequest +from .UpdateLlamaRequest import UpdateLlamaRequest +from .CreateApiTokenRequest import CreateApiTokenRequest +from .RegisterUserRequest import RegisterUserRequest +from .LlamaId import LlamaId from .Llama import Llama from .LlamaColor import LlamaColor -from .LlamaCreate import LlamaCreate -from .LlamaId import LlamaId +from .ApiToken import ApiToken from .User import User -from .UserRegistration import UserRegistration diff --git a/src/llamastore/models/base.py b/src/llamastore/models/base.py index 5d5663a..341c6a6 100644 --- a/src/llamastore/models/base.py +++ b/src/llamastore/models/base.py @@ -5,7 +5,7 @@ class BaseModel: """ - A base class that all models in the SDK inherite from (expect for Enum models). + A base class that all models in the SDK inherit from (expect for Enum models). Methods ------- @@ -16,7 +16,7 @@ class BaseModel: Checks if a value (str or enum) matches the required enum values. Returns the value if there's a match, otherwise throws an error. _one_of(cls, required_array, all_array, functions_array, input_data): - Validates wheter an input_data satisfies the oneOf requirments. + Validates whether an input_data satisfies the oneOf requirements. """ def __init__(self): @@ -43,15 +43,16 @@ def _enum_matching( def _one_of(cls, required_array, all_array, functions_array, input_data): input_array = list(input_data.keys()) for model, fields in required_array.items(): + input_copy = input_array.copy() matches_required = True for param in fields: - if param not in input_array: + if param not in input_copy: matches_required = False break - input_array.remove(param) + input_copy.remove(param) if matches_required: matches_all = True - for input in input_array: + for input in input_copy: if input not in all_array[model]: matches_all = False break diff --git a/src/llamastore/net/environment.py b/src/llamastore/net/environment.py index 05aeb0a..7677fe4 100644 --- a/src/llamastore/net/environment.py +++ b/src/llamastore/net/environment.py @@ -8,4 +8,4 @@ class Environment(Enum): """The environments available for this SDK""" - DEFAULT = "http://localhost:8000" + DEFAULT = "http://localhost:8080" diff --git a/src/llamastore/net/http_client.py b/src/llamastore/net/http_client.py index 0cb7ba3..17575b1 100644 --- a/src/llamastore/net/http_client.py +++ b/src/llamastore/net/http_client.py @@ -5,6 +5,8 @@ from .http_content_types import multipart_form_data_request from .utils import to_serialize +from ..hooks.hook import CustomHook, Request, Response + class HTTPClient: """ @@ -40,8 +42,8 @@ def _make_http_request(self, method, endpoint_url, headers, body_input): """ request_method = getattr(requests, method) serialized_body = to_serialize(body_input) - if "Content-type" in headers: - data_type, subtype = headers["Content-type"].split("/") + if "Content-Type" in headers: + data_type, subtype = headers["Content-Type"].split("/") if data_type == "multipart": return multipart_form_data_request( method, endpoint_url, headers, serialized_body @@ -68,6 +70,10 @@ def delete(self, endpoint_url: str, headers: dict, retry: bool = True): A boolean representing wether to attempt a retry """ + hook_request = Request("delete", endpoint_url, headers) + self._hook.before_request(hook_request) + headers.update(**hook_request.headers) + response = self._make_http_request("delete", endpoint_url, headers, None) if response.status_code in self._retry_codes and retry: try_cnt = 1 @@ -81,6 +87,15 @@ def delete(self, endpoint_url: str, headers: dict, retry: bool = True): ) try_cnt += 1 + hook_response = Response(response.status_code, response.headers, response.text) + self._hook.after_response(hook_request, hook_response) + + if 400 <= response.status_code < 500: + try: + self._raise_from_status(response) + except Exception as e: + self._hook.on_error(e, hook_request, hook_response) + return self._handle_response(response) def get(self, endpoint_url: str, headers: dict, retry: bool = True): @@ -97,6 +112,10 @@ def get(self, endpoint_url: str, headers: dict, retry: bool = True): A boolean representing wether to attempt a retry """ + hook_request = Request("get", endpoint_url, headers) + self._hook.before_request(hook_request) + headers.update(**hook_request.headers) + response = self._make_http_request("get", endpoint_url, headers, None) if response.status_code in self._retry_codes and retry: try_cnt = 1 @@ -108,6 +127,15 @@ def get(self, endpoint_url: str, headers: dict, retry: bool = True): response = self._make_http_request("get", endpoint_url, headers, None) try_cnt += 1 + hook_response = Response(response.status_code, response.headers, response.text) + self._hook.after_response(hook_request, hook_response) + + if 400 <= response.status_code < 500: + try: + self._raise_from_status(response) + except Exception as e: + self._hook.on_error(e, hook_request, hook_response) + return self._handle_response(response) def patch(self, endpoint_url: str, headers: dict, body_input, retry: bool = True): @@ -126,7 +154,14 @@ def patch(self, endpoint_url: str, headers: dict, body_input, retry: bool = True A boolean representing wether to attempt a retry """ - response = self._make_http_request("patch", endpoint_url, headers, body_input) + serialized_input = to_serialize(body_input) + hook_request = Request("patch", endpoint_url, headers, serialized_input) + self._hook.before_request(hook_request) + headers.update(**hook_request.headers) + + response = self._make_http_request( + "patch", endpoint_url, headers, hook_request.body + ) if response.status_code in self._retry_codes and retry: try_cnt = 1 while ( @@ -135,10 +170,19 @@ def patch(self, endpoint_url: str, headers: dict, body_input, retry: bool = True ): sleep(self._initial_delay ** (try_cnt - 1) / 1000) response = self._make_http_request( - "patch", endpoint_url, headers, body_input + "patch", endpoint_url, headers, hook_request.body ) try_cnt += 1 + hook_response = Response(response.status_code, response.headers, response.text) + self._hook.after_response(hook_request, hook_response) + + if 400 <= response.status_code < 500: + try: + self._raise_from_status(response) + except Exception as e: + self._hook.on_error(e, hook_request, hook_response) + return self._handle_response(response) def post(self, endpoint_url: str, headers: dict, body_input, retry: bool = True): @@ -157,7 +201,14 @@ def post(self, endpoint_url: str, headers: dict, body_input, retry: bool = True) A boolean representing wether to attempt a retry """ - response = self._make_http_request("post", endpoint_url, headers, body_input) + serialized_input = to_serialize(body_input) + hook_request = Request("post", endpoint_url, headers, serialized_input) + self._hook.before_request(hook_request) + headers.update(**hook_request.headers) + + response = self._make_http_request( + "post", endpoint_url, headers, hook_request.body + ) if response.status_code in self._retry_codes and retry: try_cnt = 1 while ( @@ -166,10 +217,19 @@ def post(self, endpoint_url: str, headers: dict, body_input, retry: bool = True) ): sleep(self._initial_delay ** (try_cnt - 1) / 1000) response = self._make_http_request( - "post", endpoint_url, headers, body_input + "post", endpoint_url, headers, hook_request.body ) try_cnt += 1 + hook_response = Response(response.status_code, response.headers, response.text) + self._hook.after_response(hook_request, hook_response) + + if 400 <= response.status_code < 500: + try: + self._raise_from_status(response) + except Exception as e: + self._hook.on_error(e, hook_request, hook_response) + return self._handle_response(response) def put(self, endpoint_url: str, headers: dict, body_input, retry: bool = True): @@ -188,7 +248,14 @@ def put(self, endpoint_url: str, headers: dict, body_input, retry: bool = True): A boolean representing whether to attempt a retry """ - response = self._make_http_request("put", endpoint_url, headers, body_input) + serialized_input = to_serialize(body_input) + hook_request = Request("put", endpoint_url, headers, serialized_input) + self._hook.before_request(hook_request) + headers.update(**hook_request.headers) + + response = self._make_http_request( + "put", endpoint_url, headers, hook_request.body + ) if response.status_code in self._retry_codes and retry: try_cnt = 1 while ( @@ -197,10 +264,19 @@ def put(self, endpoint_url: str, headers: dict, body_input, retry: bool = True): ): sleep(self._initial_delay ** (try_cnt - 1) / 1000) response = self._make_http_request( - "put", endpoint_url, headers, body_input + "put", endpoint_url, headers, hook_request.body ) try_cnt += 1 + hook_response = Response(response.status_code, response.headers, response.text) + self._hook.after_response(hook_request, hook_response) + + if 400 <= response.status_code < 500: + try: + self._raise_from_status(response) + except Exception as e: + self._hook.on_error(e, hook_request, hook_response) + return self._handle_response(response) def _create_exception_message(self, response, header: str) -> str: diff --git a/src/llamastore/net/http_content_types.py b/src/llamastore/net/http_content_types.py index 4b2b8f8..90961ef 100644 --- a/src/llamastore/net/http_content_types.py +++ b/src/llamastore/net/http_content_types.py @@ -27,7 +27,7 @@ def multipart_form_data_request(method, endpoint_url, headers, body_input): data = {} files = {} request_method = getattr(requests, method) - del headers["Content-type"] + del headers["Content-Type"] for key, value in body_input.items(): if isinstance(value, (io.TextIOWrapper, io.BufferedIOBase)): mime_type, encoding = guess_type(value.name) diff --git a/src/llamastore/net/query_serializer.py b/src/llamastore/net/query_serializer.py index 361e573..f55ac72 100644 --- a/src/llamastore/net/query_serializer.py +++ b/src/llamastore/net/query_serializer.py @@ -1,21 +1,31 @@ from typing import Any, Dict, List +from enum import Enum explode = bool def simple(value: Any, explode: bool) -> str: - # Check if the value is a list + if value is None: + return "null" + + if isinstance(value, Enum): + return str(value.value) + + if isinstance(value, bool): + return str(value).lower() + if isinstance(value, list): - return ",".join(value) if explode else "".join(value) + serialized_list = [simple(item, explode) for item in value] + return ",".join(serialized_list) if isinstance(value, dict): if explode: # Serialize object with exploded format: "key=value,key2=value2" - return ",".join([f"{k}={v}" for k, v in value.items()]) + return ",".join([f"{k}={simple(v, explode)}" for k, v in value.items()]) else: # Serialize object with non-exploded format: "key,value,key2,value2" return ",".join( - [str(item) for sublist in value.items() for item in sublist] + [simple(item, explode) for sublist in value.items() for item in sublist] ) return str(value) diff --git a/src/llamastore/net/utils.py b/src/llamastore/net/utils.py index 0148ff8..25aac2d 100644 --- a/src/llamastore/net/utils.py +++ b/src/llamastore/net/utils.py @@ -27,8 +27,12 @@ def to_serialize(obj): for key, value in iter_obj: if isinstance(value, (io.TextIOWrapper, io.BufferedIOBase)): result[key] = value - if isinstance(value, Enum): + elif isinstance(value, Enum): result[key] = value.value + elif isinstance(value, (list, set, tuple)): + for i in range(len(value)): + value[i] = to_serialize(value[i]) + result[key] = value elif hasattr(value, "__dict__"): result[key] = to_serialize(value) else: diff --git a/src/llamastore/sdk.py b/src/llamastore/sdk.py index 8a0918b..bfca56b 100644 --- a/src/llamastore/sdk.py +++ b/src/llamastore/sdk.py @@ -6,8 +6,9 @@ Llamastore """ from .net.environment import Environment -from .services.llama_picture import LlamaPicture + from .services.llama import Llama +from .services.llama_picture import LlamaPicture from .services.token import Token from .services.user import User @@ -18,8 +19,8 @@ class Llamastore: Attributes ---------- - llama_picture : LlamaPicture llama : Llama + llama_picture : LlamaPicture token : Token user : User @@ -41,8 +42,8 @@ def __init__(self, access_token="", environment=Environment.DEFAULT) -> None: access_token : str The access token """ - self.llama_picture = LlamaPicture(access_token) self.llama = Llama(access_token) + self.llama_picture = LlamaPicture(access_token) self.token = Token(access_token) self.user = User(access_token) @@ -57,8 +58,8 @@ def set_base_url(self, url: str) -> None: url: The end URL """ - self.llama_picture.set_base_url(url) self.llama.set_base_url(url) + self.llama_picture.set_base_url(url) self.token.set_base_url(url) self.user.set_base_url(url) @@ -71,7 +72,10 @@ def set_access_token(self, token: str) -> None: token: string Auth token value """ - self.llama_picture.set_access_token(token) self.llama.set_access_token(token) + self.llama_picture.set_access_token(token) self.token.set_access_token(token) self.user.set_access_token(token) + + +# c029837e0e474b76bc487506e8799df5e3335891efe4fb02bda7a1441840310c diff --git a/src/llamastore/services/README.md b/src/llamastore/services/README.md index ef53a8f..016c543 100644 --- a/src/llamastore/services/README.md +++ b/src/llamastore/services/README.md @@ -78,7 +78,7 @@ sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) request_body = {} results = sdk.llama_picture.create_llama_picture( request_input = request_body, - llama_id = 1 + llama_id = 2 ) pprint(vars(results)) @@ -164,7 +164,7 @@ sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) request_body = {} results = sdk.llama_picture.update_llama_picture( request_input = request_body, - llama_id = 1 + llama_id = 2 ) pprint(vars(results)) @@ -180,7 +180,7 @@ Create Llama **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [LlamaCreate](/src/llamastore/models/README.md#llamacreate) | Required | Request body. | +| request_input | [CreateLlamaRequest](/src/llamastore/models/README.md#createllamarequest) | Required | Request body. | **Return Type** @@ -279,7 +279,7 @@ from pprint import pprint from llamastore import Llamastore sdk = Llamastore() sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) -results = sdk.llama.delete_llama(llama_id = 1) +results = sdk.llama.delete_llama(llama_id = 2) pprint(vars(results)) @@ -294,7 +294,7 @@ Update Llama | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| | llama_id | int | Required | The llama's ID | -| request_input | [LlamaCreate](/src/llamastore/models/README.md#llamacreate) | Required | Request body. | +| request_input | [UpdateLlamaRequest](/src/llamastore/models/README.md#updatellamarequest) | Required | Request body. | **Return Type** @@ -331,7 +331,7 @@ Create Api Token **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [ApiTokenRequest](/src/llamastore/models/README.md#apitokenrequest) | Required | Request body. | +| request_input | [CreateApiTokenRequest](/src/llamastore/models/README.md#createapitokenrequest) | Required | Request body. | **Return Type** @@ -376,7 +376,7 @@ from pprint import pprint from llamastore import Llamastore sdk = Llamastore() sdk.set_access_token(getenv("LLAMASTORE_ACCESS_TOKEN")) -results = sdk.user.get_user_by_email(email = 'tIAimCb@N.sUaR].pV') +results = sdk.user.get_user_by_email(email = 'jS$@O.q!B') pprint(vars(results)) @@ -390,7 +390,7 @@ Register User **Parameters** | Name | Type| Required | Description | | :-------- | :----------| :----------| :----------| -| request_input | [UserRegistration](/src/llamastore/models/README.md#userregistration) | Required | Request body. | +| request_input | [RegisterUserRequest](/src/llamastore/models/README.md#registeruserrequest) | Required | Request body. | **Return Type** diff --git a/src/llamastore/services/base.py b/src/llamastore/services/base.py index 82a3c64..30ee777 100644 --- a/src/llamastore/services/base.py +++ b/src/llamastore/services/base.py @@ -5,11 +5,14 @@ Class: BaseService """ +import platform from typing import List, Union from enum import Enum import re from ..net.http_client import HTTPClient +from ..hooks.hook import CustomHook, Request, Response + class BaseService: """ @@ -30,9 +33,11 @@ def set_base_url(url: str): Sets the base url """ - _url_prefix = "http://localhost:8000" + _url_prefix = "http://localhost:8080" + + _custom_hook = CustomHook() - _http = HTTPClient(None) + _http = HTTPClient(_custom_hook) def __init__(self, access_token: str = "") -> None: """ @@ -93,6 +98,6 @@ def _add_required_headers(self, headers: dict): headers: dict Headers dict to add auth headers to """ - headers["User-Agent"] = "liblab/0.1.20 Llamastore/0.0.1 python/2.7" + headers["User-Agent"] = f"Llamastore/0.0.3 Python/{platform.python_version()}" headers["Authorization"] = f"Bearer {self._access_token}" return headers diff --git a/src/llamastore/services/llama.py b/src/llamastore/services/llama.py index b39c9eb..2da77fb 100644 --- a/src/llamastore/services/llama.py +++ b/src/llamastore/services/llama.py @@ -3,7 +3,8 @@ from .base import BaseService from ..models.GetLlamasResponse import GetLlamasResponse as GetLlamasResponseModel from ..models.Llama import Llama as LlamaModel -from ..models.LlamaCreate import LlamaCreate as LlamaCreateModel +from ..models.CreateLlamaRequest import CreateLlamaRequest as CreateLlamaRequestModel +from ..models.UpdateLlamaRequest import UpdateLlamaRequest as UpdateLlamaRequestModel class Llama(BaseService): @@ -22,13 +23,13 @@ def get_llamas(self) -> GetLlamasResponseModel: return [LlamaModel(**model) for model in res] return res - def create_llama(self, request_input: LlamaCreateModel) -> LlamaModel: + def create_llama(self, request_input: CreateLlamaRequestModel) -> LlamaModel: """ Create Llama """ url_endpoint = "/llama" - headers = {"Content-type": "application/json"} + headers = {"Content-Type": "application/json"} self._add_required_headers(headers) final_url = self._url_prefix + url_endpoint @@ -66,7 +67,7 @@ def get_llama_by_id(self, llama_id: int) -> LlamaModel: return res def update_llama( - self, request_input: LlamaCreateModel, llama_id: int + self, request_input: UpdateLlamaRequestModel, llama_id: int ) -> LlamaModel: """ Update Llama @@ -77,7 +78,7 @@ def update_llama( """ url_endpoint = "/llama/{llama_id}" - headers = {"Content-type": "application/json"} + headers = {"Content-Type": "application/json"} self._add_required_headers(headers) if not llama_id: raise ValueError( diff --git a/src/llamastore/services/llama_picture.py b/src/llamastore/services/llama_picture.py index 830367c..1dafe77 100644 --- a/src/llamastore/services/llama_picture.py +++ b/src/llamastore/services/llama_picture.py @@ -43,7 +43,7 @@ def create_llama_picture( """ url_endpoint = "/llama/{llama_id}/picture" - headers = {"Content-type": "image/png"} + headers = {"Content-Type": "image/png"} self._add_required_headers(headers) if not llama_id: raise ValueError( @@ -73,7 +73,7 @@ def update_llama_picture( """ url_endpoint = "/llama/{llama_id}/picture" - headers = {"Content-type": "image/png"} + headers = {"Content-Type": "image/png"} self._add_required_headers(headers) if not llama_id: raise ValueError( diff --git a/src/llamastore/services/token.py b/src/llamastore/services/token.py index b54b1ab..c6a702f 100644 --- a/src/llamastore/services/token.py +++ b/src/llamastore/services/token.py @@ -1,18 +1,22 @@ from urllib.parse import quote from .base import BaseService -from ..models.ApiTokenRequest import ApiTokenRequest as ApiTokenRequestModel +from ..models.CreateApiTokenRequest import ( + CreateApiTokenRequest as CreateApiTokenRequestModel, +) from ..models.ApiToken import ApiToken as ApiTokenModel class Token(BaseService): - def create_api_token(self, request_input: ApiTokenRequestModel) -> ApiTokenModel: + def create_api_token( + self, request_input: CreateApiTokenRequestModel + ) -> ApiTokenModel: """ Create Api Token """ url_endpoint = "/token" - headers = {"Content-type": "application/json"} + headers = {"Content-Type": "application/json"} self._add_required_headers(headers) final_url = self._url_prefix + url_endpoint diff --git a/src/llamastore/services/user.py b/src/llamastore/services/user.py index 394053c..cfe90de 100644 --- a/src/llamastore/services/user.py +++ b/src/llamastore/services/user.py @@ -2,7 +2,7 @@ from ..net import query_serializer from .base import BaseService from ..models.User import User as UserModel -from ..models.UserRegistration import UserRegistration as UserRegistrationModel +from ..models.RegisterUserRequest import RegisterUserRequest as RegisterUserRequestModel class User(BaseService): @@ -37,13 +37,13 @@ def get_user_by_email(self, email: str) -> UserModel: return UserModel(**res) return res - def register_user(self, request_input: UserRegistrationModel) -> UserModel: + def register_user(self, request_input: RegisterUserRequestModel) -> UserModel: """ Register User """ url_endpoint = "/user" - headers = {"Content-type": "application/json"} + headers = {"Content-Type": "application/json"} self._add_required_headers(headers) final_url = self._url_prefix + url_endpoint diff --git a/src/llamastore/setup.py b/src/llamastore/setup.py index b5207ce..cb452a6 100644 --- a/src/llamastore/setup.py +++ b/src/llamastore/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="Llamastore", - version="0.0.1", + version="0.0.3", description="""The llama store API! Get details on all your favorite llamas. ## To use this API - You will need to register a user, once done you can request an API token. - You can then use your API token to get details about the llamas. ## User registration To register a user, send a POST request to `/user` with the following body: ```json { email : , password : } ``` This API has a maximum of 1000 current users. Once this is exceeded, older users will be deleted. If your user is deleted, you will need to register again. ## Get an API token To get an API token, send a POST request to `/token` with the following body: ```json { email : , password : } ``` This will return a token that you can use to authenticate with the API: ```json { access_token : , token_type : bearer } ``` ## Use the API token To use the API token, add it to the `Authorization` header of your request: ``` Authorization: Bearer ``` """, license="MIT", packages=setuptools.find_packages(), diff --git a/test/models/test_api_token.py b/test/models/test_api_token.py index 865b0d7..0d70d4b 100644 --- a/test/models/test_api_token.py +++ b/test/models/test_api_token.py @@ -8,9 +8,9 @@ def test_true(self): def test_api_token(self): # Create ApiToken class instance - test_model = ApiToken(access_token="eos", token_type="porro") - self.assertEqual(test_model.access_token, "eos") - self.assertEqual(test_model.token_type, "porro") + test_model = ApiToken(access_token="officia", token_type="dicta") + self.assertEqual(test_model.access_token, "officia") + self.assertEqual(test_model.token_type, "dicta") def test_api_token_required_fields_missing(self): # Assert ApiToken class generation fails without required fields diff --git a/test/models/test_create_api_token_request.py b/test/models/test_create_api_token_request.py new file mode 100644 index 0000000..3cb84c3 --- /dev/null +++ b/test/models/test_create_api_token_request.py @@ -0,0 +1,28 @@ +import unittest +from src.llamastore.models.CreateApiTokenRequest import CreateApiTokenRequest + + +class TestCreateApiTokenRequestModel(unittest.TestCase): + def test_true(self): + self.assertTrue(True) + + def test_create_api_token_request(self): + # Create CreateApiTokenRequest class instance + test_model = CreateApiTokenRequest( + password="nostrum", + email='msE]{d^n(^5@@E_x3PVv|n`p#@.}}-6%ROn9E"s2s_fu_#HTnxtv@2^Oy&k,$?./h#ka8I0V@4f$uRTDcqq,j7I3pU5giC8Z#kb^XukpVR/0y%@peu.X:\\XDk 2l$Y', + ) + self.assertEqual(test_model.password, "nostrum") + self.assertEqual( + test_model.email, + 'msE]{d^n(^5@@E_x3PVv|n`p#@.}}-6%ROn9E"s2s_fu_#HTnxtv@2^Oy&k,$?./h#ka8I0V@4f$uRTDcqq,j7I3pU5giC8Z#kb^XukpVR/0y%@peu.X:\\XDk 2l$Y', + ) + + def test_create_api_token_request_required_fields_missing(self): + # Assert CreateApiTokenRequest class generation fails without required fields + with self.assertRaises(TypeError): + test_model = CreateApiTokenRequest() + + +if __name__ == "__main__": + unittest.main() diff --git a/test/models/test_create_llama_request.py b/test/models/test_create_llama_request.py new file mode 100644 index 0000000..852b5e2 --- /dev/null +++ b/test/models/test_create_llama_request.py @@ -0,0 +1,24 @@ +import unittest +from src.llamastore.models.CreateLlamaRequest import CreateLlamaRequest + + +class TestCreateLlamaRequestModel(unittest.TestCase): + def test_true(self): + self.assertTrue(True) + + def test_create_llama_request(self): + # Create CreateLlamaRequest class instance + test_model = CreateLlamaRequest(rating=4, color="brown", age=6, name="quaerat") + self.assertEqual(test_model.rating, 4) + self.assertEqual(test_model.color, "brown") + self.assertEqual(test_model.age, 6) + self.assertEqual(test_model.name, "quaerat") + + def test_create_llama_request_required_fields_missing(self): + # Assert CreateLlamaRequest class generation fails without required fields + with self.assertRaises(TypeError): + test_model = CreateLlamaRequest() + + +if __name__ == "__main__": + unittest.main() diff --git a/test/models/test_llama.py b/test/models/test_llama.py index fe82f56..0f6d751 100644 --- a/test/models/test_llama.py +++ b/test/models/test_llama.py @@ -8,12 +8,12 @@ def test_true(self): def test_llama(self): # Create Llama class instance - test_model = Llama(id=3, rating=4, color="brown", age=8, name="iste") - self.assertEqual(test_model.id, 3) - self.assertEqual(test_model.rating, 4) + test_model = Llama(id=6, rating=5, color="brown", age=7, name="omnis") + self.assertEqual(test_model.id, 6) + self.assertEqual(test_model.rating, 5) self.assertEqual(test_model.color, "brown") - self.assertEqual(test_model.age, 8) - self.assertEqual(test_model.name, "iste") + self.assertEqual(test_model.age, 7) + self.assertEqual(test_model.name, "omnis") def test_llama_required_fields_missing(self): # Assert Llama class generation fails without required fields diff --git a/test/models/test_llama_id.py b/test/models/test_llama_id.py index e01cac9..3cd89b0 100644 --- a/test/models/test_llama_id.py +++ b/test/models/test_llama_id.py @@ -8,8 +8,8 @@ def test_true(self): def test_llama_id(self): # Create LlamaId class instance - test_model = LlamaId(id=9) - self.assertEqual(test_model.id, 9) + test_model = LlamaId(id=5) + self.assertEqual(test_model.id, 5) def test_llama_id_required_fields_missing(self): # Assert LlamaId class generation fails without required fields diff --git a/test/models/test_register_user_request.py b/test/models/test_register_user_request.py new file mode 100644 index 0000000..6805b87 --- /dev/null +++ b/test/models/test_register_user_request.py @@ -0,0 +1,28 @@ +import unittest +from src.llamastore.models.RegisterUserRequest import RegisterUserRequest + + +class TestRegisterUserRequestModel(unittest.TestCase): + def test_true(self): + self.assertTrue(True) + + def test_register_user_request(self): + # Create RegisterUserRequest class instance + test_model = RegisterUserRequest( + password="animi", + email="aA(kUK6O~aem>@1Fvg\\k'x`2_kOdseAE-xK[mrK:F@!t%UGsW){)`7;Na+7lpV,j'K\"$1&hGb2.Dqiin,6<[S.\\KzG8.F4Lp\"3ZBF:4Mx$f7m$=MIbW$0T}=[!(U5+:qae?.N", + ) + self.assertEqual(test_model.password, "animi") + self.assertEqual( + test_model.email, + "aA(kUK6O~aem>@1Fvg\\k'x`2_kOdseAE-xK[mrK:F@!t%UGsW){)`7;Na+7lpV,j'K\"$1&hGb2.Dqiin,6<[S.\\KzG8.F4Lp\"3ZBF:4Mx$f7m$=MIbW$0T}=[!(U5+:qae?.N", + ) + + def test_register_user_request_required_fields_missing(self): + # Assert RegisterUserRequest class generation fails without required fields + with self.assertRaises(TypeError): + test_model = RegisterUserRequest() + + +if __name__ == "__main__": + unittest.main() diff --git a/test/models/test_update_llama_request.py b/test/models/test_update_llama_request.py new file mode 100644 index 0000000..0af54b0 --- /dev/null +++ b/test/models/test_update_llama_request.py @@ -0,0 +1,26 @@ +import unittest +from src.llamastore.models.UpdateLlamaRequest import UpdateLlamaRequest + + +class TestUpdateLlamaRequestModel(unittest.TestCase): + def test_true(self): + self.assertTrue(True) + + def test_update_llama_request(self): + # Create UpdateLlamaRequest class instance + test_model = UpdateLlamaRequest( + rating=7, color="brown", age=5, name="voluptates" + ) + self.assertEqual(test_model.rating, 7) + self.assertEqual(test_model.color, "brown") + self.assertEqual(test_model.age, 5) + self.assertEqual(test_model.name, "voluptates") + + def test_update_llama_request_required_fields_missing(self): + # Assert UpdateLlamaRequest class generation fails without required fields + with self.assertRaises(TypeError): + test_model = UpdateLlamaRequest() + + +if __name__ == "__main__": + unittest.main() diff --git a/test/models/test_user.py b/test/models/test_user.py index 193a203..33a2798 100644 --- a/test/models/test_user.py +++ b/test/models/test_user.py @@ -9,13 +9,13 @@ def test_true(self): def test_user(self): # Create User class instance test_model = User( - id=9, - email="EB2@5:mAuV^xcS'8PD*NZ7:V<;9As(D5 uEp_Tu~KOEt*yQMFM2R%;<)Tp/zlfKW:d>?SNSx9,.Fw-5U9>l~00_(wRK;olD-_2j!w_Dy`h.%%%l+B6II-j6qM(bdVaNb/=}g3^\\RL?SNSx9,.Fw-5U9>l~00_(wRK;olD-_2j!w_Dy`h.%%%l+B6II-j6qM(bdVaNb/=}g3^\\RL5+"}US}8R4$i!}>nDAyCRh"jWoC\\@NarcPx4m~3ciG2=3XC)d5wc/>Tg.wn"f?Qcq9+s&iRS_*eDJ!(jRM#gs|8^A1($%kf9iA:\'', ) def test_user_required_fields_missing(self): diff --git a/test/services/test_llama.py b/test/services/test_llama.py index db7dcbe..45e7a91 100644 --- a/test/services/test_llama.py +++ b/test/services/test_llama.py @@ -3,6 +3,7 @@ from src.llamastore.net.http_client import HTTPClient from http_exceptions import ClientException from src.llamastore.services.llama import Llama +from src.llamastore.hooks.hook import CustomHook class TestLlama_(unittest.TestCase): @@ -12,7 +13,7 @@ def test_true(self): @responses.activate def test_get_llamas(self): # Mock the API response - responses.get("http://localhost:8000/llama", json={}, status=200) + responses.get("http://localhost:8080/llama", json={}, status=200) # call the method to test test_service = Llama("testkey") response = test_service.get_llamas() @@ -22,7 +23,7 @@ def test_get_llamas(self): @responses.activate def test_get_llamas_error_on_non_200(self): # Mock the API response - responses.get("http://localhost:8000/llama", json={}, status=404) + responses.get("http://localhost:8080/llama", json={}, status=404) with self.assertRaises(ClientException): test_service = Llama("testkey") test_service.get_llamas() @@ -31,7 +32,7 @@ def test_get_llamas_error_on_non_200(self): @responses.activate def test_create_llama(self): # Mock the API response - responses.post("http://localhost:8000/llama", json={}, status=200) + responses.post("http://localhost:8080/llama", json={}, status=200) # call the method to test test_service = Llama("testkey") response = test_service.create_llama({}) @@ -41,7 +42,7 @@ def test_create_llama(self): @responses.activate def test_create_llama_error_on_non_200(self): # Mock the API response - responses.post("http://localhost:8000/llama", json={}, status=404) + responses.post("http://localhost:8080/llama", json={}, status=404) with self.assertRaises(ClientException): test_service = Llama("testkey") test_service.create_llama({}) @@ -50,17 +51,17 @@ def test_create_llama_error_on_non_200(self): @responses.activate def test_get_llama_by_id(self): # Mock the API response - responses.get("http://localhost:8000/llama/2534355165", json={}, status=200) + responses.get("http://localhost:8080/llama/7856358778", json={}, status=200) # call the method to test test_service = Llama("testkey") - response = test_service.get_llama_by_id(2534355165) + response = test_service.get_llama_by_id(7856358778) self.assertEqual(response, {}) responses.reset(), @responses.activate def test_get_llama_by_id_required_fields_missing(self): # Mock the API response - responses.get("http://localhost:8000/llama/8702382703", json={}, status=202) + responses.get("http://localhost:8080/llama/3360228648", json={}, status=202) with self.assertRaises(TypeError): test_service = Llama("testkey") test_service.get_llama_by_id() @@ -69,26 +70,26 @@ def test_get_llama_by_id_required_fields_missing(self): @responses.activate def test_get_llama_by_id_error_on_non_200(self): # Mock the API response - responses.get("http://localhost:8000/llama/6160292169", json={}, status=404) + responses.get("http://localhost:8080/llama/5990850853", json={}, status=404) with self.assertRaises(ClientException): test_service = Llama("testkey") - test_service.get_llama_by_id(6160292169) + test_service.get_llama_by_id(5990850853) responses.reset() @responses.activate def test_update_llama(self): # Mock the API response - responses.put("http://localhost:8000/llama/1905854765", json={}, status=200) + responses.put("http://localhost:8080/llama/7325483761", json={}, status=200) # call the method to test test_service = Llama("testkey") - response = test_service.update_llama({}, 1905854765) + response = test_service.update_llama({}, 7325483761) self.assertEqual(response, {}) responses.reset(), @responses.activate def test_update_llama_required_fields_missing(self): # Mock the API response - responses.put("http://localhost:8000/llama/1538563307", json={}, status=202) + responses.put("http://localhost:8080/llama/6829488783", json={}, status=202) with self.assertRaises(TypeError): test_service = Llama("testkey") test_service.update_llama() @@ -97,26 +98,26 @@ def test_update_llama_required_fields_missing(self): @responses.activate def test_update_llama_error_on_non_200(self): # Mock the API response - responses.put("http://localhost:8000/llama/2867398589", json={}, status=404) + responses.put("http://localhost:8080/llama/3471206007", json={}, status=404) with self.assertRaises(ClientException): test_service = Llama("testkey") - test_service.update_llama({}, 2867398589) + test_service.update_llama({}, 3471206007) responses.reset() @responses.activate def test_delete_llama(self): # Mock the API response - responses.delete("http://localhost:8000/llama/7001320851", json={}, status=200) + responses.delete("http://localhost:8080/llama/2837498804", json={}, status=200) # call the method to test test_service = Llama("testkey") - response = test_service.delete_llama(7001320851) + response = test_service.delete_llama(2837498804) self.assertEqual(response, {}) responses.reset(), @responses.activate def test_delete_llama_required_fields_missing(self): # Mock the API response - responses.delete("http://localhost:8000/llama/3450004469", json={}, status=202) + responses.delete("http://localhost:8080/llama/7658503572", json={}, status=202) with self.assertRaises(TypeError): test_service = Llama("testkey") test_service.delete_llama() @@ -125,10 +126,10 @@ def test_delete_llama_required_fields_missing(self): @responses.activate def test_delete_llama_error_on_non_200(self): # Mock the API response - responses.delete("http://localhost:8000/llama/5838396433", json={}, status=404) + responses.delete("http://localhost:8080/llama/4452004756", json={}, status=404) with self.assertRaises(ClientException): test_service = Llama("testkey") - test_service.delete_llama(5838396433) + test_service.delete_llama(4452004756) responses.reset() diff --git a/test/services/test_llama_picture.py b/test/services/test_llama_picture.py index e301943..2848ff3 100644 --- a/test/services/test_llama_picture.py +++ b/test/services/test_llama_picture.py @@ -3,6 +3,7 @@ from src.llamastore.net.http_client import HTTPClient from http_exceptions import ClientException from src.llamastore.services.llama_picture import LlamaPicture +from src.llamastore.hooks.hook import CustomHook class TestLlamaPicture_(unittest.TestCase): @@ -13,11 +14,11 @@ def test_true(self): def test_get_llama_picture_by_llama_id(self): # Mock the API response responses.get( - "http://localhost:8000/llama/8812109834/picture", json={}, status=200 + "http://localhost:8080/llama/5326915966/picture", json={}, status=200 ) # call the method to test test_service = LlamaPicture("testkey") - response = test_service.get_llama_picture_by_llama_id(8812109834) + response = test_service.get_llama_picture_by_llama_id(5326915966) self.assertEqual(response, {}) responses.reset(), @@ -25,7 +26,7 @@ def test_get_llama_picture_by_llama_id(self): def test_get_llama_picture_by_llama_id_required_fields_missing(self): # Mock the API response responses.get( - "http://localhost:8000/llama/1153432959/picture", json={}, status=202 + "http://localhost:8080/llama/6283376734/picture", json={}, status=202 ) with self.assertRaises(TypeError): test_service = LlamaPicture("testkey") @@ -36,22 +37,22 @@ def test_get_llama_picture_by_llama_id_required_fields_missing(self): def test_get_llama_picture_by_llama_id_error_on_non_200(self): # Mock the API response responses.get( - "http://localhost:8000/llama/5922537141/picture", json={}, status=404 + "http://localhost:8080/llama/2623353000/picture", json={}, status=404 ) with self.assertRaises(ClientException): test_service = LlamaPicture("testkey") - test_service.get_llama_picture_by_llama_id(5922537141) + test_service.get_llama_picture_by_llama_id(2623353000) responses.reset() @responses.activate def test_create_llama_picture(self): # Mock the API response responses.post( - "http://localhost:8000/llama/5625093984/picture", json={}, status=200 + "http://localhost:8080/llama/2491224511/picture", json={}, status=200 ) # call the method to test test_service = LlamaPicture("testkey") - response = test_service.create_llama_picture(5625093984, {}) + response = test_service.create_llama_picture(2491224511, {}) self.assertEqual(response, {}) responses.reset(), @@ -59,7 +60,7 @@ def test_create_llama_picture(self): def test_create_llama_picture_required_fields_missing(self): # Mock the API response responses.post( - "http://localhost:8000/llama/7063736764/picture", json={}, status=202 + "http://localhost:8080/llama/8606858946/picture", json={}, status=202 ) with self.assertRaises(TypeError): test_service = LlamaPicture("testkey") @@ -70,22 +71,22 @@ def test_create_llama_picture_required_fields_missing(self): def test_create_llama_picture_error_on_non_200(self): # Mock the API response responses.post( - "http://localhost:8000/llama/7665988791/picture", json={}, status=404 + "http://localhost:8080/llama/2373629239/picture", json={}, status=404 ) with self.assertRaises(ClientException): test_service = LlamaPicture("testkey") - test_service.create_llama_picture(7665988791, {}) + test_service.create_llama_picture(2373629239, {}) responses.reset() @responses.activate def test_update_llama_picture(self): # Mock the API response responses.put( - "http://localhost:8000/llama/4759892190/picture", json={}, status=200 + "http://localhost:8080/llama/8417020818/picture", json={}, status=200 ) # call the method to test test_service = LlamaPicture("testkey") - response = test_service.update_llama_picture(4759892190, {}) + response = test_service.update_llama_picture(8417020818, {}) self.assertEqual(response, {}) responses.reset(), @@ -93,7 +94,7 @@ def test_update_llama_picture(self): def test_update_llama_picture_required_fields_missing(self): # Mock the API response responses.put( - "http://localhost:8000/llama/8963328117/picture", json={}, status=202 + "http://localhost:8080/llama/9045264244/picture", json={}, status=202 ) with self.assertRaises(TypeError): test_service = LlamaPicture("testkey") @@ -104,22 +105,22 @@ def test_update_llama_picture_required_fields_missing(self): def test_update_llama_picture_error_on_non_200(self): # Mock the API response responses.put( - "http://localhost:8000/llama/4670686801/picture", json={}, status=404 + "http://localhost:8080/llama/3780574656/picture", json={}, status=404 ) with self.assertRaises(ClientException): test_service = LlamaPicture("testkey") - test_service.update_llama_picture(4670686801, {}) + test_service.update_llama_picture(3780574656, {}) responses.reset() @responses.activate def test_delete_llama_picture(self): # Mock the API response responses.delete( - "http://localhost:8000/llama/5362285801/picture", json={}, status=200 + "http://localhost:8080/llama/4937061895/picture", json={}, status=200 ) # call the method to test test_service = LlamaPicture("testkey") - response = test_service.delete_llama_picture(5362285801) + response = test_service.delete_llama_picture(4937061895) self.assertEqual(response, {}) responses.reset(), @@ -127,7 +128,7 @@ def test_delete_llama_picture(self): def test_delete_llama_picture_required_fields_missing(self): # Mock the API response responses.delete( - "http://localhost:8000/llama/9811918532/picture", json={}, status=202 + "http://localhost:8080/llama/6501543652/picture", json={}, status=202 ) with self.assertRaises(TypeError): test_service = LlamaPicture("testkey") @@ -138,11 +139,11 @@ def test_delete_llama_picture_required_fields_missing(self): def test_delete_llama_picture_error_on_non_200(self): # Mock the API response responses.delete( - "http://localhost:8000/llama/2153248509/picture", json={}, status=404 + "http://localhost:8080/llama/9966467699/picture", json={}, status=404 ) with self.assertRaises(ClientException): test_service = LlamaPicture("testkey") - test_service.delete_llama_picture(2153248509) + test_service.delete_llama_picture(9966467699) responses.reset() diff --git a/test/services/test_token.py b/test/services/test_token.py index 793f040..7a1ac1b 100644 --- a/test/services/test_token.py +++ b/test/services/test_token.py @@ -3,6 +3,7 @@ from src.llamastore.net.http_client import HTTPClient from http_exceptions import ClientException from src.llamastore.services.token import Token +from src.llamastore.hooks.hook import CustomHook class TestToken_(unittest.TestCase): @@ -12,7 +13,7 @@ def test_true(self): @responses.activate def test_create_api_token(self): # Mock the API response - responses.post("http://localhost:8000/token", json={}, status=200) + responses.post("http://localhost:8080/token", json={}, status=200) # call the method to test test_service = Token("testkey") response = test_service.create_api_token({}) @@ -22,7 +23,7 @@ def test_create_api_token(self): @responses.activate def test_create_api_token_error_on_non_200(self): # Mock the API response - responses.post("http://localhost:8000/token", json={}, status=404) + responses.post("http://localhost:8080/token", json={}, status=404) with self.assertRaises(ClientException): test_service = Token("testkey") test_service.create_api_token({}) diff --git a/test/services/test_user.py b/test/services/test_user.py index 42179eb..ca88d28 100644 --- a/test/services/test_user.py +++ b/test/services/test_user.py @@ -3,6 +3,7 @@ from src.llamastore.net.http_client import HTTPClient from http_exceptions import ClientException from src.llamastore.services.user import User +from src.llamastore.hooks.hook import CustomHook class TestUser_(unittest.TestCase): @@ -13,14 +14,14 @@ def test_true(self): def test_get_user_by_email(self): # Mock the API response responses.get( - 'http://localhost:8000/user/ZSE4%:SX?336qK@1B4/-ffLtkh+7m"4j5K1n{fR:cRC3}dW$F!\\"z+{I@iH"i%B>B^w.OY&Azw@S9(X=dawe` P,pt"~#q5|O"|~.KgRW-J4t7KM[XGE/<7{e\\yQXGP:tq?gN', json={}, status=200, ) # call the method to test test_service = User("testkey") response = test_service.get_user_by_email( - 'ZSE4%:SX?336qK@1B4/-ffLtkh+7m"4j5K1n{fR:cRC3}dW$F!\\"z+{I@iH"i%B>B^w.OY&Azw@S9(X=dawe` P,pt"~#q5|O"|~.KgRW-J4t7KM[XGE/<7{e\\yQXGP:tq?gN' ) self.assertEqual(response, {}) responses.reset(), @@ -29,7 +30,7 @@ def test_get_user_by_email(self): def test_get_user_by_email_required_fields_missing(self): # Mock the API response responses.get( - "http://localhost:8000/user/O<{Ig?DVYV7lz_.eus,PVx]0Y6z+N*d]M;x=hgbCxi^S)H1S.]viU,-rdSyB+X\\qI?5+]fLoO/1|;\\%dny\\-zFid*O3", + 'http://localhost:8080/user/VP@?_5vt;7;qmB2C2v7EX%3aCxn6rqd.%cR[Z4A&f39D%c?ey>a&tl99lgiqo@x%:OfZO RK0@ApoWU!E#B0+"VhdL590,qVa8=%-OabjrIn$rVce\\A2NK:MBL9.;w0d !@CEY+HF', json={}, status=202, ) @@ -42,21 +43,21 @@ def test_get_user_by_email_required_fields_missing(self): def test_get_user_by_email_error_on_non_200(self): # Mock the API response responses.get( - 'http://localhost:8000/user/~jB"q6vYt!DhxoaS1ZLnHeYK\\XIo,$[FHc"1[[C1E@$5{?eohK7&?>=;0q^bJ5D8LQ!_Q6n/4FRcY 6MrPI\\0!a0zv<`O~;)_AE#HyzOKrmnvv-@d5nI`O.4&Tx* ,e./user/P2D:~P3(c=]bG{V "@/d;%{fXfqy)Ct`Cyd>%tPq+)pxYz}jc46_>+hkZp ++%2,+f%h8s#`Ke[Q_|y[', + "http://localhost:8080/user/N]OuG4fjS1Ry8m%b>twb5'Tb$aL@ubIWa3o3e;GRycTlzJSY%Z`Gpfnfw.)S6}K\\FJ,fN7WZ3JZ3s&dtK3{zWo5*", json={}, status=404, ) with self.assertRaises(ClientException): test_service = User("testkey") test_service.get_user_by_email( - '~jB"q6vYt!DhxoaS1ZLnHeYK\\XIo,$[FHc"1[[C1E@$5{?eohK7&?>=;0q^bJ5D8LQ!_Q6n/4FRcY 6MrPI\\0!a0zv<`O~;)_AE#HyzOKrmnvv-@d5nI`O.4&Tx* ,e.$`P2D:~P3(c=]bG{V "@/d;%{fXfqy)Ct`Cyd>%tPq+)pxYz}jc46_>+hkZp ++%2,+f%h8s#`Ke[Q_|y[' + "N]OuG4fjS1Ry8m%b>twb5'Tb$aL@ubIWa3o3e;GRycTlzJSY%Z`Gpfnfw.)S6}K\\FJ,fN7WZ3JZ3s&dtK3{zWo5*" ) responses.reset() @responses.activate def test_register_user(self): # Mock the API response - responses.post("http://localhost:8000/user", json={}, status=200) + responses.post("http://localhost:8080/user", json={}, status=200) # call the method to test test_service = User("testkey") response = test_service.register_user({}) @@ -66,7 +67,7 @@ def test_register_user(self): @responses.activate def test_register_user_error_on_non_200(self): # Mock the API response - responses.post("http://localhost:8000/user", json={}, status=404) + responses.post("http://localhost:8080/user", json={}, status=404) with self.assertRaises(ClientException): test_service = User("testkey") test_service.register_user({})