Skip to content

Commit ab6d427

Browse files
committed
Bug Fix: Admin Base URI update
1 parent 3bffbea commit ab6d427

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

stackinawsgi/admin/admin.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ def __init__(self, session_manager, base_uri):
2727
"""
2828
super(StackInAWsgiAdmin, self).__init__('admin')
2929
self.manager = session_manager
30-
if base_uri.startswith('/'):
31-
self.base_uri = base_uri[1:]
32-
else:
33-
self.base_uri = base_uri
34-
35-
if self.base_uri.endswith('/'):
36-
self.base_uri = self.base_uri[:-1]
30+
self.base_uri = base_uri
3731

3832
self.register(
3933
StackInABoxService.DELETE, '/', StackInAWsgiAdmin.remove_session
@@ -48,6 +42,32 @@ def __init__(self, session_manager, base_uri):
4842
StackInABoxService.GET, '/', StackInAWsgiAdmin.get_session_info
4943
)
5044

45+
@property
46+
def base_uri(self):
47+
"""
48+
Base URI of the WSGI App
49+
"""
50+
return self.__base_uri
51+
52+
@base_uri.setter
53+
def base_uri(self, value):
54+
"""
55+
Update the Base URI of the WSGI App
56+
"""
57+
if value.startswith('/'):
58+
value = value[1:]
59+
60+
if value.endswith('/'):
61+
value = value[:-1]
62+
63+
self.__base_uri = value
64+
logger.debug(
65+
'Received Base URI: {0}'.format(
66+
self.__base_uri
67+
)
68+
)
69+
70+
5171
def helper_get_session_id(self, headers):
5272
"""
5373
Helper to retrieve the session id or build a new one

stackinawsgi/test/test_admin_admin.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ def test_construction(self):
4646
self.assertEqual(id(self.manager), id(admin.manager))
4747
self.assertTrue(admin.base_uri.startswith(self.base_uri))
4848

49-
def test_construction_alternate_url(self):
49+
def test_property_base_uri_with_no_slash(self):
50+
"""
51+
test basic construction of the admin interface
52+
"""
53+
base_uri = 'hello'
54+
admin = StackInAWsgiAdmin(self.manager, base_uri)
55+
self.assertIsInstance(admin, StackInABoxService)
56+
self.assertEqual(id(self.manager), id(admin.manager))
57+
self.assertTrue(admin.base_uri.startswith(base_uri))
58+
59+
def test_property_base_uri_start_with_slash(self):
5060
"""
5161
test basic construction of the admin interface
5262
"""
@@ -56,6 +66,15 @@ def test_construction_alternate_url(self):
5666
self.assertEqual(id(self.manager), id(admin.manager))
5767
self.assertTrue(admin.base_uri.startswith(base_uri[1:]))
5868

69+
def test_property_base_uri_ends_with_slash(self):
70+
"""
71+
"""
72+
base_uri = 'hello/'
73+
admin = StackInAWsgiAdmin(self.manager, base_uri)
74+
self.assertIsInstance(admin, StackInABoxService)
75+
self.assertEqual(id(self.manager), id(admin.manager))
76+
self.assertTrue(admin.base_uri.startswith(base_uri[:-1]))
77+
5978
def test_helper_get_session_id(self):
6079
"""
6180
test extracting the session-id from the headers

stackinawsgi/wsgi/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def StackInABoxUriUpdate(self, uri):
112112
Update StackInABox to use a new URI value.
113113
"""
114114
self.stackinabox.base_url = uri
115+
self.admin_service.base_uri = uri
115116

116117
def CallStackInABox(self, request, response):
117118
"""

0 commit comments

Comments
 (0)