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

@@ -1001,11 +1001,12 @@ class RealmPlayground(models.Model):
return f"<RealmPlayground({self.realm.string_id}): {self.pygments_language} {self.name}>"
def get_realm_playgrounds(realm: Realm) -> List[Dict[str, str]]:
playgrounds: List[Dict[str, str]] = []
def get_realm_playgrounds(realm: Realm) -> List[Dict[str, Union[int, str]]]:
playgrounds: List[Dict[str, Union[int, str]]] = []
for playground in RealmPlayground.objects.filter(realm=realm).all():
playgrounds.append(
dict(
id=playground.id,
name=playground.name,
pygments_language=playground.pygments_language,
url_prefix=playground.url_prefix,