backend: Change return value of compose_views.

As a preparatory step to refactoring json_success to accept
request as a parameter, update helper function `compose_views`
in `views.streams.py` to return the response data and call
json_success from view functions that utilize `compose_views`.

Also, updates related test in `zerver.tests.test_subs.py`.
This commit is contained in:
Lauryn Menard
2022-01-31 15:27:58 +01:00
committed by Tim Abbott
parent a4b347bb5f
commit dbddbee5a1
2 changed files with 8 additions and 4 deletions

View File

@@ -374,10 +374,12 @@ def update_subscriptions_backend(
lambda: add_subscriptions_backend(request, user_profile, streams_raw=add),
lambda: remove_subscriptions_backend(request, user_profile, streams_raw=delete),
]
return compose_views(thunks)
data = compose_views(thunks)
return json_success(data)
def compose_views(thunks: List[Callable[[], HttpResponse]]) -> HttpResponse:
def compose_views(thunks: List[Callable[[], HttpResponse]]) -> Dict[str, Any]:
"""
This takes a series of thunks and calls them in sequence, and it
smushes all the json results into a single response when
@@ -391,7 +393,7 @@ def compose_views(thunks: List[Callable[[], HttpResponse]]) -> HttpResponse:
for thunk in thunks:
response = thunk()
json_dict.update(orjson.loads(response.content))
return json_success(json_dict)
return json_dict
check_principals: Validator[Union[List[str], List[int]]] = check_union(