mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-12 12:33:02 +00:00
Add tests of page announcements
- Adds test_pages.py:test_page_contents, which currently tests just the page annoucement variables.
This commit is contained in:
@@ -517,3 +517,84 @@ def test_oauth_token_page(app):
|
|||||||
def test_proxy_error(app, error_status):
|
def test_proxy_error(app, error_status):
|
||||||
r = yield get_page('/error/%i' % error_status, app)
|
r = yield get_page('/error/%i' % error_status, app)
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.gen_test
|
||||||
|
def test_page_contents(app):
|
||||||
|
"""Tests the contents of various pages.
|
||||||
|
|
||||||
|
Currently includes tests for the template_vars variables:
|
||||||
|
announcement, announcement_login, announcement_home,
|
||||||
|
announcement_spawn, and announcement_logout.
|
||||||
|
|
||||||
|
Other simple template tests could be put here.
|
||||||
|
"""
|
||||||
|
# Basic announcements - same on all pages
|
||||||
|
ann01 = 'ANNOUNCE01'
|
||||||
|
ann02 = 'ANNOUNCE02'
|
||||||
|
with mock.patch.dict(app.users.settings,
|
||||||
|
{'template_vars': {'announcement': ann01},
|
||||||
|
'spawner_class': FormSpawner}):
|
||||||
|
r = yield get_page('login', app)
|
||||||
|
r.raise_for_status()
|
||||||
|
assert ann01 in r.text
|
||||||
|
cookies = yield app.login_user('jones')
|
||||||
|
r = yield get_page('spawn', app, cookies=cookies)
|
||||||
|
r.raise_for_status()
|
||||||
|
assert ann01 in r.text
|
||||||
|
r = yield get_page('home', app, cookies=cookies) # hub/home
|
||||||
|
r.raise_for_status()
|
||||||
|
assert ann01 in r.text
|
||||||
|
r = yield get_page('logout', app, cookies=cookies)
|
||||||
|
r.raise_for_status()
|
||||||
|
assert ann01 in r.text
|
||||||
|
|
||||||
|
# Different annoncements on one page
|
||||||
|
with mock.patch.dict(app.users.settings,
|
||||||
|
{'template_vars': {'announcement': ann01,
|
||||||
|
'announcement_spawn': ann02},
|
||||||
|
'spawner_class': FormSpawner}):
|
||||||
|
r = yield get_page('login', app)
|
||||||
|
r.raise_for_status()
|
||||||
|
assert ann01 in r.text
|
||||||
|
assert ann02 not in r.text
|
||||||
|
|
||||||
|
cookies = yield app.login_user('jones')
|
||||||
|
r = yield get_page('spawn', app, cookies=cookies)
|
||||||
|
r.raise_for_status()
|
||||||
|
assert ann01 not in r.text
|
||||||
|
assert ann02 in r.text
|
||||||
|
|
||||||
|
# Different annoucements on all pages. Must give formspawner to
|
||||||
|
# ensure we get a message on the spawn page
|
||||||
|
with mock.patch.dict(app.users.settings,
|
||||||
|
{'template_vars': {'announcement': ann01,
|
||||||
|
'announcement_spawn': 'ANN_spawn',
|
||||||
|
'announcement_home': 'ANN_home',
|
||||||
|
'announcement_login': 'ANN_login'},
|
||||||
|
'spawner_class': FormSpawner
|
||||||
|
}):
|
||||||
|
r = yield get_page('login', app)
|
||||||
|
assert 'ANN_login' in r.text
|
||||||
|
assert ann01 not in r.text
|
||||||
|
|
||||||
|
cookies = yield app.login_user('jones')
|
||||||
|
r = yield get_page('spawn', app, cookies=cookies)
|
||||||
|
assert 'ANN_spawn' in r.text
|
||||||
|
assert ann01 not in r.text
|
||||||
|
|
||||||
|
r = yield get_page('home', app, cookies=cookies) # hub/home
|
||||||
|
assert 'ANN_home' in r.text
|
||||||
|
assert ann01 not in r.text
|
||||||
|
# ... and must have auto_login=True in order to not be immediately
|
||||||
|
# redirected from the logout page:
|
||||||
|
with mock.patch.dict(app.users.settings,
|
||||||
|
{'template_vars': {'announcement': ann01,
|
||||||
|
'announcement_logout': 'ANN_logout'},
|
||||||
|
'authenticator': Authenticator(auto_login=True),
|
||||||
|
'spawner_class': FormSpawner
|
||||||
|
}):
|
||||||
|
r = yield get_page('logout', app, cookies=cookies)
|
||||||
|
assert 'ANN_logout' in r.text
|
||||||
|
assert ann01 not in r.text
|
||||||
|
Reference in New Issue
Block a user