Example #1
0
def delete_realm_playground(request: HttpRequest, user_profile: UserProfile,
                            playground_id: int) -> HttpResponse:
    realm_playground = access_playground_by_id(user_profile.realm,
                                               playground_id)
    do_remove_realm_playground(user_profile.realm,
                               realm_playground,
                               acting_user=user_profile)
    return json_success(request)
Example #2
0
    def test_realm_playground_entries(self) -> None:
        user = self.example_user("iago")
        intial_playgrounds = get_realm_playgrounds(user.realm)
        now = timezone_now()
        playground_id = do_add_realm_playground(
            user.realm,
            acting_user=user,
            name="Python playground",
            pygments_language="Python",
            url_prefix="https://python.example.com",
        )
        added_playground = RealmPlaygroundDict(
            id=playground_id,
            name="Python playground",
            pygments_language="Python",
            url_prefix="https://python.example.com",
        )
        expected_extra_data = {
            "realm_playgrounds": intial_playgrounds + [added_playground],
            "added_playground": added_playground,
        }
        self.assertEqual(
            RealmAuditLog.objects.filter(
                realm=user.realm,
                event_type=RealmAuditLog.REALM_PLAYGROUND_ADDED,
                event_time__gte=now,
                acting_user=user,
                extra_data=orjson.dumps(expected_extra_data).decode(),
            ).count(),
            1,
        )

        now = timezone_now()
        realm_playground = RealmPlayground.objects.get(id=playground_id)
        do_remove_realm_playground(
            user.realm,
            realm_playground,
            acting_user=user,
        )
        removed_playground = {
            "name": "Python playground",
            "pygments_language": "Python",
            "url_prefix": "https://python.example.com",
        }
        expected_extra_data = {
            "realm_playgrounds": intial_playgrounds,
            "removed_playground": removed_playground,
        }
        self.assertEqual(
            RealmAuditLog.objects.filter(
                realm=user.realm,
                event_type=RealmAuditLog.REALM_PLAYGROUND_REMOVED,
                event_time__gte=now,
                acting_user=user,
                extra_data=orjson.dumps(expected_extra_data).decode(),
            ).count(),
            1,
        )