add tests (#26768)
This commit is contained in:
parent
9781d9e401
commit
07e68ef209
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Get venv site-packages path
|
||||
DSTDIR=`python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
|
||||
|
||||
# Get not venv site-packages path
|
||||
# Remove first path (assuming that is the venv path)
|
||||
NONPATH=`echo $PATH | sed 's/^[^:]*://'`
|
||||
SRCDIR=`PATH=$NONPATH python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
|
||||
|
||||
# Clean up
|
||||
rm -f $DSTDIR/lasso.*
|
||||
rm -f $DSTDIR/_lasso.*
|
||||
|
||||
# Link
|
||||
ln -sv $SRCDIR/lasso.py $DSTDIR
|
||||
ln -sv $SRCDIR/_lasso.* $DSTDIR
|
||||
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import pytest
|
||||
import django_webtest
|
||||
from collections import namedtuple
|
||||
|
||||
from authentic2.a2_rbac import utils as a2_rbac_utils
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(request, db):
|
||||
wtm = django_webtest.WebTestMixin()
|
||||
wtm._patch_settings()
|
||||
request.addfinalizer(wtm._unpatch_settings)
|
||||
return django_webtest.DjangoTestApp(extra_environ={'HTTP_HOST': 'localhost'})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def glc(app, db):
|
||||
from authentic2_idp_oidc.models import OIDCClient
|
||||
|
||||
oidc_client = OIDCClient.objects.create(
|
||||
name='Client 1',
|
||||
slug='client1',
|
||||
ou=a2_rbac_utils.get_default_ou(),
|
||||
client_id='client1',
|
||||
client_secret='client1',
|
||||
# IMPORTANT !
|
||||
has_api_access=True,
|
||||
identifier_policy=OIDCClient.POLICY_PAIRWISE_REVERSIBLE,
|
||||
)
|
||||
GLC = namedtuple('GLC', ['oidc_client', 'app'])
|
||||
return GLC(oidc_client=oidc_client, app=app)
|
||||
|
||||
|
||||
class AllHook(object):
|
||||
def __init__(self):
|
||||
self.calls = {}
|
||||
from authentic2 import hooks
|
||||
hooks.get_hooks.cache.clear()
|
||||
|
||||
def __call__(self, hook_name, *args, **kwargs):
|
||||
calls = self.calls.setdefault(hook_name, [])
|
||||
calls.append({'args': args, 'kwargs': kwargs})
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self.calls.get(name, [])
|
||||
|
||||
def clear(self):
|
||||
self.calls = {}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hooks(settings):
|
||||
if hasattr(settings, 'A2_HOOKS'):
|
||||
hooks = settings.A2_HOOKS
|
||||
else:
|
||||
hooks = settings.A2_HOOKS = {}
|
||||
hook = hooks['__all__'] = AllHook()
|
||||
yield hook
|
||||
hook.clear()
|
||||
del settings.A2_HOOKS['__all__']
|
|
@ -0,0 +1,11 @@
|
|||
import os
|
||||
|
||||
LANGUAGE_CODE = 'en'
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'),
|
||||
'TEST': {
|
||||
'NAME': 'a2-test',
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
JOHN = u'Jôhn'
|
||||
DOE = u'Dôe'
|
||||
EMAIL = 'john.doe@example.com'
|
||||
|
||||
|
||||
def test_no_email(glc):
|
||||
app = glc.app
|
||||
oidc_client = glc.oidc_client
|
||||
|
||||
app.authorization = ('Basic', (oidc_client.client_id, oidc_client.client_secret))
|
||||
|
||||
response = app.post_json('/api/users/', params={}, status=400)
|
||||
assert set(response.json['errors']) == set(['first_name', 'last_name', 'email'])
|
||||
assert response.json['result'] == 0
|
||||
|
||||
response = app.post_json('/api/users/', params={
|
||||
'first_name': JOHN,
|
||||
'last_name': DOE,
|
||||
'email': EMAIL,
|
||||
})
|
||||
assert response.json['sub']
|
||||
assert response.json['first_name'] == JOHN
|
||||
assert response.json['last_name'] == DOE
|
||||
assert response.json['email'] == EMAIL
|
|
@ -0,0 +1,47 @@
|
|||
# Tox (http://tox.testrun.org/) is a tool for running tests
|
||||
# in multiple virtualenvs. This configuration file will run the
|
||||
# test suite on all supported python versions. To use it, "pip install tox"
|
||||
# and then run "tox" from this directory.
|
||||
|
||||
[tox]
|
||||
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic2-cut/
|
||||
envlist = {coverage,nocoverage}-{dj18,dj111}-{pg,sqlite}
|
||||
|
||||
[testenv]
|
||||
# django.contrib.auth is not tested it does not work with our templates
|
||||
setenv =
|
||||
AUTHENTIC2_SETTINGS_FILE=tests/settings.py
|
||||
DJANGO_SETTINGS_MODULE=authentic2.settings
|
||||
sqlite: DB_ENGINE=django.db.backends.sqlite3
|
||||
pg: DB_ENGINE=django.db.backends.postgresql_psycopg2
|
||||
coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov=src/ --cov-config .coveragerc
|
||||
fast: FAST=--nomigrations
|
||||
usedevelop =
|
||||
coverage: True
|
||||
nocoverage: False
|
||||
deps =
|
||||
dj18: django>=1.8,<1.9
|
||||
dj18: django-tables2<1.1
|
||||
dj111: django>=1.11,<1.12
|
||||
dj111: django-tables2>=1.1,django-tables<2.0
|
||||
pg: psycopg2
|
||||
coverage
|
||||
pytest-cov
|
||||
pytest-django
|
||||
mock
|
||||
pytest
|
||||
lxml
|
||||
cssselect
|
||||
pylint
|
||||
pylint-django
|
||||
django-webtest
|
||||
WebTest
|
||||
pyquery
|
||||
httmock
|
||||
pytz
|
||||
requests<=2.11.1
|
||||
../authentic2
|
||||
../authentic2-auth-fc
|
||||
commands =
|
||||
./getlasso.sh
|
||||
py.test {env:FAST:} {env:COVERAGE:} {posargs:tests/}
|
Loading…
Reference in New Issue