41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from django.contrib.auth.models import User
|
|
import pytest
|
|
from webtest import TestApp
|
|
|
|
from chrono.wsgi import application
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
@pytest.fixture
|
|
def admin_user():
|
|
try:
|
|
user = User.objects.get(username='admin')
|
|
except User.DoesNotExist:
|
|
user = User.objects.create_superuser('admin', email=None, password='admin')
|
|
return user
|
|
|
|
def login(app, username='admin', password='admin'):
|
|
login_page = app.get('/login/')
|
|
login_form = login_page.forms[0]
|
|
login_form['username'] = username
|
|
login_form['password'] = password
|
|
resp = login_form.submit()
|
|
assert resp.status_int == 302
|
|
return app
|
|
|
|
def test_unlogged_access():
|
|
# connect while not being logged in
|
|
app = TestApp(application)
|
|
assert app.get('/manage/', status=302).location == 'http://localhost:80/login/?next=/manage/'
|
|
|
|
def test_access(admin_user):
|
|
app = login(TestApp(application))
|
|
resp = app.get('/manage/', status=200)
|
|
assert '<h2>Agendas</h2>' in resp.body
|
|
assert "This site doesn't have any agenda yet." in resp.body
|
|
|
|
def test_logout(admin_user):
|
|
app = login(TestApp(application))
|
|
app.get('/logout/')
|
|
assert app.get('/manage/', status=302).location == 'http://localhost:80/login/?next=/manage/'
|