From d90f85b8570246a34a21156f7f46af7b8ae377e7 Mon Sep 17 00:00:00 2001
From: Aurélien Bompard <aurelien@bompard.org>
Date: Jul 26 2017 16:42:52 +0000
Subject: [PATCH 1/2] Fix unit tests


---

diff --git a/hubs/static/client/package.json b/hubs/static/client/package.json
index d0e6a6c..420bd05 100644
--- a/hubs/static/client/package.json
+++ b/hubs/static/client/package.json
@@ -42,7 +42,10 @@
     "unmockedModulePathPatterns": [
       "<rootDir>/node_modules/react/",
       "<rootDir>/node_modules/react-dom/",
-      "<rootDir>/node_modules/react-addons-test-utils/"
+      "<rootDir>/node_modules/prop-types/",
+      "<rootDir>/node_modules/react-addons-test-utils/",
+      "<rootDir>/node_modules/react-intl/",
+      "<rootDir>/node_modules/intl-messageformat/"
     ]
   },
   "author": "Eric Barbour <ebarbour@redhat.com>",
diff --git a/hubs/tests/test_widget_view.py b/hubs/tests/test_widget_view.py
index 328d207..6b17af2 100644
--- a/hubs/tests/test_widget_view.py
+++ b/hubs/tests/test_widget_view.py
@@ -1,13 +1,9 @@
 from __future__ import unicode_literals
 
-import six
-from mock import Mock
-
 from hubs.app import app
 from hubs.tests import APPTest
 from hubs.widgets.base import Widget
-from hubs.widgets.caching import CachedFunction
-from hubs.widgets.view import WidgetView, RootWidgetView
+from hubs.widgets.view import RootWidgetView
 
 
 class TestingWidget(Widget):
diff --git a/hubs/tests/utils/test_pkgdb.py b/hubs/tests/utils/test_pkgdb.py
index 36f4905..c5f193a 100644
--- a/hubs/tests/utils/test_pkgdb.py
+++ b/hubs/tests/utils/test_pkgdb.py
@@ -20,7 +20,7 @@ class PkgdbUtilsTest(APPTest):
         cache.delete("owned_packages:abompard")
 
     def _is_cached(self):
-        result = cache.get("owned_packages:abompard", ignore_expiration=True)
+        result = cache.get(b"owned_packages:abompard", ignore_expiration=True)
         return not isinstance(result, dogpile.cache.api.NoValue)
 
     def test_get_owned_packages(self):
diff --git a/hubs/tests/widgets/test_about.py b/hubs/tests/widgets/test_about.py
index 0766de2..1cb4ab1 100644
--- a/hubs/tests/widgets/test_about.py
+++ b/hubs/tests/widgets/test_about.py
@@ -18,6 +18,7 @@ class TestAbout(WidgetTest):
             'text': 'Testing.',
             'title': "<span class='glyphicon glyphicon-info-sign' "
                      "aria-hidden='true'></span> About",
+            'edit_mode': False,
         })
 
     def test_view_authz(self):
diff --git a/hubs/tests/widgets/test_contact.py b/hubs/tests/widgets/test_contact.py
index 03f24e7..8bea137 100644
--- a/hubs/tests/widgets/test_contact.py
+++ b/hubs/tests/widgets/test_contact.py
@@ -86,6 +86,7 @@ class ContactsTest(WidgetTest):
             'location': 'United States',
             'timezone': 'UTC',
             'usergroup': True,
+            'edit_mode': False,
         })
 
     def test_view_authz(self):
