urls: Simplify URL patterns for presence.

Extracting a section for presence endpoints and using path() rather
than re_path() results in a much cleaner implementation of this
concept.

This eliminates the last case where test_openapi couldn't correctly
match an endpoint documentation with the OpenAPI definitions for it.
This commit is contained in:
Tim Abbott 2020-08-26 15:47:43 -07:00
parent 0b77525814
commit 4f0f734810
2 changed files with 9 additions and 14 deletions

View File

@ -290,10 +290,6 @@ class OpenAPIArgumentsTest(ZulipTestCase):
'/fetch_google_client_id',
# API for video calls we're planning to remove/replace.
'/calls/zoom/create',
#### Documented endpoints not properly detected by tooling.
# Regex with an unnamed capturing group.
'/users/(?!me/)(?P<email>[^/]*)/presence',
}
# Endpoints where the documentation is currently failing our

View File

@ -138,19 +138,11 @@ v1_api_and_json_patterns = [
{'GET': 'zerver.views.presence.get_statuses_for_realm'}),
# users -> zerver.views.users
#
# Since some of these endpoints do something different if used on
# yourself with `/me` as the email, we need to make sure that we
# don't accidentally trigger these. The cleanest way to do that
# is to add a regular expression assertion that it isn't `/me/`
# (or ends with `/me`, in the case of hitting the root URL).
path('users', rest_dispatch,
{'GET': 'zerver.views.users.get_members_backend',
'POST': 'zerver.views.users.create_user_backend'}),
path('users/<int:user_id>/reactivate', rest_dispatch,
{'POST': 'zerver.views.users.reactivate_user_backend'}),
re_path(r'^users/(?!me/)(?P<email>[^/]*)/presence$', rest_dispatch,
{'GET': 'zerver.views.presence.get_presence_backend'}),
path('users/<int:user_id>', rest_dispatch,
{'GET': 'zerver.views.users.get_members_backend',
'PATCH': 'zerver.views.users.update_user_backend',
@ -273,8 +265,6 @@ v1_api_and_json_patterns = [
path('users/me', rest_dispatch,
{'GET': 'zerver.views.users.get_profile_backend',
'DELETE': 'zerver.views.users.deactivate_user_own_backend'}),
path('users/me/presence', rest_dispatch,
{'POST': 'zerver.views.presence.update_active_status_backend'}),
path('users/me/status', rest_dispatch,
{'POST': 'zerver.views.presence.update_user_status_backend'}),
# Endpoint used by mobile devices to register their push
@ -286,6 +276,15 @@ v1_api_and_json_patterns = [
{'POST': 'zerver.views.push_notifications.add_android_reg_id',
'DELETE': 'zerver.views.push_notifications.remove_android_reg_id'}),
# users/*/presnece => zerver.views.presence.
path('users/me/presence', rest_dispatch,
{'POST': 'zerver.views.presence.update_active_status_backend'}),
# It's important that this sit after users/me/presence so that
# Django's URL resolution order doesn't break the
# /users/me/presence endpoint.
path(r'users/<str:email>/presence', rest_dispatch,
{'GET': 'zerver.views.presence.get_presence_backend'}),
# user_groups -> zerver.views.user_groups
path('user_groups', rest_dispatch,
{'GET': 'zerver.views.user_groups.get_user_group'}),