From 840275914ad6c105bce38c9f1033c5efd3c51904 Mon Sep 17 00:00:00 2001 From: Anderson Murilo Date: Wed, 7 Jun 2023 17:39:37 -0300 Subject: [PATCH] Adjust on generate_api_example to new way to get auth token on Taiga. --- .../management/commands/_requests_data.py | 4 ++-- .../management/commands/generate_api_examples.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/generate_api_documents_app/generate_api_documents/management/commands/_requests_data.py b/generate_api_documents_app/generate_api_documents/management/commands/_requests_data.py index 3471bd1..a05386b 100644 --- a/generate_api_documents_app/generate_api_documents/management/commands/_requests_data.py +++ b/generate_api_documents_app/generate_api_documents/management/commands/_requests_data.py @@ -10,7 +10,7 @@ from taiga.external_apps.models import Application, ApplicationToken from taiga.webhooks.models import Webhook from taiga.users.models import User -from taiga.auth.tokens import get_token_for_user +from taiga.auth.tokens import CancelToken from taiga.projects.epics.models import RelatedUserStory from taiga.projects.models import Project, Membership from taiga.projects.notifications.models import NotifyPolicy @@ -2731,7 +2731,7 @@ "method": "POST", "url": "/api/v1/users/cancel", "body": { - "cancel_token": get_token_for_user(user, "cancel_account") + "cancel_token": str(CancelToken.for_user(user)) } }), ("importers-trello-auth-url", { diff --git a/generate_api_documents_app/generate_api_documents/management/commands/generate_api_examples.py b/generate_api_documents_app/generate_api_documents/management/commands/generate_api_examples.py index 2da1a66..c1a1052 100644 --- a/generate_api_documents_app/generate_api_documents/management/commands/generate_api_examples.py +++ b/generate_api_documents_app/generate_api_documents/management/commands/generate_api_examples.py @@ -16,7 +16,7 @@ from django.db import connection from taiga.users.models import User -from taiga.auth.tokens import get_token_for_user +from taiga.auth.tokens import AccessToken from ._requests_data import USER_ID, reqs as _reqs @@ -72,13 +72,12 @@ def _execute_requests(self, reqs): user.new_email = "test@sample-email.com" user.save() - user_token = get_token_for_user(user, "authentication") - admin_token = get_token_for_user(admin, "authentication") + user_token = str(AccessToken.for_user(user)) + admin_token = str(AccessToken.for_user(admin)) os.environ["AUTH_TOKEN"] = user_token os.environ["ADMIN_AUTH_TOKEN"] = admin_token host = "http://localhost:8000" - for (key, req) in reqs.items(): print("Generate", key) @@ -110,7 +109,10 @@ def _execute_requests(self, reqs): if result.stdout == b'': response_data = None else: - response_data = json.loads(result.stdout.decode('utf-8')) + try: + response_data = json.loads(result.stdout.decode('utf-8')) + except Exception as e: + print("ERROR on key: ", key) if req.get('index', None) is not None: response_data = response_data[req['index']]