From 356dfaf7fc05bd0729ab511b59cf6009d81d781a Mon Sep 17 00:00:00 2001 From: Florian Reisinger Date: Wed, 18 Sep 2024 13:15:16 +1000 Subject: [PATCH] Update Python service skel * Use `api` as API base instead of service namespace * Update README with shared DB config setup --- skel/django-api/README.md | 19 ++++++++++++++----- .../project_name/tests/test_viewsets.py | 2 +- skel/django-api/project_name/urls/base.py | 3 +-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/skel/django-api/README.md b/skel/django-api/README.md index 90db37a25..ea4788c69 100644 --- a/skel/django-api/README.md +++ b/skel/django-api/README.md @@ -29,6 +29,15 @@ conda create -n hello-manager python=3.12 conda activate hello-manager ``` +### DB setup + +- Add database config to `../../../../../shared/init-db.sql` for centralised DB setup +``` +CREATE ROLE hello_manager; +CREATE DATABASE hello_manager OWNER hello_manager; +``` + + ### Make - At app root, perform @@ -109,17 +118,17 @@ python manage.py runserver_plus ``` ``` -curl -s http://localhost:8000/hlo/v1/hello | jq +curl -s http://localhost:8000/api/v1/hello | jq ``` ``` -curl -s http://localhost:8000/hlo/v1/hello/1 | jq +curl -s http://localhost:8000/api/v1/hello/1 | jq ``` Or visit in browser: -- http://localhost:8000/hlo/v1 -- http://localhost:8000/hlo/v1/hello -- http://localhost:8000/hlo/v1/hello/1 +- http://localhost:8000/api/v1 +- http://localhost:8000/api/v1/hello +- http://localhost:8000/api/v1/hello/1 ### API Doc diff --git a/skel/django-api/project_name/tests/test_viewsets.py b/skel/django-api/project_name/tests/test_viewsets.py index da93e3e4c..d5c141b1a 100644 --- a/skel/django-api/project_name/tests/test_viewsets.py +++ b/skel/django-api/project_name/tests/test_viewsets.py @@ -19,6 +19,6 @@ def test_get_api(self): """ python manage.py test {{project_name}}.tests.test_viewsets.HelloViewSetTestCase.test_get_api """ - response = self.client.get('/hlo/v1/hello/') + response = self.client.get('/api/v1/hello/') logger.info(response.json()) self.assertEqual(response.status_code, 200, 'Ok status response is expected') diff --git a/skel/django-api/project_name/urls/base.py b/skel/django-api/project_name/urls/base.py index ed355a0ab..558010a36 100644 --- a/skel/django-api/project_name/urls/base.py +++ b/skel/django-api/project_name/urls/base.py @@ -4,9 +4,8 @@ from {{project_name}}.viewsets.helloworld import HelloWorldViewSet from {{project_name}}.settings.base import API_VERSION -api_namespace = "hlo" api_version = API_VERSION -api_base = f"{api_namespace}/{api_version}/" +api_base = f"api/{api_version}/" router = OptionalSlashDefaultRouter() router.register(r"hello", HelloWorldViewSet, basename="hello")