| |
@@ -1,7 +1,10 @@
|
| |
from __future__ import unicode_literals
|
| |
|
| |
from six.moves.urllib.parse import urlparse
|
| |
+ import mock
|
| |
+ import json
|
| |
|
| |
+ import hubs
|
| |
from hubs.app import app
|
| |
from hubs.tests import APPTest, FakeAuthorization, auth_set
|
| |
|
| |
@@ -41,11 +44,71 @@
|
| |
# this will redirect to fedora.login
|
| |
self.assertEqual(urlparse(result.location).path, "/")
|
| |
|
| |
- def test_groups_logged_in(self):
|
| |
+
|
| |
+ class RootGroupsTestCase(APPTest):
|
| |
+ def _parse_setuppage_json(self, result):
|
| |
+ result = result.get_data(as_text=True)
|
| |
+ result = result.partition('function() {\n Hubs.setupPage("page", ')[2]
|
| |
+ result = result.partition(');\n})();\n</script>')[0]
|
| |
+ return json.loads(result)
|
| |
+
|
| |
+ def _add_assoc(self, hubname, username, role):
|
| |
+ hub = hubs.models.Hub.query.get(hubname)
|
| |
+ user = hubs.models.User.query.get(username)
|
| |
+ self.session.add(hubs.models.Association(
|
| |
+ hub=hub, user=user, role=role))
|
| |
+
|
| |
+ @mock.patch('hubs.views.root.log.warning')
|
| |
+ def test_groups_HOTM_not_found(self, warning):
|
| |
+ """
|
| |
+ Test we log a warning if the HUB_OF_THE_MONTH value
|
| |
+ set in the config does not name a hub that exists.
|
| |
+ The config in the base tests sets commops, as the
|
| |
+ HOTM, but this hub doesnt exist in the base testcase
|
| |
+ """
|
| |
user = FakeAuthorization('ralph')
|
| |
with auth_set(app, user):
|
| |
result = self.app.get('/groups/', follow_redirects=True)
|
| |
- # assert the status code of the response
|
| |
+ data = self._parse_setuppage_json(result)
|
| |
+
|
| |
+ self.assertEqual(result.status_code, 200)
|
| |
+ warning.assert_called_once_with("The hub (commops) set as the "
|
| |
+ "HUB_OF_THE_MONTH in the config "
|
| |
+ "does not exist")
|
| |
+ self.assertEquals(data["hubslist"]["hub_of_the_month"], None)
|
| |
+
|
| |
+ @mock.patch('hubs.views.root.log.warning')
|
| |
+ @mock.patch('hubs.app.app.config.get', return_value="infra")
|
| |
+ def test_groups_HOTM_found(self, config, warning):
|
| |
+ """
|
| |
+ Test that we return the HOTM in the JSON we give to
|
| |
+ the react component
|
| |
+ """
|
| |
+ user = FakeAuthorization('ralph')
|
| |
+ with auth_set(app, user):
|
| |
+ result = self.app.get('/groups/', follow_redirects=True)
|
| |
+ data = self._parse_setuppage_json(result)
|
| |
+
|
| |
+ self.assertEqual(result.status_code, 200)
|
| |
+ warning.assert_not_called()
|
| |
+ self.assertEquals(data["hubslist"]
|
| |
+ ["hub_of_the_month"]
|
| |
+ ["name"], "infra")
|
| |
+
|
| |
+ def test_groups(self):
|
| |
+ """
|
| |
+ Test that we return the correct groups list
|
| |
+ in the JSON we give to the react component
|
| |
+ """
|
| |
+ user = FakeAuthorization('ralph')
|
| |
+ self._add_assoc("infra", "ralph", "stargazer")
|
| |
+ self._add_assoc("infra", "ralph", "member")
|
| |
+ self._add_assoc("infra", "ralph", "subscriber")
|
| |
+ with auth_set(app, user):
|
| |
+ result = self.app.get('/groups/', follow_redirects=True)
|
| |
+ data = self._parse_setuppage_json(result)
|
| |
self.assertEqual(result.status_code, 200)
|
| |
- self.assertIn("ZOMG - is the Hub Of The Month!",
|
| |
- result.get_data(as_text=True))
|
| |
+ self.assertEqual(len(data["hubslist"]["hubs"]), 3)
|
| |
+ self.assertEqual(data["hubslist"]["hubs"][0]["name"], "i18n")
|
| |
+ self.assertEqual(data["hubslist"]["hubs"][1]["name"], "infra")
|
| |
+ self.assertEqual(data["hubslist"]["hubs"][2]["name"], "old")
|
| |
Updates the allgroups page.
This updates the page to kinda partially use react. We will probably want to update this in the future to a full react-style component, with a proper backend APO point so we can enable filtering on the list ajax-style, but for MVP, i think a simple static list of available teams hubs is a go!