start unit tests

This commit is contained in:
Emmanuel Cazenave 2019-10-16 15:07:39 +02:00
parent ffe75c6505
commit 1e7b6f0030
4 changed files with 84 additions and 0 deletions

10
Jenkinsfile vendored
View File

@ -3,6 +3,16 @@
pipeline {
agent any
stages {
stage('Unit Tests') {
steps {
sh 'tox -rv'
}
post {
always {
junit '*_results.xml'
}
}
}
stage('Packaging') {
steps {
script {

9
tests/settings.py Normal file
View File

@ -0,0 +1,9 @@
INSTALLED_APPS += ('passerelle_reunion_pastell',)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'passerelle',
}
}

40
tests/test_connector.py Normal file
View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
import json
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
import django_webtest
import httmock
import pytest
from passerelle_reunion_pastell.models import PastellReunionConnector
from passerelle.base.models import ApiUser, AccessRight
@pytest.fixture
def app(request):
wtm = django_webtest.WebTestMixin()
wtm._patch_settings()
request.addfinalizer(wtm._unpatch_settings)
cache.clear()
return django_webtest.DjangoTestApp()
@pytest.fixture
def connector(db):
# création du connecteur et ouverture de la permission "can_access" sans authentification.
connector = PastellReunionConnector.objects.create(slug='test', url='https://some-url')
api = ApiUser.objects.create(username='all', keytype='', key='')
obj_type = ContentType.objects.get_for_model(connector)
AccessRight.objects.create(
codename='can_access', apiuser=api,
resource_type=obj_type, resource_pk=connector.pk)
def test_create_document(app, connector):
import requests_mock
with requests_mock.Mocker() as m:
m.post('https://some-url', status_code=200)
resp = app.post('/passerelle-reunion-pastell/test/createDocument')
assert resp.json['data']['response'] == 200

25
tox.ini Normal file
View File

@ -0,0 +1,25 @@
[tox]
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/passerelle-reunion-pastell/{env:BRANCH_NAME:}
envlist = django111-pg
[testenv]
usedevelop = True
basepython = python2
setenv =
DJANGO_SETTINGS_MODULE=passerelle.settings
PASSERELLE_SETTINGS_FILE=tests/settings.py
WCSCTL=wcs/wcsctl.py
deps =
django111: django>=1.11,<1.12
git+http://git.entrouvert.org/passerelle.git
django-webtest
psycopg2-binary
pytest-django
pytest
WebTest
mock
httmock
requests-mock
ipdb
commands =
django111: py.test {posargs: --junitxml=test_{envname}_results.xml tests/}