events/tests/api: Send realm_playground events to clients.

We send the whole data set as a part of the event rather than
doing an add/remove operation for couple of reasons:
    * This would make the client logic simpler.
    * The playground data is small enough for us to not worry
      about performance.

Tweaked both `fetch_initial_state_data` and `apply_events` to
handle the new playground event.

Tests added to validate the event matches the expected schema.

Documented realm_playgrounds sections inside /events and
/register to support our openapi validation system in test_events.

Tweaked other tests like test_event_system.py and test_home.py
to account for the new event being generated.

Lastly, documented the changes to the API endpoints in
api/changelog.md and bumped API_FEATURE_LEVEL.

Tweaked by tabbott to add an `id` field in RealmPlayground objects
sent to clients, which is essential to sending the API request to
remove one.
This commit is contained in:
Sumanth V Rao
2020-10-28 08:30:46 +05:30
committed by Tim Abbott
parent d2e5b62dce
commit 1ac8fe7538
11 changed files with 149 additions and 9 deletions

View File

@@ -27,6 +27,7 @@ from zerver.lib.actions import (
do_add_linkifier,
do_add_reaction,
do_add_realm_domain,
do_add_realm_playground,
do_add_streams_to_default_stream_group,
do_add_submessage,
do_change_avatar_fields,
@@ -70,6 +71,7 @@ from zerver.lib.actions import (
do_remove_realm_custom_profile_field,
do_remove_realm_domain,
do_remove_realm_emoji,
do_remove_realm_playground,
do_remove_streams_from_default_stream_group,
do_rename_stream,
do_revoke_multi_use_invite,
@@ -126,6 +128,7 @@ from zerver.lib.event_schema import (
check_realm_emoji_update,
check_realm_export,
check_realm_filters,
check_realm_playgrounds,
check_realm_update,
check_realm_update_dict,
check_realm_user_add,
@@ -176,6 +179,7 @@ from zerver.models import (
Realm,
RealmAuditLog,
RealmDomain,
RealmPlayground,
Service,
Stream,
UserGroup,
@@ -191,6 +195,7 @@ from zerver.tornado.event_queue import (
allocate_client_descriptor,
clear_client_event_queues_for_testing,
)
from zerver.views.realm_playgrounds import access_playground_by_id
class BaseAction(ZulipTestCase):
@@ -1358,6 +1363,24 @@ class NormalActionsTest(BaseAction):
check_realm_domains_remove("events[0]", events[0])
self.assertEqual(events[0]["domain"], "zulip.org")
def test_realm_playground_events(self) -> None:
playground_info = dict(
name="Python playground",
pygments_language="Python",
url_prefix="https://python.example.com",
)
events = self.verify_action(
lambda: do_add_realm_playground(self.user_profile.realm, **playground_info)
)
check_realm_playgrounds("events[0]", events[0])
last_id = RealmPlayground.objects.last().id
realm_playground = access_playground_by_id(self.user_profile.realm, last_id)
events = self.verify_action(
lambda: do_remove_realm_playground(self.user_profile.realm, realm_playground)
)
check_realm_playgrounds("events[0]", events[0])
def test_create_bot(self) -> None:
action = lambda: self.create_bot("test")
events = self.verify_action(action, num_events=2)