| |
@@ -1,587 +0,0 @@
|
| |
- from __future__ import unicode_literals
|
| |
-
|
| |
- import unittest
|
| |
- from six.moves.urllib.parse import urlparse
|
| |
-
|
| |
- from flask import json
|
| |
- from werkzeug.datastructures import ImmutableMultiDict
|
| |
-
|
| |
- import hubs
|
| |
- from hubs import tests
|
| |
- from hubs.app import app
|
| |
-
|
| |
- import hubs.models
|
| |
-
|
| |
-
|
| |
- class HubsAPITest(hubs.tests.APPTest):
|
| |
-
|
| |
- def test_index_logged_out(self):
|
| |
- result = self.app.get('/', follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, "/login")
|
| |
-
|
| |
- def test_index_logged_in(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/', follow_redirects=True)
|
| |
- # its trying to redirect to login id.fedoraproject.org/openid
|
| |
- # assert the status code of the response
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertNotIn(
|
| |
- 'Not logged in. Click to <a href="/login">login</a>',
|
| |
- result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_logged_out(self):
|
| |
- with tests.auth_set(app, None): # check_auth doesn't load in unittest
|
| |
- result = self.app.get('/ralph', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- match_expected = r'<h5[^>]*>Ralph</h5>'
|
| |
- self.assertRegexpMatches(
|
| |
- result.get_data(as_text=True), match_expected)
|
| |
- str_expected = 'Not logged in.'
|
| |
- self.assertIn(str_expected, result.get_data(as_text=True))
|
| |
-
|
| |
- def test_groups_logged_out(self):
|
| |
- result = self.app.get('/groups', follow_redirects=False)
|
| |
- # assert the status code of the response
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- # this will redirect to fedora.login
|
| |
- self.assertEqual(urlparse(result.location).path, "/login")
|
| |
-
|
| |
- def test_groups_logged_in(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/groups', follow_redirects=True)
|
| |
- # assert the status code of the response
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertIn("ZOMG - is the Hub Of The Month!",
|
| |
- result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_logged_in(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertNotIn(
|
| |
- 'Not logged in. Click to <a href="/login">login</a>',
|
| |
- result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_preview(self):
|
| |
- hub = hubs.models.Hub.by_name('ralph')
|
| |
- hub.config.visibility = "preview"
|
| |
- # Preview hubs are accessible to anonymous users (but some
|
| |
- # widgets may be restricted).
|
| |
- with tests.auth_set(app, None):
|
| |
- result = self.app.get('/ralph', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
-
|
| |
- def test_hub_private(self):
|
| |
- hub = hubs.models.Hub.by_name('ralph')
|
| |
- hub.config.visibility = "private"
|
| |
- self.session.commit()
|
| |
- # Private hubs are not accessible to anonymous users.
|
| |
- with tests.auth_set(app, None):
|
| |
- result = self.app.get('/ralph', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
- # But they are accessible to members.
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
-
|
| |
- def test_hub_json(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/json', follow_redirects=True)
|
| |
- # assert the status code of the response
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- data = {
|
| |
- "config": {
|
| |
- "avatar": "https://seccdn.libravatar.org/avatar/"
|
| |
- "9c9f7784935381befc302fe3c814f9136e7a339"
|
| |
- "53d0318761669b8643f4df55c?s=312&d=retro",
|
| |
- 'chat_channel': None,
|
| |
- 'chat_domain': None,
|
| |
- "left_width": 8,
|
| |
- "summary": "Ralph",
|
| |
- "visibility": "public",
|
| |
- },
|
| |
- "members": ["ralph"],
|
| |
- "name": "ralph",
|
| |
- "owners": ["ralph"],
|
| |
- "subscribers": [],
|
| |
- "widgets": [37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 61],
|
| |
- }
|
| |
- self.assertDictEqual(data, json.loads(result.get_data(as_text=True)))
|
| |
-
|
| |
- def test_hub_private_json(self):
|
| |
- hub = hubs.models.Hub.by_name('ralph')
|
| |
- hub.config.visibility = "private"
|
| |
- self.session.commit()
|
| |
- # Private hubs are not accessible to anonymous users.
|
| |
- with tests.auth_set(app, None):
|
| |
- result = self.app.get('/ralph/json', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
- # But they are accessible to members.
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/json', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
-
|
| |
- def test_hub_edit_get_logged_out(self):
|
| |
- with tests.auth_set(app, None):
|
| |
- result = self.app.get('/ralph/edit', follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, "/login")
|
| |
-
|
| |
- def test_hub_edit_get_logged_in_not_owner(self):
|
| |
- user = tests.FakeAuthorization('not_ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/edit', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
-
|
| |
- def test_hub_edit_get_logged_in_owner(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/edit', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
-
|
| |
- def test_hub_edit_post_logged_out(self):
|
| |
- with tests.auth_set(app, None):
|
| |
- result = self.app.post('/ralph/edit', follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, "/login")
|
| |
-
|
| |
- def test_hub_edit_post_logged_in_not_owner(self):
|
| |
- user = tests.FakeAuthorization('not_ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.post('/ralph/edit', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
-
|
| |
- def test_hub_edit_post_logged_in_owner_empty_data(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.post('/ralph/edit', data={},
|
| |
- follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertNotIn(
|
| |
- 'Not logged in. Click to <a href="/login">login</a>',
|
| |
- result.get_data(as_text=True))
|
| |
- self.assertIn(
|
| |
- '<a href="#" class="dropdown-item">Full Name: '
|
| |
- 'fullname: ralph</a>', result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_edit_post_logged_in_owner_valid_data(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- data = ImmutableMultiDict(
|
| |
- [('right_indexes[]', u'0'), ('right_indexes[]', u'1'),
|
| |
- ('right_indexes[]', u'2'), ('right_indexes[]', u'3'),
|
| |
- ('right_indexes[]', u'4'), ('right_indexes[]', u'5'),
|
| |
- ('right_indexes[]', u'6'), ('right_indexes[]', u'7'),
|
| |
- ('right_indexes[]', u'8'), ('right_widgets[]', u'32'),
|
| |
- ('right_widgets[]', u'33'), ('right_widgets[]', u'34'),
|
| |
- ('right_widgets[]', u'35'), ('right_widgets[]', u'36'),
|
| |
- ('right_widgets[]', u'37'), ('right_widgets[]', u'38'),
|
| |
- ('right_widgets[]', u'39'), ('right_widgets[]', u'40'),
|
| |
- ('js', u'true'), ('left_indexes[]', u'0'),
|
| |
- ('left_indexes[]', u'1'), ('left_widgets[]', u'31'),
|
| |
- ('left_widgets[]', u'32')])
|
| |
- result = self.app.post('/ralph/edit', data=data,
|
| |
- follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertEqual(result.get_data(as_text=True), 'ok')
|
| |
-
|
| |
- def test_hub_edit_post_logged_in_owner_invalid_data_1(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- # some indexes and widgets are not integers
|
| |
- data = ImmutableMultiDict(
|
| |
- [('right_indexes[]', u'0a'), ('right_indexes[]', u'1'),
|
| |
- ('right_indexes[]', u'2'), ('right_indexes[]', u'3'),
|
| |
- ('right_indexes[]', u'4'), ('right_indexes[]', u'5'),
|
| |
- ('right_indexes[]', u'6'), ('right_indexes[]', u'7'),
|
| |
- ('right_indexes[]', u'8'), ('right_widgets[]', u'32'),
|
| |
- ('right_widgets[]', u'33a'), ('right_widgets[]', u'34'),
|
| |
- ('right_widgets[]', u'35'), ('right_widgets[]', u'36'),
|
| |
- ('right_widgets[]', u'37'), ('right_widgets[]', u'38'),
|
| |
- ('right_widgets[]', u'39'), ('right_widgets[]', u'40'),
|
| |
- ('js', u'true'), ('left_indexes[]', u'0a'),
|
| |
- ('left_indexes[]', u'1'), ('left_widgets[]', u'31a'),
|
| |
- ('left_widgets[]', u'32')])
|
| |
- result = self.app.post('/ralph/edit', data=data,
|
| |
- follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 400)
|
| |
-
|
| |
- def test_hub_edit_post_logged_in_owner_invalid_data_2(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- # indexes len don't match widgets len
|
| |
- data = ImmutableMultiDict(
|
| |
- [('right_indexes[]', u'1'), ('right_indexes[]', u'2'),
|
| |
- ('right_indexes[]', u'3'), ('right_indexes[]', u'4'),
|
| |
- ('right_indexes[]', u'5'), ('right_indexes[]', u'6'),
|
| |
- ('right_indexes[]', u'7'), ('right_indexes[]', u'8'),
|
| |
- ('right_widgets[]', u'32'), ('right_widgets[]', u'34'),
|
| |
- ('right_widgets[]', u'35'), ('right_widgets[]', u'36'),
|
| |
- ('right_widgets[]', u'37'), ('right_widgets[]', u'38'),
|
| |
- ('right_widgets[]', u'39'), ('right_widgets[]', u'40'),
|
| |
- ('js', u'true'), ('left_indexes[]', u'0'),
|
| |
- ('left_indexes[]', u'1'), ('left_widgets[]', u'32')])
|
| |
- result = self.app.post('/ralph/edit', data=data,
|
| |
- follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 400)
|
| |
-
|
| |
- def test_login_already_loggedin(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/login', follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(
|
| |
- urlparse(result.location).path,
|
| |
- "/openidc/Authorization")
|
| |
-
|
| |
- def test_hub_add_widget_get_no_args(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/add', follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 400)
|
| |
- expected_str = 'Invalid position provided'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_add_widget_get_with_args(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/add?position=right',
|
| |
- follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- page_html = result.get_data(as_text=True)
|
| |
- self.assertIn('Adding a widget to hub: ralph', page_html)
|
| |
- self.assertIn('<form method="post" action="/ralph/add">', page_html)
|
| |
- self.assertIn('<input type="hidden" name="position" value="right" />',
|
| |
- page_html)
|
| |
-
|
| |
- def test_hub_add_widget_post_no_widget_name(self):
|
| |
- data = {"position": "left"}
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.post(
|
| |
- '/ralph/add', data=data, follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 400)
|
| |
- expected_str = 'Invalid request sent'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_add_widget_post_invalid_widget_name(self):
|
| |
- data = {'widget': 'invalid_widget_name',
|
| |
- 'position': 'right'}
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.post(
|
| |
- '/ralph/add', data=data, follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 404)
|
| |
- expected_str = 'Unknown widget called'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_add_widget_post_valid_widget_name_no_args(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- data = {
|
| |
- 'widget': 'memberships',
|
| |
- 'position': 'right',
|
| |
- }
|
| |
- result = self.app.post('/ralph/add', data=data)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertEqual(
|
| |
- json.loads(result.get_data(as_text=True)),
|
| |
- {"status": "ADDED"})
|
| |
- result = self.app.get('/ralph/edit')
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- page_html = result.get_data(as_text=True)
|
| |
- self.assertIn('data-url="/ralph/w/memberships/', page_html)
|
| |
-
|
| |
- def test_hub_add_widget_post_valid_widget_name_with_args(self):
|
| |
- self.assertEqual(
|
| |
- hubs.models.Widget.query.filter(
|
| |
- hubs.models.Hub.name == "ralph",
|
| |
- hubs.models.Widget.plugin == "about",
|
| |
- ).count(), 1)
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- data = {
|
| |
- 'text': 'text of widget',
|
| |
- 'position': 'right',
|
| |
- }
|
| |
- result = self.app.post('/ralph/add/about', data=data,
|
| |
- follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- self.assertEqual(
|
| |
- json.loads(result.get_data(as_text=True)),
|
| |
- {"status": "ADDED"})
|
| |
- self.assertEqual(
|
| |
- hubs.models.Widget.query.filter(
|
| |
- hubs.models.Hub.name == "ralph",
|
| |
- hubs.models.Widget.plugin == "about",
|
| |
- ).count(), 2)
|
| |
-
|
| |
- def test_hub_edit_widget_get_logged_in(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- result = self.app.get('/ralph/37/edit', follow_redirects=True)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- expected_str = '/ralph/37/edit'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_edit_widget_get_logged_out(self):
|
| |
- result = self.app.get('/ralph/31/edit', follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, "/login")
|
| |
-
|
| |
- def test_hub_edit_widget_post_empty_data_logged_in(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- data = {}
|
| |
- url = '/ralph/37/edit'
|
| |
- result = self.app.post(url, data=data, follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, '/ralph/edit')
|
| |
-
|
| |
- def test_hub_visit_counter_logged_in(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/visit/decause'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(
|
| |
- json.loads(result.get_data(as_text=True)),
|
| |
- {"count": 0})
|
| |
-
|
| |
- result = self.app.post(url)
|
| |
- self.assertEqual(
|
| |
- json.loads(result.get_data(as_text=True)),
|
| |
- {"count": 1})
|
| |
-
|
| |
- # accessing my hub shouldn't increment the count
|
| |
- url = 'visit/ralph'
|
| |
- result = self.app.post(url)
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
-
|
| |
- # visiting no hub while logged should throw a 405
|
| |
- url = 'visit/'
|
| |
- result = self.app.post(url)
|
| |
- self.assertEqual(result.status_code, 405)
|
| |
-
|
| |
- # visiting a hub that doesn't exist should 404
|
| |
- url = 'visit/hub-does-not-exist'
|
| |
- result = self.app.post(url)
|
| |
- self.assertEqual(result.status_code, 404)
|
| |
-
|
| |
- @unittest.skip("Ajax calls don't seem to work in unittests ")
|
| |
- def test_hub_vist_counter_logged_in_2(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/visit/decause'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.get_data(as_text=True), '0')
|
| |
-
|
| |
- url = '/decause'
|
| |
- result = self.app.get(url, follow_redirects=True)
|
| |
-
|
| |
- url = '/visit/decause'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.get_data(as_text=True), '1')
|
| |
-
|
| |
- def test_hub_add_widget_valid_side(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/add/about?position=right'
|
| |
- result = self.app.get(url)
|
| |
- self.assertIn('Adding widget "about" to hub ralph',
|
| |
- result.get_data(as_text=True))
|
| |
-
|
| |
- def test_hub_add_widget_invalid_side(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/add/about?position=invalid'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 400)
|
| |
-
|
| |
- def test_hub_delete(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/37/delete' # 37 is widget fedmsgstats for ralph
|
| |
- result = self.app.post(url)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertIn('/ralph/edit', result.get_data(as_text=True))
|
| |
-
|
| |
- def test_source_name(self):
|
| |
- with tests.auth_set(app, None):
|
| |
- url = '/source/about'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- expected_str = 'https://pagure.io/fedora-hubs/' \
|
| |
- 'blob/develop/f/hubs/widgets/about/__init__.py'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
-
|
| |
- def test_source_name_not_existent(self):
|
| |
- with tests.auth_set(app, None):
|
| |
- url = '/source/notexistent'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 404)
|
| |
-
|
| |
- def test_hub_config_get(self):
|
| |
- expected = {
|
| |
- "hubconfig": {
|
| |
- "summary": "Ralph",
|
| |
- "left_width": 8,
|
| |
- "avatar": (
|
| |
- "https://seccdn.libravatar.org/avatar/9c9f7784935381befc30"
|
| |
- "2fe3c814f9136e7a33953d0318761669b8643f4df55c"
|
| |
- "?s=312&d=retro"
|
| |
- ),
|
| |
- "chat_channel": None,
|
| |
- "chat_domain": None,
|
| |
- "visibility": "public",
|
| |
- },
|
| |
- "general": {
|
| |
- "chat_networks": app.config["CHAT_NETWORKS"],
|
| |
- "roles": ["owner", "member"],
|
| |
- "hub_visibility": hubs.models.HubConfig.VISIBILITY,
|
| |
- },
|
| |
- "users": {
|
| |
- "member": [],
|
| |
- "owner": [{
|
| |
- "fullname": "Ralph",
|
| |
- "locked": True,
|
| |
- "role": "owner",
|
| |
- "username": "ralph",
|
| |
- }],
|
| |
- },
|
| |
- }
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "OK")
|
| |
- self.assertDictEqual(result_data["result"], expected)
|
| |
-
|
| |
- def test_hub_config_post(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config?category=config'
|
| |
- result = self.app.post(url, data={
|
| |
- "summary": "changed value",
|
| |
- "chat_domain": "",
|
| |
- })
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "OK")
|
| |
- self.assertEqual(
|
| |
- result_data["result"]["hubconfig"]["summary"],
|
| |
- "changed value")
|
| |
- self.assertEqual(
|
| |
- result_data["result"]["hubconfig"]["chat_domain"],
|
| |
- app.config["CHAT_NETWORKS"][0]["domain"])
|
| |
-
|
| |
- def test_hub_config_post_unknown_post_data(self):
|
| |
- # Unknown POST data is silently ignored
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config?category=config'
|
| |
- result = self.app.post(url, data={"non_existant": "dummy"})
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "ERROR")
|
| |
- self.assertEqual(result_data["message"], "Invalid value(s)")
|
| |
- self.assertIn("non_existant", result_data["fields"])
|
| |
- self.assertEqual(
|
| |
- result_data["fields"]["non_existant"],
|
| |
- "Unexpected parameter."
|
| |
- )
|
| |
-
|
| |
- def test_hub_config_post_invalid_chat_domain(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config?category=config'
|
| |
- result = self.app.post(url, data={"chat_domain": "dummy"})
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "ERROR")
|
| |
- self.assertEqual(result_data["message"], "Invalid value(s)")
|
| |
- self.assertIn("chat_domain", result_data["fields"])
|
| |
- self.assertEqual(
|
| |
- result_data["fields"]["chat_domain"],
|
| |
- "Unsupported chat domain."
|
| |
- )
|
| |
-
|
| |
- def test_hub_config_get_unauthorized(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/decause/config'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
-
|
| |
- def test_hub_config_post_unauthorized(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/decause/config?category=config'
|
| |
- result = self.app.post(url, data={"summary": "Defaced!"})
|
| |
- self.assertEqual(result.status_code, 403)
|
| |
-
|
| |
- def test_hub_config_suggest_users_no_filter(self):
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- expected = [
|
| |
- u.username for u in
|
| |
- hubs.models.User.query.order_by(
|
| |
- hubs.models.User.username
|
| |
- ).all()]
|
| |
- # Check without filter
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config/suggest-users'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "OK")
|
| |
- self.assertListEqual(result_data["results"], expected)
|
| |
-
|
| |
- def test_hub_config_suggest_users_filter_owners(self):
|
| |
- # Filters on owners
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- expected = [
|
| |
- u.username for u in
|
| |
- hubs.models.User.query.order_by(
|
| |
- hubs.models.User.username
|
| |
- ).filter(
|
| |
- hubs.models.User.username != "ralph"
|
| |
- ).all()]
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config/suggest-users?exclude-role=owner'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "OK")
|
| |
- self.assertListEqual(result_data["results"], expected)
|
| |
-
|
| |
- def test_hub_config_suggest_users_filter_members(self):
|
| |
- # Filters on members
|
| |
- user = tests.FakeAuthorization('ralph')
|
| |
- hub = hubs.models.Hub.get('ralph')
|
| |
- decause = hubs.models.User.query.get("decause")
|
| |
- devyani7 = hubs.models.User.query.get("devyani7")
|
| |
- hub.subscribe(decause, "member")
|
| |
- hub.subscribe(devyani7, "member")
|
| |
- expected = [
|
| |
- u.username for u in
|
| |
- hubs.models.User.query.order_by(
|
| |
- hubs.models.User.username
|
| |
- ).filter(
|
| |
- hubs.models.User.username != "decause",
|
| |
- hubs.models.User.username != "devyani7"
|
| |
- ).all()]
|
| |
- with tests.auth_set(app, user):
|
| |
- url = '/ralph/config/suggest-users?exclude-role=member'
|
| |
- result = self.app.get(url)
|
| |
- self.assertEqual(result.status_code, 200)
|
| |
- result_data = json.loads(result.get_data(as_text=True))
|
| |
- self.assertEqual(result_data["status"], "OK")
|
| |
- self.assertListEqual(result_data["results"], expected)
|
| |
The current situation with unit tests has some shortcomings, this branch brings the following improvements:
test_fedora_hubs_api.py
file into smaller files in a subdirectoryhubs.tests
to handle more cases and be more versatileOnce again, there are many commits, .... you know the drill ;-)
The aim is to make it easier to run the tests, and to make them more independent from the production database / cache / fedmsg config.