Skip to content

Commit 2fceca4

Browse files
committed
Add session_webapp_url to Slash plugin (fix #50)
1 parent a196771 commit 2fceca4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

backslash/contrib/slash_plugin.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,22 @@ def rest_url(self):
7979

8080
@property
8181
def webapp_url(self):
82+
return self._url_with_fragment('/')
83+
84+
@property
85+
def session_webapp_url(self):
86+
session = slash.context.session
87+
if session is None:
88+
return None
89+
return self._url_with_fragment('sessions/{}'.format(session.id))
90+
91+
def _url_with_fragment(self, fragment):
8292
returned = str(self._get_backslash_url())
8393
if not returned.endswith('/'):
8494
returned += '/'
85-
returned += '#/'
95+
if not fragment.startswith('/'):
96+
fragment = '/' + fragment
97+
returned += '#{}'.format(fragment)
8698
return returned
8799

88100
def _handle_exception(self, exc_info):

tests/test_slash_plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ def test_webapp_url(installed_plugin, server_url):
4040
expected += '#/'
4141
assert installed_plugin.webapp_url == expected
4242

43+
def test_session_webapp_url_no_session(installed_plugin):
44+
assert installed_plugin.session_webapp_url is None
45+
46+
def test_session_webapp_url_with_session(installed_plugin, server_url):
47+
with slash.Session() as s:
48+
url = installed_plugin.session_webapp_url
49+
assert url == '{}/#/sessions/{}'.format(server_url, s.id)
50+
51+
52+
4353

4454

4555
@pytest.fixture

0 commit comments

Comments
 (0)