From 7dd5b7e37f89f460771d7d7c5894baebbeb4d4ad Mon Sep 17 00:00:00 2001
From: Aurélien Bompard <aurelien@bompard.org>
Date: Apr 26 2017 07:53:23 +0000
Subject: Support Flask 0.10


---

diff --git a/hubs/tests/test_api/test_notifications.py b/hubs/tests/test_api/test_notifications.py
index c224a77..086e5eb 100644
--- a/hubs/tests/test_api/test_notifications.py
+++ b/hubs/tests/test_api/test_notifications.py
@@ -17,7 +17,7 @@ class TestGetNotifications(hubs.tests.APPTest):
             resp = self.app.get('/{}/notifications/'.format(name))
         self.assertEqual(resp.status_code, 200)
         data = json.loads(resp.get_data(as_text=True))
-        self.assertEqual(data, [])
+        self.assertEqual(data, {"notifications": []})
 
     def test_get_notifications_valid_name(self):
         with hubs.tests.auth_set(app, self.user):
@@ -26,9 +26,9 @@ class TestGetNotifications(hubs.tests.APPTest):
 
         self.assertEqual(resp.status_code, 200)
         data = json.loads(resp.get_data(as_text=True))
-        self.assertEqual(len(data), 1)
+        self.assertEqual(len(data["notifications"]), 1)
 
-        for saved in data:
+        for saved in data["notifications"]:
             self.assertEqual(saved['markup'], 'foo')
             self.assertEqual(saved['link'], 'bar')
 
diff --git a/hubs/views/user.py b/hubs/views/user.py
index 5012aea..8c640af 100644
--- a/hubs/views/user.py
+++ b/hubs/views/user.py
@@ -40,7 +40,7 @@ def notifications(user):
     if flask.request.method == 'GET':
         notifications = hubs.models.SavedNotification.by_username(user)
         notifications = [n.__json__() for n in notifications]
-        return flask.jsonify(notifications)
+        return flask.jsonify(dict(notifications=notifications))
 
     if flask.request.method == 'POST':
         data = flask.request.get_json()
diff --git a/hubs/widgets/halp/views.py b/hubs/widgets/halp/views.py
index f1aae71..11ae36e 100644
--- a/hubs/widgets/halp/views.py
+++ b/hubs/widgets/halp/views.py
@@ -4,7 +4,7 @@ import datetime
 import time
 
 import flask
-from flask.signals import template_rendered, before_render_template
+from flask.signals import template_rendered
 
 from hubs.models import Hub
 from hubs.views.utils import get_hub, require_hub_access
@@ -13,6 +13,11 @@ from hubs.widgets.base import WidgetView
 from .functions import GetRequests
 from .utils import find_hubs_for_msg, paginate
 
+try:
+    from flask.signals import before_render_template
+except ImportError:
+    before_render_template = None  # Flask < 0.11
+
 
 class BaseView(WidgetView):
     """The base view to instantiate the widget."""
@@ -190,8 +195,9 @@ def add_view(hub):
         )
     initial["hubs"] = [hub.name]
     context = dict(mode="add", url=post_url, initial=initial)
-    before_render_template.send(
-        flask.current_app, template=template, context=context)
+    if before_render_template is not None:
+        before_render_template.send(
+            flask.current_app, template=template, context=context)
     output = template.render(**context)
     template_rendered.send(
         flask.current_app, template=template, context=context)
diff --git a/hubs/widgets/view.py b/hubs/widgets/view.py
index f02e777..4fdb936 100644
--- a/hubs/widgets/view.py
+++ b/hubs/widgets/view.py
@@ -1,9 +1,14 @@
 from __future__ import unicode_literals, absolute_import
 
 import flask
-from flask.signals import template_rendered, before_render_template
+from flask.signals import template_rendered
 from flask.views import View
 
+try:
+    from flask.signals import before_render_template
+except ImportError:
+    before_render_template = None  # Flask < 0.11
+
 
 class WidgetView(View):
     """
@@ -120,8 +125,9 @@ class WidgetView(View):
         else:
             context.update(self.get_extra_context(instance, *args, **kwargs))
             template = self.get_template()
-            before_render_template.send(
-                flask.current_app, template=template, context=context)
+            if before_render_template is not None:
+                before_render_template.send(
+                    flask.current_app, template=template, context=context)
             output = template.render(**context)
             template_rendered.send(
                 flask.current_app, template=template, context=context)
diff --git a/requirements.txt b/requirements.txt
index 74264a8..4a76840 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
 arrow
-bleach
+bleach<2.0.0
 blinker
 datanommer.models
 decorator
diff --git a/tox.ini b/tox.ini
index a77ac69..291e2b9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,14 @@
 [tox]
-envlist = py{27,34,35},js,docs,lint
+envlist = py{27,34,35}-flask01{0,1,2},js,docs,lint
 skipsdist = True
 
 
 [testenv]
 usedevelop = True
 deps =
-    -rrequirements.txt
+    flask010: flask>=0.10,<0.11
+    flask011: flask>=0.11,<0.12
+    flask012: flask>=0.12,<0.13
     -rtest-requirements.txt
 setenv =
     HUBS_CONFIG={toxinidir}/hubs/tests/hubs_test.cfg

