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.environment.models import Authentic
|
12 |
|
from hobo.wsgi import application
|
13 |
23 |
|
14 |
|
pytestmark = pytest.mark.django_db
|
15 |
24 |
|
16 |
25 |
@pytest.fixture
|
17 |
|
def admin_user():
|
|
26 |
def admin_user(db):
|
18 |
27 |
try:
|
19 |
28 |
user = User.objects.get(username='admin')
|
20 |
29 |
except User.DoesNotExist:
|
21 |
30 |
user = User.objects.create_superuser('admin', email=None, password='admin')
|
22 |
31 |
return user
|
23 |
32 |
|
|
33 |
|
24 |
34 |
def login(app, username='admin', password='admin'):
|
25 |
35 |
login_page = app.get('/login/')
|
26 |
36 |
login_form = login_page.forms[0]
|
... | ... | |
30 |
40 |
assert resp.status_int == 302
|
31 |
41 |
return app
|
32 |
42 |
|
33 |
|
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):
|
34 |
50 |
# connect while not being logged in
|
35 |
|
app = TestApp(application)
|
36 |
51 |
assert app.get('/', status=302).location.endswith('/login/?next=/')
|
37 |
52 |
|
38 |
|
def test_access(admin_user):
|
39 |
|
app = login(TestApp(application))
|
40 |
|
resp = app.get('/', status=200)
|
|
53 |
|
|
54 |
def test_access(logged_app):
|
|
55 |
resp = logged_app.get('/', status=200)
|
41 |
56 |
assert 'User Profile' not in resp.body
|
42 |
57 |
assert 'Services' in resp.body
|
43 |
58 |
assert 'Variables' in resp.body
|
44 |
59 |
|
45 |
60 |
Authentic(title='bar', slug='bar', base_url='http://bar.example.net').save()
|
46 |
|
resp = app.get('/', status=200)
|
|
61 |
resp = logged_app.get('/', status=200)
|
47 |
62 |
assert 'User Profile' in resp.body
|
48 |
63 |
|
49 |
|
def test_logout(admin_user):
|
50 |
|
app = login(TestApp(application))
|
|
64 |
|
|
65 |
def test_logout(logged_app):
|
|
66 |
app = logged_app
|
51 |
67 |
app.get('/logout/')
|
52 |
68 |
assert app.get('/', status=302).location.endswith('/login/?next=/')
|
53 |
69 |
|
54 |
70 |
|
55 |
71 |
@pytest.mark.parametrize('kind', ['boolean', 'string'])
|
56 |
|
def test_add_attribute(admin_user, kind):
|
57 |
|
app = login(TestApp(application))
|
|
72 |
def test_add_attribute(logged_app, admin_user, kind):
|
|
73 |
app = logged_app
|
58 |
74 |
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 0
|
59 |
75 |
page = app.get('/profile/add-attribute', status=200)
|
60 |
76 |
page.form['label'] = 'test'
|
... | ... | |
70 |
86 |
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 1
|
71 |
87 |
|
72 |
88 |
|
73 |
|
def test_attribute_kind_not_restricted_at_model_level():
|
|
89 |
def test_attribute_kind_not_restricted_at_model_level(db):
|
74 |
90 |
assert models.AttributeDefinition.objects.create(label='test', kind='somestring')
|
75 |
|
-
|