From f8497788b5ae571c0a18776817f511e0d2f54231 Mon Sep 17 00:00:00 2001 From: Eric Barbour Date: Jun 20 2016 14:47:52 +0000 Subject: Test login redirection for hub actions --- diff --git a/hubs/tests/test_api/test_hub.py b/hubs/tests/test_api/test_hub.py index ee749d9..785aef3 100644 --- a/hubs/tests/test_api/test_hub.py +++ b/hubs/tests/test_api/test_hub.py @@ -1,5 +1,6 @@ import flask import unittest +from urlparse import urlparse import hubs.tests import hubs.models @@ -12,12 +13,12 @@ def usernames(collection): return [u.username for u in collection] class TestHubSubscribe(hubs.tests.APPTest): user = hubs.tests.FakeAuthorization('decause') - @unittest.skip('Need to handle redirects') def test_subscribe_redirects_when_logged_out(self): hub = hubs.models.Hub.by_name(self.session, 'infra') - resp = self.app.post('/api/hub/{}/subscribe'.format(hub.idx)) + resp = self.app.post('/api/hub/{}/subscribe'.format(hub.name), + follow_redirects=False) self.assertEqual(resp.status_code, 302) - self.assertEqual(resp.location, flask.url_for('fedora.login')) + self.assertEqual(urlparse(resp.location).path, '/login/fedora') def test_subscribe_when_logged_in(self): hub = hubs.models.Hub.by_name(self.session, 'infra') @@ -33,12 +34,12 @@ class TestHubSubscribe(hubs.tests.APPTest): class TestHubUnsubscribe(hubs.tests.APPTest): user = hubs.tests.FakeAuthorization('decause') - @unittest.skip('Need to handle redirects') def test_unsubscribe_redirects_when_logged_out(self): hub = hubs.models.Hub.by_name(self.session, 'infra') - resp = self.app.post('/api/hub/{}/unsubscribe'.format(hub.idx)) + resp = self.app.post('/api/hub/{}/unsubscribe'.format(hub.name), + follow_redirects=False) self.assertEqual(resp.status_code, 302) - self.assertEqual(resp.location, flask.url_for('fedora.login')) + self.assertEqual(urlparse(resp.location).path, '/login/fedora') def test_unsubscribe_when_logged_in(self): hub = hubs.models.Hub.by_name(self.session, 'infra') @@ -59,12 +60,12 @@ class TestHubUnsubscribe(hubs.tests.APPTest): class TestHubStar(hubs.tests.APPTest): user = hubs.tests.FakeAuthorization('decause') - @unittest.skip('Need to handle redirects') def test_star_redirects_when_logged_out(self): hub = hubs.models.Hub.by_name(self.session, 'infra') - resp = self.app.post('/api/hub/{}/star'.format(hub.idx)) + resp = self.app.post('/api/hub/{}/star'.format(hub.name), + follow_redirects=False) self.assertEqual(resp.status_code, 302) - self.assertEqual(resp.location, flask.url_for('fedora.login')) + self.assertEqual(urlparse(resp.location).path, '/login/fedora') def test_star_when_logged_in(self): hub = hubs.models.Hub.by_name(self.session, 'infra') @@ -80,12 +81,12 @@ class TestHubStar(hubs.tests.APPTest): class TestHubUnstar(hubs.tests.APPTest): user = hubs.tests.FakeAuthorization('decause') - @unittest.skip('Need to handle redirects') def test_unstar_redirects_when_logged_out(self): hub = hubs.models.Hub.by_name(self.session, 'infra') - resp = self.app.post('/api/hub/{}/unstar'.format(hub.idx)) + resp = self.app.post('/api/hub/{}/unstar'.format(hub.name), + follow_redirects=False) self.assertEqual(resp.status_code, 302) - self.assertEqual(resp.location, flask.url_for('fedora.login')) + self.assertEqual(urlparse(resp.location).path, '/login/fedora') def test_unstar_when_logged_in(self): hub = hubs.models.Hub.by_name(self.session, 'infra') @@ -107,12 +108,12 @@ class TestHubUnstar(hubs.tests.APPTest): class TestHubJoin(hubs.tests.APPTest): user = hubs.tests.FakeAuthorization('decause') - @unittest.skip('Need to handle redirects') def test_join_redirects_when_logged_out(self): hub = hubs.models.Hub.by_name(self.session, 'infra') - resp = self.app.post('/api/hub/{}/join'.format(hub.idx)) + resp = self.app.post('/api/hub/{}/join'.format(hub.name), + follow_redirects=False) self.assertEqual(resp.status_code, 302) - self.assertEqual(resp.location, flask.url_for('fedora.login')) + self.assertEqual(urlparse(resp.location).path, '/login/fedora') def test_join_when_logged_in(self): hub = hubs.models.Hub.by_name(self.session, 'infra') @@ -128,12 +129,12 @@ class TestHubJoin(hubs.tests.APPTest): class TestHubLeave(hubs.tests.APPTest): user = hubs.tests.FakeAuthorization('decause') - @unittest.skip('Need to handle redirects') def test_leave_redirects_when_logged_out(self): hub = hubs.models.Hub.by_name(self.session, 'infra') - resp = self.app.post('/api/hub/{}/leave'.format(hub.idx)) + resp = self.app.post('/api/hub/{}/leave'.format(hub.name), + follow_redirects=False) self.assertEqual(resp.status_code, 302) - self.assertEqual(resp.location, flask.url_for('fedora.login')) + self.assertEqual(urlparse(resp.location).path, '/login/fedora') def test_star_when_logged_in(self): hub = hubs.models.Hub.by_name(self.session, 'infra')