add missing tests and templates
This commit is contained in:
parent
17e4461781
commit
a6959ccdab
|
@ -0,0 +1,10 @@
|
|||
{% extends "bijoe/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
<i>You have been logged out</i>
|
||||
</p>
|
||||
<p>
|
||||
<a href="{% url "homepage" %}">Continue to homepage</a>
|
||||
</p>
|
||||
{% endblock %}
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "bijoe/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" name="Login"/>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -0,0 +1,8 @@
|
|||
{% extends "bijoe/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
<i>You are not authorized to access this service, please ask your administrator for
|
||||
access.</i>
|
||||
</p>
|
||||
{% endblock %}
|
|
@ -0,0 +1,31 @@
|
|||
import pytest
|
||||
|
||||
import django_webtest
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(request):
|
||||
wtm = django_webtest.WebTestMixin()
|
||||
wtm._patch_settings()
|
||||
request.addfinalizer(wtm._unpatch_settings)
|
||||
return django_webtest.DjangoTestApp()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def john_doe(db):
|
||||
u = User(username='john.doe', first_name='John', last_name='Doe', email='john.doe@example.net')
|
||||
u.set_password('john.doe')
|
||||
u.save()
|
||||
return u
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin(db):
|
||||
u = User(username='super.user', first_name='Super', last_name='User',
|
||||
email='super.user@example.net')
|
||||
u.set_password('super.user')
|
||||
u.is_superuser = True
|
||||
u.is_staff = True
|
||||
u.save()
|
||||
return u
|
|
@ -0,0 +1,31 @@
|
|||
# bijoe - BI dashboard
|
||||
# Copyright (C) 2015 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from utils import login
|
||||
|
||||
|
||||
def test_simple_user_403(app, john_doe):
|
||||
login(app, john_doe)
|
||||
app.get('/', status=403)
|
||||
app.get('/manage/menu.json', status=403)
|
||||
|
||||
|
||||
def test_superuser(app, admin):
|
||||
login(app, admin)
|
||||
resp = app.get('/manage/menu.json', status=200)
|
||||
assert len(resp.json) == 1
|
||||
assert resp.json[0]['slug'] == 'statistics'
|
||||
app.get('/', status=200)
|
|
@ -0,0 +1,20 @@
|
|||
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
|
||||
|
Loading…
Reference in New Issue