test_subs: Use 'common_subscribe_to_streams' helper function.

In 'test_subs' we were making POST request to add
subscrption using 'self.api_post'.

This commit updates the code to use the test helper
function 'common_subscribe_to_streams' instead.

This prep commit will also help us to avoid adding
'transaction.atomic' context manager to these API calls
individually in the case of error response in the next commit.
This commit is contained in:
Prakhar Pratyush
2024-07-09 16:57:16 +05:30
committed by Tim Abbott
parent b0dbfc96a3
commit 9c614531fb
2 changed files with 85 additions and 102 deletions

View File

@@ -12,7 +12,6 @@ from typing import (
Callable,
Collection,
Dict,
Iterable,
Iterator,
List,
Mapping,
@@ -1439,15 +1438,22 @@ Output:
def common_subscribe_to_streams(
self,
user: UserProfile,
streams: Iterable[str],
subscriptions_raw: List[str] | List[Dict[str, str]],
extra_post_data: Mapping[str, Any] = {},
invite_only: bool = False,
is_web_public: bool = False,
allow_fail: bool = False,
**extra: str,
) -> "TestHttpResponse":
subscriptions: List[Dict[str, str]] = []
for entry in subscriptions_raw:
if isinstance(entry, str):
subscriptions.append({"name": entry})
else:
subscriptions.append(entry)
post_data = {
"subscriptions": orjson.dumps([{"name": stream} for stream in streams]).decode(),
"subscriptions": orjson.dumps(subscriptions).decode(),
"is_web_public": orjson.dumps(is_web_public).decode(),
"invite_only": orjson.dumps(invite_only).decode(),
}