75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
import base64
|
|
import os
|
|
import StringIO
|
|
|
|
from django.conf import settings
|
|
from django.contrib.auth.models import User
|
|
import pytest
|
|
from webtest import TestApp
|
|
|
|
from hobo.profile import models
|
|
from hobo.environment.models import Authentic
|
|
from hobo.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('/', status=302).location.endswith('/login/?next=/')
|
|
|
|
def test_access(admin_user):
|
|
app = login(TestApp(application))
|
|
resp = app.get('/', status=200)
|
|
assert 'User Profile' not in resp.body
|
|
assert 'Services' in resp.body
|
|
assert 'Variables' in resp.body
|
|
|
|
Authentic(title='bar', slug='bar', base_url='http://bar.example.net').save()
|
|
resp = app.get('/', status=200)
|
|
assert 'User Profile' in resp.body
|
|
|
|
def test_logout(admin_user):
|
|
app = login(TestApp(application))
|
|
app.get('/logout/')
|
|
assert app.get('/', status=302).location.endswith('/login/?next=/')
|
|
|
|
|
|
@pytest.mark.parametrize('kind', ['boolean', 'string'])
|
|
def test_add_attribute(admin_user, kind):
|
|
app = login(TestApp(application))
|
|
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 0
|
|
page = app.get('/profile/add-attribute', status=200)
|
|
page.form['label'] = 'test'
|
|
page.form['name'] = 'test'
|
|
page.form['description'] = 'test'
|
|
page.form['required'] = True
|
|
page.form['asked_on_registration'] = False
|
|
page.form['user_editable'] = False
|
|
page.form['user_visible'] = False
|
|
page.form['disabled'] = False
|
|
page.form['kind'] = kind
|
|
page.form.submit()
|
|
assert models.AttributeDefinition.objects.filter(kind=kind).filter(name='test').count() == 1
|
|
|
|
|
|
def test_attribute_kind_not_restricted_at_model_level():
|
|
assert models.AttributeDefinition.objects.create(label='test', kind='somestring')
|