32 lines
942 B
Python
32 lines
942 B
Python
from django.conf import settings
|
|
|
|
|
|
def login(app, user, path=None, password=None):
|
|
if path:
|
|
login_page = app.get(path)
|
|
else:
|
|
login_page = app.get(settings.LOGIN_URL)
|
|
login_page = login_page.maybe_follow()
|
|
form = login_page.form
|
|
form.set('username', user.username if hasattr(user, 'username') else user)
|
|
# password is supposed to be the same as username
|
|
form.set('password', password or user.username)
|
|
response = form.submit(name='login-password-submit').follow(expect_errors=True)
|
|
if path:
|
|
assert response.request.path == path
|
|
assert '_auth_user_id' in app.session
|
|
assert str(app.session['_auth_user_id']) == str(user.id)
|
|
return response
|
|
|
|
|
|
def get_table(response):
|
|
table = []
|
|
|
|
for tr in response.pyquery('table tr'):
|
|
row = []
|
|
table.append(row)
|
|
for td in tr.findall('td'):
|
|
row.append((td.text or '').strip())
|
|
return table
|
|
|