diff --git a/hubs/tests/widgets/test_fedmsgstats.py b/hubs/tests/widgets/test_fedmsgstats.py
index c7f7ce2..2a4508a 100644
--- a/hubs/tests/widgets/test_fedmsgstats.py
+++ b/hubs/tests/widgets/test_fedmsgstats.py
@@ -15,15 +15,16 @@ class TestFedmsgStats(WidgetTest):
         response = self.check_url('/ralph/%i/json' % widget.idx, user)
         data = json.loads(response.get_data(as_text=True))
         self.assertDictEqual(data['data'], {
-            u'fedmsgs': 83854,
-            u'fedmsgs_text': u'83,854',
-            u'subscribers': [],
-            u'subscribed_to': [],
-            u'subscribers_text': u'0',
-            u'subscribed_text': u'0',
-            u'username': u'ralph',
-            u'hub_subscribe_url': u'/api/hub/ralph/subscribe',
-            u'hub_unsubscribe_url': u'/api/hub/ralph/unsubscribe',
+            'fedmsgs': 83854,
+            'fedmsgs_text': '83,854',
+            'subscribers': [],
+            'subscribed_to': [],
+            'subscribers_text': '0',
+            'subscribed_text': '0',
+            'username': 'ralph',
+            'hub_subscribe_url': '/api/hub/ralph/subscribe',
+            'hub_unsubscribe_url': '/api/hub/ralph/unsubscribe',
+            'edit_mode': False,
         })
 
     def test_view_authz(self):
diff --git a/hubs/tests/widgets/test_library.py b/hubs/tests/widgets/test_library.py
index f8651e4..11e4c92 100644
--- a/hubs/tests/widgets/test_library.py
+++ b/hubs/tests/widgets/test_library.py
@@ -23,6 +23,7 @@ class TestLibrary(WidgetTest):
                 "urls": [
                     "<a href=\"ralph/\">ralph/</a>"
                 ],
+                'edit_mode': False,
             },
             "description": None,
             "hub": "ralph",
diff --git a/hubs/widgets/about/__init__.py b/hubs/widgets/about/__init__.py
index 196ace3..0c01124 100644
--- a/hubs/widgets/about/__init__.py
+++ b/hubs/widgets/about/__init__.py
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
 
 from hubs.widgets import validators
 from hubs.widgets.base import Widget
-from hubs.widgets.view import WidgetView, RootWidgetView
+from hubs.widgets.view import RootWidgetView
 
 
 class About(Widget):
diff --git a/hubs/widgets/badges/__init__.py b/hubs/widgets/badges/__init__.py
index ee1ff98..1e5fcea 100644
--- a/hubs/widgets/badges/__init__.py
+++ b/hubs/widgets/badges/__init__.py
@@ -5,7 +5,7 @@ import requests
 
 from hubs.widgets import validators
 from hubs.widgets.base import Widget
-from hubs.widgets.view import WidgetView, RootWidgetView
+from hubs.widgets.view import RootWidgetView
 from hubs.widgets.caching import CachedFunction
 
 
diff --git a/hubs/widgets/bugzilla/__init__.py b/hubs/widgets/bugzilla/__init__.py
index a57d72b..8731c8a 100644
--- a/hubs/widgets/bugzilla/__init__.py
+++ b/hubs/widgets/bugzilla/__init__.py
@@ -7,7 +7,7 @@ import pkgwat.api
 from hubs.utils.pkgdb import get_owned_packages
 from hubs.widgets import validators
 from hubs.widgets.base import Widget
-from hubs.widgets.view import WidgetView, RootWidgetView
+from hubs.widgets.view import RootWidgetView
 from hubs.widgets.caching import CachedFunction
 
 
diff --git a/hubs/widgets/view.py b/hubs/widgets/view.py
index c5aec95..3794bb3 100644
--- a/hubs/widgets/view.py
+++ b/hubs/widgets/view.py
@@ -147,6 +147,8 @@ class RootWidgetView(WidgetView):
         """
         Export the edit mode status to the template
         """
-        context = super(RootWidgetView, self).get_extra_context(*args, **kwargs)
-        context["edit_mode"] = flask.request.args.get("editmode", "", type=bool)
+        context = super(RootWidgetView, self).get_extra_context(
+            *args, **kwargs)
+        context["edit_mode"] = flask.request.args.get(
+            "editmode", False, type=bool)
         return context
