From ae87ec26bbb2a2d243685aaaf7dc4b587c128f29 Mon Sep 17 00:00:00 2001 From: Igor Benav Date: Sun, 15 Sep 2024 02:49:58 -0300 Subject: [PATCH] Simplified endpoints by default --- fastcrud/endpoint/endpoint_creator.py | 21 ++----- fastcrud/endpoint/helper.py | 8 ++- tests/sqlalchemy/conftest.py | 63 +++++++++++++++++++ .../endpoint/test_custom_endpoint_creator.py | 9 +++ .../endpoint/test_deleted_methods.py | 9 +++ .../endpoint/test_included_methods.py | 9 +++ tests/sqlmodel/conftest.py | 63 +++++++++++++++++++ .../endpoint/test_custom_endpoint_creator.py | 9 +++ .../sqlmodel/endpoint/test_deleted_methods.py | 9 +++ .../endpoint/test_included_methods.py | 9 +++ 10 files changed, 191 insertions(+), 18 deletions(-) diff --git a/fastcrud/endpoint/endpoint_creator.py b/fastcrud/endpoint/endpoint_creator.py index 8dd5d82..91b3e06 100644 --- a/fastcrud/endpoint/endpoint_creator.py +++ b/fastcrud/endpoint/endpoint_creator.py @@ -273,24 +273,15 @@ def __init__( self.deleted_at_column = deleted_at_column self.updated_at_column = updated_at_column self.default_endpoint_names = { - "create": "create", - "read": "get", - "update": "update", - "delete": "delete", - "db_delete": "db_delete", - "read_multi": "get_multi", + "create": "", + "read": "", + "update": "", + "delete": "", + "db_delete": "", + "read_multi": "", "read_paginated": "get_paginated", } self.endpoint_names = {**self.default_endpoint_names, **(endpoint_names or {})} - if self.endpoint_names == self.default_endpoint_names: - warnings.warn( - "Old default_endpoint_names are getting deprecated. " - "Default values are going to be replaced by empty strings, " - "resulting in plain endpoint names. " - "For details see:" - " https://github.com/igorbenav/fastcrud/issues/67", - DeprecationWarning, - ) if filter_config: if isinstance(filter_config, dict): filter_config = FilterConfig(**filter_config) diff --git a/fastcrud/endpoint/helper.py b/fastcrud/endpoint/helper.py index 2f16f72..04747f9 100644 --- a/fastcrud/endpoint/helper.py +++ b/fastcrud/endpoint/helper.py @@ -132,11 +132,13 @@ def _inject_dependencies( """Wraps a list of functions in FastAPI's Depends.""" if funcs is None: return None - + for func in funcs: if not callable(func): - raise TypeError(f"All dependencies must be callable. Got {type(func)} instead.") - + raise TypeError( + f"All dependencies must be callable. Got {type(func)} instead." + ) + return [Depends(func) for func in funcs] diff --git a/tests/sqlalchemy/conftest.py b/tests/sqlalchemy/conftest.py index c8283ee..2b6498b 100644 --- a/tests/sqlalchemy/conftest.py +++ b/tests/sqlalchemy/conftest.py @@ -481,6 +481,15 @@ def client( delete_schema=delete_schema, path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -494,6 +503,15 @@ def client( delete_schema=tier_delete_schema, path="/tier", tags=["tier"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -508,6 +526,15 @@ def client( read_deps=[test_read_dep], path="/multi_pk", tags=["multi_pk"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -531,6 +558,15 @@ def filtered_client( filter_config=FilterConfig(tier_id=None, name=None), path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -554,6 +590,15 @@ def dict_filtered_client( filter_config={"tier_id": None, "name": None}, path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -578,6 +623,15 @@ def invalid_filtered_client( filter_config=filter_config, path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) @@ -593,4 +647,13 @@ def endpoint_creator(test_model, async_session) -> EndpointCreator: delete_schema=DeleteSchemaTest, path="/custom_test", tags=["custom_test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) diff --git a/tests/sqlalchemy/endpoint/test_custom_endpoint_creator.py b/tests/sqlalchemy/endpoint/test_custom_endpoint_creator.py index 0b5969a..e363472 100644 --- a/tests/sqlalchemy/endpoint/test_custom_endpoint_creator.py +++ b/tests/sqlalchemy/endpoint/test_custom_endpoint_creator.py @@ -59,6 +59,15 @@ async def test_custom_endpoint_creator( endpoint_creator=CustomEndpointCreator, path="/custom", tags=["Test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) client.app.include_router(custom_router) diff --git a/tests/sqlalchemy/endpoint/test_deleted_methods.py b/tests/sqlalchemy/endpoint/test_deleted_methods.py index bfa8209..1a095fc 100644 --- a/tests/sqlalchemy/endpoint/test_deleted_methods.py +++ b/tests/sqlalchemy/endpoint/test_deleted_methods.py @@ -16,6 +16,15 @@ async def test_deleted_methods( deleted_methods=["delete"], path="/test_custom", tags=["Test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) client.app.include_router(custom_router) diff --git a/tests/sqlalchemy/endpoint/test_included_methods.py b/tests/sqlalchemy/endpoint/test_included_methods.py index 149805c..a9a848f 100644 --- a/tests/sqlalchemy/endpoint/test_included_methods.py +++ b/tests/sqlalchemy/endpoint/test_included_methods.py @@ -16,6 +16,15 @@ async def test_included_methods( included_methods=["create", "read"], path="/test_custom", tags=["Test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) client.app.include_router(custom_router) diff --git a/tests/sqlmodel/conftest.py b/tests/sqlmodel/conftest.py index 63baef3..5fc90d7 100644 --- a/tests/sqlmodel/conftest.py +++ b/tests/sqlmodel/conftest.py @@ -469,6 +469,15 @@ def client( delete_schema=delete_schema, path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -482,6 +491,15 @@ def client( delete_schema=tier_delete_schema, path="/tier", tags=["tier"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -496,6 +514,15 @@ def client( delete_schema=multi_pk_test_schema, path="/multi_pk", tags=["multi_pk"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -523,6 +550,15 @@ def filtered_client( filter_config=FilterConfig(tier_id=None, name=None), path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -550,6 +586,15 @@ def dict_filtered_client( filter_config={"tier_id": None, "name": None}, path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) ) @@ -578,6 +623,15 @@ def invalid_filtered_client( filter_config=filter_config, path="/test", tags=["test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) @@ -593,4 +647,13 @@ def endpoint_creator(test_model, async_session) -> EndpointCreator: delete_schema=DeleteSchemaTest, path="/custom_test", tags=["custom_test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) diff --git a/tests/sqlmodel/endpoint/test_custom_endpoint_creator.py b/tests/sqlmodel/endpoint/test_custom_endpoint_creator.py index 0b5969a..e363472 100644 --- a/tests/sqlmodel/endpoint/test_custom_endpoint_creator.py +++ b/tests/sqlmodel/endpoint/test_custom_endpoint_creator.py @@ -59,6 +59,15 @@ async def test_custom_endpoint_creator( endpoint_creator=CustomEndpointCreator, path="/custom", tags=["Test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) client.app.include_router(custom_router) diff --git a/tests/sqlmodel/endpoint/test_deleted_methods.py b/tests/sqlmodel/endpoint/test_deleted_methods.py index bfa8209..1a095fc 100644 --- a/tests/sqlmodel/endpoint/test_deleted_methods.py +++ b/tests/sqlmodel/endpoint/test_deleted_methods.py @@ -16,6 +16,15 @@ async def test_deleted_methods( deleted_methods=["delete"], path="/test_custom", tags=["Test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) client.app.include_router(custom_router) diff --git a/tests/sqlmodel/endpoint/test_included_methods.py b/tests/sqlmodel/endpoint/test_included_methods.py index 149805c..a9a848f 100644 --- a/tests/sqlmodel/endpoint/test_included_methods.py +++ b/tests/sqlmodel/endpoint/test_included_methods.py @@ -16,6 +16,15 @@ async def test_included_methods( included_methods=["create", "read"], path="/test_custom", tags=["Test"], + endpoint_names={ + "create": "create", + "read": "get", + "update": "update", + "delete": "delete", + "db_delete": "db_delete", + "read_multi": "get_multi", + "read_paginated": "get_paginated", + }, ) client.app.include_router(custom_router)