diff --git a/testproject/testapp/tests/test_urls/test_urls.py b/testproject/testapp/tests/test_urls/test_urls.py index ac37c40d..b619a187 100644 --- a/testproject/testapp/tests/test_urls/test_urls.py +++ b/testproject/testapp/tests/test_urls/test_urls.py @@ -1,5 +1,6 @@ import json import pathlib +from contextlib import suppress import pytest from deepdiff import DeepDiff @@ -26,7 +27,33 @@ def get_all_urls(patterns, prefix=""): else: pattern_str = prefix + pattern.pattern.regex.pattern name = pattern.name if pattern.name else None - urls.append({"pattern": pattern_str, "name": name}) + allowed_methods = [] + if hasattr(pattern, "callback"): + view = pattern.callback + if hasattr(view, "http_method_names"): + allowed_methods = view.http_method_names + elif hasattr(view, "actions"): + allowed_methods = list(view.actions.keys()) + elif hasattr( + view, "view_class" + ): # assume all, even though probably not + allowed_methods = view.view_class.http_method_names + else: + raise NotImplementedError( + "Function based views are not supported" + ) + # head is not present in the CI for some reason... + with suppress(ValueError): + i = allowed_methods.index("head") + del allowed_methods[i] + + urls.append( + { + "pattern": pattern_str, + "name": name, + "allowed_methods": allowed_methods, + } + ) return urls current_urls = sorted(get_all_urls(url_patterns), key=lambda x: x["pattern"]) diff --git a/testproject/testapp/tests/test_urls/urls_snapshot.json b/testproject/testapp/tests/test_urls/urls_snapshot.json index 659e01a3..b52be00f 100644 --- a/testproject/testapp/tests/test_urls/urls_snapshot.json +++ b/testproject/testapp/tests/test_urls/urls_snapshot.json @@ -1,134 +1,313 @@ [ { "pattern": "^auth/^jwt/create/?", - "name": "jwt-create" + "name": "jwt-create", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^auth/^jwt/refresh/?", - "name": "jwt-refresh" + "name": "jwt-refresh", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^auth/^jwt/verify/?", - "name": "jwt-verify" + "name": "jwt-verify", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^auth/^o/(?P\\S+)/$", - "name": "provider-auth" + "name": "provider-auth", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^auth/^token/login/?$", - "name": "login" + "name": "login", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^auth/^token/logout/?$", - "name": "logout" + "name": "logout", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^auth/^users/$", - "name": "user-list" + "name": "user-list", + "allowed_methods": [ + "get", + "post" + ] }, { "pattern": "^auth/^users/(?P[^/.]+)/$", - "name": "user-detail" + "name": "user-detail", + "allowed_methods": [ + "get", + "put", + "patch", + "delete" + ] }, { "pattern": "^auth/^users/(?P[^/.]+)\\.(?P[a-z0-9]+)/?$", - "name": "user-detail" + "name": "user-detail", + "allowed_methods": [ + "get", + "put", + "patch", + "delete" + ] }, { "pattern": "^auth/^users/activation/$", - "name": "user-activation" + "name": "user-activation", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/activation\\.(?P[a-z0-9]+)/?$", - "name": "user-activation" + "name": "user-activation", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/me/$", - "name": "user-me" + "name": "user-me", + "allowed_methods": [ + "get", + "put", + "patch", + "delete" + ] }, { "pattern": "^auth/^users/me\\.(?P[a-z0-9]+)/?$", - "name": "user-me" + "name": "user-me", + "allowed_methods": [ + "get", + "put", + "patch", + "delete" + ] }, { "pattern": "^auth/^users/resend_activation/$", - "name": "user-resend-activation" + "name": "user-resend-activation", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/resend_activation\\.(?P[a-z0-9]+)/?$", - "name": "user-resend-activation" + "name": "user-resend-activation", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_password/$", - "name": "user-reset-password" + "name": "user-reset-password", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_password\\.(?P[a-z0-9]+)/?$", - "name": "user-reset-password" + "name": "user-reset-password", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_password_confirm/$", - "name": "user-reset-password-confirm" + "name": "user-reset-password-confirm", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_password_confirm\\.(?P[a-z0-9]+)/?$", - "name": "user-reset-password-confirm" + "name": "user-reset-password-confirm", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_username/$", - "name": "user-reset-username" + "name": "user-reset-username", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_username\\.(?P[a-z0-9]+)/?$", - "name": "user-reset-username" + "name": "user-reset-username", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_username_confirm/$", - "name": "user-reset-username-confirm" + "name": "user-reset-username-confirm", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/reset_username_confirm\\.(?P[a-z0-9]+)/?$", - "name": "user-reset-username-confirm" + "name": "user-reset-username-confirm", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/set_password/$", - "name": "user-set-password" + "name": "user-set-password", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/set_password\\.(?P[a-z0-9]+)/?$", - "name": "user-set-password" + "name": "user-set-password", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/set_username/$", - "name": "user-set-username" + "name": "user-set-username", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users/set_username\\.(?P[a-z0-9]+)/?$", - "name": "user-set-username" + "name": "user-set-username", + "allowed_methods": [ + "post" + ] }, { "pattern": "^auth/^users\\.(?P[a-z0-9]+)/?$", - "name": "user-list" + "name": "user-list", + "allowed_methods": [ + "get", + "post" + ] }, { "pattern": "^webauthn-example/$", - "name": null + "name": null, + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^webauthn/^login/$", - "name": "webauthn_login" + "name": "webauthn_login", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^webauthn/^login_request/$", - "name": "webauthn_login_request" + "name": "webauthn_login_request", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^webauthn/^signup/(?P.+)/$", - "name": "webauthn_signup" + "name": "webauthn_signup", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] }, { "pattern": "^webauthn/^signup_request/$", - "name": "webauthn_signup_request" + "name": "webauthn_signup_request", + "allowed_methods": [ + "get", + "post", + "put", + "patch", + "delete", + "options", + "trace" + ] } ]