diff --git a/hubs/widgets/workflow/pendingacls.py b/hubs/widgets/workflow/pendingacls.py
index 8db3aeb..f7b0c4b 100644
--- a/hubs/widgets/workflow/pendingacls.py
+++ b/hubs/widgets/workflow/pendingacls.py
@@ -5,7 +5,7 @@ import requests
 from hubs.utils import username2avatar
 from hubs.widgets import validators
 from hubs.widgets.base import Widget
-from hubs.widgets.view import WidgetView, RootWidgetView
+from hubs.widgets.view import RootWidgetView
 from hubs.widgets.caching import CachedFunction
 
 
diff --git a/hubs/widgets/workflow/updates2stable.py b/hubs/widgets/workflow/updates2stable.py
index 413631b..6b87c03 100644
--- a/hubs/widgets/workflow/updates2stable.py
+++ b/hubs/widgets/workflow/updates2stable.py
@@ -4,7 +4,7 @@ import requests
 
 from hubs.widgets import validators
 from hubs.widgets.base import Widget
-from hubs.widgets.view import WidgetView, RootWidgetView
+from hubs.widgets.view import RootWidgetView
 from hubs.widgets.caching import CachedFunction
 
 

From 36f6714e9f1e5b226313a6f06a8d7836f22afe9a Mon Sep 17 00:00:00 2001
From: Aurélien Bompard <aurelien@bompard.org>
Date: Jul 26 2017 16:45:36 +0000
Subject: [PATCH 2/2] Only top-level elements should instantiate IntlProvider, not components


---

diff --git a/hubs/static/client/app/components/feed/Feed.jsx b/hubs/static/client/app/components/feed/Feed.jsx
index ec6b037..a11176e 100644
--- a/hubs/static/client/app/components/feed/Feed.jsx
+++ b/hubs/static/client/app/components/feed/Feed.jsx
@@ -1,7 +1,6 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import {
-  IntlProvider,
   defineMessages,
   FormattedMessage,
   } from 'react-intl';
@@ -26,15 +25,13 @@ export default class Feed extends React.Component {
         );
     });
     return (
-      <IntlProvider locale={navigator.language}>
-        <div className="component-feed">
-          { (items.length == 0 && this.props.loaded) ?
-            <FormattedMessage {...messages.no_items} tagName="i" />
-            :
-            items
-          }
-        </div>
-      </IntlProvider>
+      <div className="component-feed">
+        { (items.length == 0 && this.props.loaded) ?
+          <FormattedMessage {...messages.no_items} tagName="i" />
+          :
+          items
+        }
+      </div>
     );
   }
 
diff --git a/hubs/static/client/app/widgets/feed/Widget.jsx b/hubs/static/client/app/widgets/feed/Widget.jsx
index b266609..b60a6eb 100644
--- a/hubs/static/client/app/widgets/feed/Widget.jsx
+++ b/hubs/static/client/app/widgets/feed/Widget.jsx
@@ -1,4 +1,5 @@
 import React from 'react';
+import {IntlProvider} from 'react-intl';
 import ItemsGetter from '../../components/feed/ItemsGetter.jsx';
 import Feed from '../../components/feed/Feed.jsx';
 
@@ -23,19 +24,21 @@ export default class Widget extends React.Component {
 
   render() {
     return (
-      <ItemsGetter
-        url={this.props.url}
-        sse={{
-          eventName: "hubs:widget-updated",
-          shouldReload: (idx) => (parseInt(idx) === this.props.widgetIdx),
-        }}
-        handleData={this.handleServerData}
-        >
-        <Feed
-          items={this.state.items}
-          loaded={this.state.loaded}
-          />
-      </ItemsGetter>
+      <IntlProvider locale={navigator.language}>
+        <ItemsGetter
+          url={this.props.url}
+          sse={{
+            eventName: "hubs:widget-updated",
+            shouldReload: (idx) => (parseInt(idx) === this.props.widgetIdx),
+          }}
+          handleData={this.handleServerData}
+          >
+          <Feed
+            items={this.state.items}
+            loaded={this.state.loaded}
+            />
+        </ItemsGetter>
+      </IntlProvider>
     );
   }
 

