1 |
|
import base64
|
2 |
|
import os
|
3 |
|
import StringIO
|
|
1 |
# hobo - portal to configure and deploy applications
|
|
2 |
# Copyright (C) 2015-2019 Entr'ouvert
|
|
3 |
#
|
|
4 |
# This program is free software: you can redistribute it and/or modify it
|
|
5 |
# under the terms of the GNU Affero General Public License as published
|
|
6 |
# by the Free Software Foundation, either version 3 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU Affero General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU Affero General Public License
|
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
|
4 |
17 |
|
5 |
|
from django.conf import settings
|
6 |
18 |
from django.contrib.auth.models import User
|
7 |
19 |
import pytest
|
8 |
|
from webtest import TestApp
|
9 |
20 |
|
10 |
21 |
from hobo.profile import models
|
11 |
22 |
from hobo.wsgi import application
|
12 |
23 |
|
13 |
|
pytestmark = pytest.mark.django_db
|
14 |
24 |
|
15 |
25 |
@pytest.fixture
|
16 |
|
def admin_user():
|
|
26 |
def admin_user(db):
|
17 |
27 |
try:
|
18 |
28 |
user = User.objects.get(username='admin')
|
19 |
29 |
except User.DoesNotExist:
|
20 |
30 |
user = User.objects.create_superuser('admin', email=None, password='admin')
|
21 |
31 |
return user
|
22 |
32 |
|
|
33 |
|
23 |
34 |
def login(app, username='admin', password='admin'):
|
24 |
35 |
login_page = app.get('/login/')
|
25 |
36 |
login_form = login_page.forms[0]
|
... | ... | |
29 |
40 |
assert resp.status_int == 302
|
30 |
41 |
return app
|
31 |
42 |
|
32 |
|
def test_unlogged_access():
|
|
43 |
|
|
44 |
@pytest.fixture
|
|
45 |
def logged_app(app, admin_user):
|
|
46 |
return login(app)
|
|
47 |
|
|
48 |
|
|
49 |
def test_unlogged_access(app):
|
33 |
50 |
# connect while not being logged in
|
34 |
|
app = TestApp(application)
|
35 |
51 |
assert app.get('/', status=302).location.endswith('/login/?next=/')
|
36 |
52 |
|
37 |
|
def test_access(admin_user):
|
38 |
|
app = login(TestApp(application))
|
39 |
|
resp = app.get('/', status=200)
|
|
53 |
|
|
54 |
def test_access(logged_app):
|
|
55 |
resp = logged_app.get('/', status=200)
|
40 |
56 |
assert 'User Profile' in resp.body
|
41 |
57 |
assert 'Services' in resp.body
|
42 |
58 |
assert 'Variables' in resp.body
|
43 |
59 |
|
44 |
|
def test_logout(admin_user):
|
45 |
|
app = login(TestApp(application))
|
|
60 |
|
|
61 |
def test_logout(logged_app):
|
|
62 |
app = logged_app
|
46 |
63 |
app.get('/logout/')
|
47 |
64 |
assert app.get('/', status=302).location.endswith('/login/?next=/')
|
48 |
65 |
|
49 |
66 |
|
50 |
67 |
@pytest.mark.parametrize('kind', ['boolean', 'string'])
|
51 |
|
def test_add_attribute(admin_user, kind):
|
52 |
|
app = login(TestApp(application))
|
|
68 |
def test_add_attribute(logged_app, admin_user, kind):
|
|
69 |
app = logged_app
|
53 |
70 |
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 0
|
54 |
71 |
page = app.get('/profile/add-attribute', status=200)
|
55 |
72 |
page.form['label'] = 'test'
|
... | ... | |
65 |
82 |
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 1
|
66 |
83 |
|
67 |
84 |
|
68 |
|
def test_attribute_kind_not_restricted_at_model_level():
|
|
85 |
def test_attribute_kind_not_restricted_at_model_level(db):
|
69 |
86 |
assert models.AttributeDefinition.objects.create(label='test', kind='somestring')
|
70 |
|
-
|