| |
@@ -2,11 +2,8 @@
|
| |
|
| |
import unittest
|
| |
from six.moves.urllib.parse import urlparse
|
| |
- import ast # import for string to dict conversion without unicode
|
| |
|
| |
from flask import json
|
| |
- from os.path import dirname
|
| |
- import vcr
|
| |
from mock import mock
|
| |
from werkzeug.datastructures import ImmutableMultiDict
|
| |
|
| |
@@ -16,8 +13,6 @@
|
| |
|
| |
import hubs.models
|
| |
|
| |
- import fedmsg.config
|
| |
-
|
| |
|
| |
class HubsAPITest(hubs.tests.APPTest):
|
| |
def test_index_logged_out(self):
|
| |
@@ -214,30 +209,42 @@
|
| |
"/openidc/Authorization")
|
| |
|
| |
def test_hub_add_widget_get_no_args(self):
|
| |
- result = self.app.get('/ralph/add', follow_redirects=False)
|
| |
+ 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):
|
| |
- result = self.app.get('/ralph/add?position=right',
|
| |
- follow_redirects=True)
|
| |
+ 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)
|
| |
- expected_str = 'Adding a widget to hub: ralph'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
- expected_str = "url: 'add/' + $('#widget').val() + '?position=right',"
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
+ 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 = {}
|
| |
- result = self.app.post('/ralph/add', data=data, follow_redirects=False)
|
| |
+ 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_name': 'invalid_widget_name'}
|
| |
- result = self.app.post('/ralph/add', data=data, follow_redirects=False)
|
| |
+ 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))
|
| |
@@ -245,31 +252,43 @@
|
| |
def test_hub_add_widget_post_valid_widget_name_no_args(self):
|
| |
user = tests.FakeAuthorization('ralph')
|
| |
with tests.auth_set(app, user):
|
| |
- data = {'widget_name': 'about'}
|
| |
+ data = {
|
| |
+ 'widget': 'memberships',
|
| |
+ 'position': 'right',
|
| |
+ }
|
| |
result = self.app.post('/ralph/add', data=data)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, "/ralph/edit")
|
| |
+ 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)
|
| |
- expected_str = '<h6 class="dropdown-header">Account Information</h6>'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
- expected_str = '<a href="#" class="dropdown-item">Full Name: fullname: ralph</a>'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
+ 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 = {'widget_name': 'about', 'text': 'text of widget'}
|
| |
- result = self.app.post('/ralph/add', data=data,
|
| |
+ data = {
|
| |
+ 'text': 'text of widget',
|
| |
+ 'position': 'right',
|
| |
+ }
|
| |
+ result = self.app.post('/ralph/add/about', data=data,
|
| |
follow_redirects=False)
|
| |
- self.assertEqual(result.status_code, 302)
|
| |
- self.assertEqual(urlparse(result.location).path, "/ralph/edit")
|
| |
- result = self.app.get('/ralph/edit')
|
| |
self.assertEqual(result.status_code, 200)
|
| |
- expected_str = '<h6 class="dropdown-header">Account Information</h6>'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
- expected_str = '<a href="#" class="dropdown-item">Full Name: fullname: ralph</a>'
|
| |
- self.assertIn(expected_str, result.get_data(as_text=True))
|
| |
+ 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')
|
| |
@@ -291,7 +310,7 @@
|
| |
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/')
|
| |
+ self.assertEqual(urlparse(result.location).path, '/ralph/edit')
|
| |
|
| |
def test_hub_visit_counter_logged_in(self):
|
| |
user = tests.FakeAuthorization('ralph')
|
| |
@@ -342,7 +361,7 @@
|
| |
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',
|
| |
+ self.assertIn('Adding widget "about" to hub ralph',
|
| |
result.get_data(as_text=True))
|
| |
|
| |
def test_hub_add_widget_invalid_side(self):
|
| |
@@ -376,7 +395,7 @@
|
| |
self.assertEqual(result.status_code, 404)
|
| |
|
| |
def mocked_requests_get(*args, **kwargs):
|
| |
- class MockResponse:
|
| |
+ class MockResponse: # flake8: noqa
|
| |
def __init__(self, json_data, status_code):
|
| |
self.json_data = json_data
|
| |
self.status_code = status_code
|
| |
@@ -491,9 +510,3 @@
|
| |
result = self.app.get(url)
|
| |
self.assertEqual(result.status_code, 403)
|
| |
self.assertEqual(result.get_data(as_text=True), 'User does not exist')
|
| |
-
|
| |
-
|
| |
-
|
| |
-
|
| |
- if __name__ == '__main__':
|
| |
- unittest.main()
|
| |
This way, widgets can have a more complex configuration panel.