Skip to content

Commit

Permalink
add method names to test urls test (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwojcik authored Nov 10, 2024
1 parent 016ca3a commit 9deaa63
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 34 deletions.
29 changes: 28 additions & 1 deletion testproject/testapp/tests/test_urls/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pathlib
from contextlib import suppress

import pytest
from deepdiff import DeepDiff
Expand All @@ -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"])
Expand Down
245 changes: 212 additions & 33 deletions testproject/testapp/tests/test_urls/urls_snapshot.json
Original file line number Diff line number Diff line change
@@ -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<provider>\\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<id>[^/.]+)/$",
"name": "user-detail"
"name": "user-detail",
"allowed_methods": [
"get",
"put",
"patch",
"delete"
]
},
{
"pattern": "^auth/^users/(?P<id>[^/.]+)\\.(?P<format>[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<format>[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<format>[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<format>[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<format>[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<format>[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<format>[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<format>[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<format>[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<format>[a-z0-9]+)/?$",
"name": "user-set-username"
"name": "user-set-username",
"allowed_methods": [
"post"
]
},
{
"pattern": "^auth/^users\\.(?P<format>[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<ukey>.+)/$",
"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"
]
}
]

0 comments on commit 9deaa63

Please sign in to comment.