test helpers: Tweak common_subscribe_to_streams.

We assert that the post was successful, to give
more immediate feedback for tests that don't
bother to check the return value and may be
implicitly assuming this method just works in
all cases.

And we also make it more convenient for tests
that are happy-path tests--they don't have to
do the assertion themselves.  (And they're still
free to do deeper checks on the json.)

We opt out with allow_fail=True.  We probably want
a more direct API eventually for tests that are
clearly trying to test the failure path for
subscribing to streams.

It's possible that a couple tests here that I added
allow_fail=True to just have flawed data setup--
I don't have time to investigate all cases, but
hopefully they will at least stand out more.
This commit is contained in:
Steve Howell
2020-06-17 21:49:33 +00:00
committed by Tim Abbott
parent 2e9f689add
commit fbe45fa889
3 changed files with 63 additions and 73 deletions

View File

@@ -756,11 +756,14 @@ class ZulipTestCase(TestCase):
# Subscribe to a stream by making an API request
def common_subscribe_to_streams(self, user: UserProfile, streams: Iterable[str],
extra_post_data: Dict[str, Any]={}, invite_only: bool=False,
allow_fail: bool=False,
**kwargs: Any) -> HttpResponse:
post_data = {'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
'invite_only': ujson.dumps(invite_only)}
post_data.update(extra_post_data)
result = self.api_post(user, "/api/v1/users/me/subscriptions", post_data, **kwargs)
if not allow_fail:
self.assert_json_success(result)
return result
def check_user_subscribed_only_to_streams(self, user_name: str,