1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 16:36:15 +00:00

add "sudo mode": confirm password before doing sysadmin work

This commit is contained in:
Shuai Lin
2015-05-04 13:57:10 +08:00
parent 801abe9026
commit c449e3842c
11 changed files with 275 additions and 46 deletions

53
tests/ui/fixtures.py Normal file
View File

@@ -0,0 +1,53 @@
from contextlib import contextmanager
from pytest import yield_fixture # pylint: disable=E1101
from tests.ui.driver import Browser
from tests.common.common import (
BASE_URL, USERNAME, PASSWORD, ADMIN_USERNAME, ADMIN_PASSWORD
)
@yield_fixture(scope='session')
def browser():
"""Get an instance of a browser that already logged in.
Note this browser instance are shared among all test cases.
"""
with _create_browser(admin=False) as browser:
yield browser
@yield_fixture(scope='session')
def admin_browser():
"""Get an instance of a browser that already logged in with admin credentials.
This browser instance are shared among all test cases.
"""
with _create_browser(admin=True) as browser:
yield browser
@yield_fixture(scope='function')
def admin_browser_once():
"""Get an instance of a browser that already logged in with admin credentials.
This browser instance are created/destroyed for each test case.
"""
with _create_browser(admin=True) as browser:
yield browser
@contextmanager
def _create_browser(admin=False):
username, password = (ADMIN_USERNAME, ADMIN_PASSWORD) \
if admin else (USERNAME, PASSWORD)
b = Browser(BASE_URL)
b.gohome()
assert b.path == '/accounts/login/'
b.fill_form({
'username': username,
'password': password
})
b.submit_by_input_name('username')
assert b.path != '/accounts/login/'
try:
yield b
finally:
b.quit()