Add pytest to Pipfile

This commit is contained in:
2024-01-22 16:14:48 -05:00
parent 9a3603c3c8
commit dbc77df78b
6 changed files with 641 additions and 741 deletions
+14 -7
View File
@@ -1,14 +1,12 @@
gen-model: fetch-v2-schema
datamodel-codegen \
--input v2.json \
--input-file-type jsonschema \
--collapse-root-models \
--output-model-type pydantic_v2.BaseModel \
--output neon_client/schema.py \
--use-standard-collections \
--output-model-type pydantic_v2.BaseModel \
--input-file-type openapi \
# --use-standard-collections \
--output-model-type dataclasses.dataclass \
# --input-file-type openapi \
--use-standard-collections \
--use-union-operator \
--target-python-version 3.11 \
--use-schema-description \
@@ -18,17 +16,26 @@ gen-model: fetch-v2-schema
--allow-population-by-field-name \
--use-title-as-name \
--reuse-model \
--field-constraints \
--collapse-root-models \
# --field-constraints \
--disable-appending-item-suffix \
--allow-extra-fields \
--capitalise-enum-members \
--allow-extra-fields \
--use-field-description \
--use-default \
--use-enum-values \
--reuse-model \
--use-unique-items-as-set \
--set-default-enum-member \
--enum-field-as-literal one \
--allow-extra-fields \
--openapi-scopes {schemas,paths,tags,parameters} \
--use-operation-id-as-name \
--strict-nullable \
--keep-model-order \
--field-constraints \
# --field-constraints \
# --use-annotated \
+1
View File
@@ -5,6 +5,7 @@ name = "pypi"
[packages]
requests = "*"
pytest = "*"
[dev-packages]
neon-client = {file = ".", editable = true}
Generated
+34 -1
View File
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "772851b6661af11cfdfc63062de6b894ea1b3f849eec2e665b8fd97be81ac72c"
"sha256": "ad05855f463975a7c461165b1f6a61f09782a791c2ded66bf623cd81af3f8f44"
},
"pipfile-spec": 6,
"requires": {
@@ -128,6 +128,39 @@
"markers": "python_version >= '3.5'",
"version": "==3.6"
},
"iniconfig": {
"hashes": [
"sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3",
"sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"
],
"markers": "python_version >= '3.7'",
"version": "==2.0.0"
},
"packaging": {
"hashes": [
"sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5",
"sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"
],
"markers": "python_version >= '3.7'",
"version": "==23.2"
},
"pluggy": {
"hashes": [
"sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12",
"sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"
],
"markers": "python_version >= '3.8'",
"version": "==1.3.0"
},
"pytest": {
"hashes": [
"sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280",
"sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"
],
"index": "pypi",
"markers": "python_version >= '3.7'",
"version": "==7.4.4"
},
"requests": {
"hashes": [
"sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f",
+29 -4
View File
@@ -2,6 +2,7 @@ import os
import typing as t
import requests
from pydantic import ValidationError
from . import schema
from .utils import compact_mapping
@@ -12,6 +13,7 @@ __VERSION__ = "0.1.0"
NEON_API_KEY_ENVIRON = "NEON_API_KEY"
NEON_API_BASE_URL = "https://console.neon.tech/api/v2/"
ENABLE_PYDANTIC = True
def returns_model(model, is_array=False):
@@ -19,10 +21,28 @@ def returns_model(model, is_array=False):
def decorator(func):
def wrapper(*args, **kwargs):
if not ENABLE_PYDANTIC:
return func(*args, **kwargs)
if is_array:
return [model.model_construct(**item) for item in func(*args, **kwargs)]
return [model(**item) for item in func(*args, **kwargs)]
else:
return model.model_construct(**func(*args, **kwargs))
return model(**func(*args, **kwargs))
return wrapper
return decorator
def returns_subkey(key):
"""Decorator that returns a subkey."""
def decorator(func):
def wrapper(*args, **kwargs):
try:
return getattr(func(*args, **kwargs), key)
except AttributeError:
return func(*args, **kwargs)[key]
return wrapper
@@ -82,7 +102,7 @@ class NeonAPI:
@classmethod
def from_environ(cls):
"""Create a new Neon API client from the NEON_API_KEY environment variable."""
"""Create a new Neon API client from the `NEON_API_KEY` environment variable."""
return cls(os.environ[NEON_API_KEY_ENVIRON])
@@ -103,9 +123,14 @@ class NeonAPI:
@returns_model(schema.ApiKeyRevokeResponse)
def api_key_revoke(self, api_key_id: str) -> t.Dict[str, t.Any]:
"""Revoke an API key."""
"""Revoke an API key.
:param api_key_id: The ID of the API key to revoke.
:return: A dictionary representing the API key.
"""
return self.request("DELETE", f"api_keys/{ api_key_id }")
# @returns_subkey("projects")
@returns_model(schema.ProjectsResponse)
def projects(
self,
+415 -725
View File
File diff suppressed because it is too large Load Diff
+148 -4
View File
@@ -893,7 +893,65 @@
"type": "string"
}
}
]
],
"get": {
"summary": "Return project's permissions",
"description": "Return project's permissions",
"tags": [
"Project",
"Permissions"
],
"operationId": "listProjectPermissions",
"responses": {
"200": {
"description": "Successfully returned permissions",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProjectPermissions"
}
}
}
},
"default": {
"$ref": "#/components/responses/GeneralError"
}
}
},
"post": {
"summary": "Grant project permission to the user",
"description": "Grant project permission to the user",
"tags": [
"Project",
"Permissions"
],
"operationId": "grantPermissionToProject",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GrantPermissionToProjectRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successfully granted permission to the user",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProjectPermission"
}
}
}
},
"default": {
"$ref": "#/components/responses/GeneralError"
}
}
}
},
"/projects/{project_id}/permissions/{permission_id}": {
"parameters": [
@@ -913,7 +971,31 @@
"type": "string"
}
}
]
],
"delete": {
"summary": "Revoke permission from the user",
"description": "Revoke permission from the user",
"tags": [
"Project",
"Permissions"
],
"operationId": "revokePermissionFromProject",
"responses": {
"200": {
"description": "Successfully revoked permission from the user",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProjectPermission"
}
}
}
},
"default": {
"$ref": "#/components/responses/GeneralError"
}
}
}
},
"/saved_queries/{saved_query_id}": {
"parameters": [
@@ -3772,6 +3854,55 @@
}
}
},
"ProjectPermission": {
"type": "object",
"required": [
"id",
"granted_to_email",
"granted_at"
],
"properties": {
"id": {
"type": "string"
},
"granted_to_email": {
"type": "string"
},
"granted_at": {
"type": "string",
"format": "date-time"
},
"revoked_at": {
"type": "string",
"format": "date-time"
}
}
},
"ProjectPermissions": {
"type": "object",
"required": [
"project_permissions"
],
"properties": {
"project_permissions": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ProjectPermission"
}
}
}
},
"GrantPermissionToProjectRequest": {
"type": "object",
"required": [
"email"
],
"properties": {
"email": {
"type": "string"
}
}
},
"ProjectsConsumptionResponse": {
"type": "object",
"required": [
@@ -4393,10 +4524,9 @@
"maximum": 604800
},
"AllowedIps": {
"description": "A list of IP addresses that are allowed to connect to the endpoint.\nIf the list is empty, all IP addresses are allowed.\nIf primary_branch_only is true, the list will be applied only to the primary branch.\n",
"description": "A list of IP addresses that are allowed to connect to the endpoint.\nIf the list is empty or not set, all IP addresses are allowed.\nIf primary_branch_only is true, the list will be applied only to the primary branch.\n",
"type": "object",
"required": [
"ips",
"primary_branch_only"
],
"properties": {
@@ -5271,6 +5401,13 @@
}
}
},
"SubscriptionDowngradeNewType": {
"type": "string",
"enum": [
"free",
"free_v2"
]
},
"GeneralError": {
"type": "object",
"description": "General Error",
@@ -5339,6 +5476,13 @@
"high",
"critical"
]
},
"SubscriptionUpgradeNewType": {
"type": "string",
"enum": [
"launch",
"scale"
]
}
}
}