passerelle/tests/test_manager.py

64 lines
2.1 KiB
Python

import re
from django.contrib.auth.models import User
from django.core.wsgi import get_wsgi_application
import pytest
from webtest import TestApp
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(get_wsgi_application())
assert app.get('/manage/', status=302).location == 'http://localhost:80/login/?next=/manage/'
def test_access(admin_user):
app = login(TestApp(get_wsgi_application()))
resp = app.get('/manage/', status=200)
assert 'Add Connector' in resp.body
def test_add_connector(admin_user):
app = login(TestApp(get_wsgi_application()))
resp = app.get('/manage/', status=200)
resp = resp.click('Add Connector')
assert 'Business Process Connectors' in resp.body
assert 'SMS Providers' in resp.body
resp = resp.click('OVH')
resp.forms[0]['title'] = 'Test Connector'
resp.forms[0]['description'] = 'Connector for a simple test'
resp.forms[0]['account'] = 'xxx'
resp.forms[0]['username'] = 'username'
resp.forms[0]['password'] = 'password'
resp = resp.forms[0].submit()
assert resp.status_int == 302
assert resp.location == 'http://localhost:80/ovh/test-connector/'
resp = resp.follow()
assert 'OVH - Test Connector' in resp.body
resp = app.get('/manage/', status=200)
assert 'Test Connector' in resp.body
def test_visit_connectors(admin_user):
app = login(TestApp(get_wsgi_application()))
resp = app.get('/manage/', status=200)
resp = resp.click('Add Connector')
for link in re.findall('href="(/manage.*add)"', resp.body):
resp = app.get(link, status=200)