tests: get app as a fixture (#40099)
This commit is contained in:
parent
e2f826e19b
commit
54ff275487
|
@ -5,13 +5,11 @@ import mock
|
||||||
import pytest
|
import pytest
|
||||||
import re
|
import re
|
||||||
from requests import Response
|
from requests import Response
|
||||||
from webtest import TestApp
|
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
from hobo.environment.models import Wcs, Combo, Fargo
|
from hobo.environment.models import Wcs, Combo, Fargo
|
||||||
from hobo.wsgi import application
|
|
||||||
|
|
||||||
from test_manager import login
|
from test_manager import login
|
||||||
|
|
||||||
|
@ -87,25 +85,24 @@ def requests_post_mocked_replies(contents):
|
||||||
responses.append(response)
|
responses.append(response)
|
||||||
return responses
|
return responses
|
||||||
|
|
||||||
def test_unlogged_access():
|
def test_unlogged_access(app):
|
||||||
# connect while not being logged in
|
# connect while not being logged in
|
||||||
app = TestApp(application)
|
|
||||||
resp = app.get('/visits-tracking/', status=302)
|
resp = app.get('/visits-tracking/', status=302)
|
||||||
assert resp.location.endswith('/login/?next=/visits-tracking/')
|
assert resp.location.endswith('/login/?next=/visits-tracking/')
|
||||||
|
|
||||||
def test_access(admin_user):
|
def test_access(app, admin_user):
|
||||||
app = login(TestApp(application))
|
login(app)
|
||||||
assert app.get('/visits-tracking/', status=200)
|
assert app.get('/visits-tracking/', status=200)
|
||||||
|
|
||||||
def test_disable(admin_user):
|
def test_disable(app, admin_user):
|
||||||
app = login(TestApp(application))
|
login(app)
|
||||||
resp1 = app.get('/visits-tracking/disable', status=200)
|
resp1 = app.get('/visits-tracking/disable', status=200)
|
||||||
resp2 = resp1.form.submit()
|
resp2 = resp1.form.submit()
|
||||||
assert resp2.location.endswith('/visits-tracking/')
|
assert resp2.location.endswith('/visits-tracking/')
|
||||||
|
|
||||||
def test_enable_manual(admin_user):
|
def test_enable_manual(app, admin_user):
|
||||||
"""scenario where user manually paste a javascript code"""
|
"""scenario where user manually paste a javascript code"""
|
||||||
app = login(TestApp(application))
|
login(app)
|
||||||
|
|
||||||
# get matomo's validation page
|
# get matomo's validation page
|
||||||
resp = app.get('/visits-tracking/enable-manual', status=200)
|
resp = app.get('/visits-tracking/enable-manual', status=200)
|
||||||
|
@ -141,27 +138,28 @@ def test_enable_manual(admin_user):
|
||||||
'You should remove the surrounding <script> markup.</li></ul>') in resp.text
|
'You should remove the surrounding <script> markup.</li></ul>') in resp.text
|
||||||
|
|
||||||
|
|
||||||
def test_available_options(admin_user):
|
def test_available_options(app, admin_user):
|
||||||
"""check available buttons (manual/automatic configurations)"""
|
"""check available buttons (manual/automatic configurations)"""
|
||||||
|
login(app)
|
||||||
|
|
||||||
with override_settings(MATOMO_SERVER=CONFIG):
|
with override_settings(MATOMO_SERVER=CONFIG):
|
||||||
app = login(TestApp(application))
|
|
||||||
resp = app.get('/visits-tracking/', status=200)
|
resp = app.get('/visits-tracking/', status=200)
|
||||||
assert str(resp).find('href="/visits-tracking/enable-manual"') != -1
|
assert str(resp).find('href="/visits-tracking/enable-manual"') != -1
|
||||||
assert str(resp).find('href="/visits-tracking/enable-auto"') != -1
|
assert str(resp).find('href="/visits-tracking/enable-auto"') != -1
|
||||||
|
|
||||||
# without configuration: no automatic configuration available
|
# without configuration: no automatic configuration available
|
||||||
app = login(TestApp(application))
|
|
||||||
resp = app.get('/visits-tracking/', status=200)
|
resp = app.get('/visits-tracking/', status=200)
|
||||||
assert str(resp).find('href="/visits-tracking/enable-manual"') != -1
|
assert str(resp).find('href="/visits-tracking/enable-manual"') != -1
|
||||||
assert str(resp).find('href="/visits-tracking/enable-auto"') == -1
|
assert str(resp).find('href="/visits-tracking/enable-auto"') == -1
|
||||||
|
|
||||||
@mock.patch('requests.post')
|
@mock.patch('requests.post')
|
||||||
def test_enable_auto(mocked_post, admin_user):
|
def test_enable_auto(mocked_post, app, admin_user):
|
||||||
"""succesfull automatic scenario"""
|
"""succesfull automatic scenario"""
|
||||||
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
||||||
template_name='portal-user')
|
template_name='portal-user')
|
||||||
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
||||||
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
||||||
|
login(app)
|
||||||
|
|
||||||
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS,
|
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS,
|
||||||
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
||||||
|
@ -169,7 +167,6 @@ def test_enable_auto(mocked_post, admin_user):
|
||||||
|
|
||||||
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
||||||
with override_settings(MATOMO_SERVER=CONFIG):
|
with override_settings(MATOMO_SERVER=CONFIG):
|
||||||
app = login(TestApp(application))
|
|
||||||
resp1 = app.get('/visits-tracking/enable-auto', status=200)
|
resp1 = app.get('/visits-tracking/enable-auto', status=200)
|
||||||
resp2 = resp1.form.submit()
|
resp2 = resp1.form.submit()
|
||||||
|
|
||||||
|
@ -180,12 +177,13 @@ def test_enable_auto(mocked_post, admin_user):
|
||||||
assert resp3.text.find('Excellent respect of user rights') != -1
|
assert resp3.text.find('Excellent respect of user rights') != -1
|
||||||
|
|
||||||
@mock.patch('requests.post')
|
@mock.patch('requests.post')
|
||||||
def test_enable_auto_warning(mocked_post, admin_user):
|
def test_enable_auto_warning(mocked_post, app, admin_user):
|
||||||
"""succesfull automatic scenario having final ping failure"""
|
"""succesfull automatic scenario having final ping failure"""
|
||||||
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
||||||
template_name='portal-user')
|
template_name='portal-user')
|
||||||
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
||||||
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
||||||
|
login(app)
|
||||||
|
|
||||||
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS,
|
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS,
|
||||||
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
||||||
|
@ -193,7 +191,6 @@ def test_enable_auto_warning(mocked_post, admin_user):
|
||||||
|
|
||||||
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
||||||
with override_settings(MATOMO_SERVER=CONFIG):
|
with override_settings(MATOMO_SERVER=CONFIG):
|
||||||
app = login(TestApp(application))
|
|
||||||
resp1 = app.get('/visits-tracking/enable-auto', status=200)
|
resp1 = app.get('/visits-tracking/enable-auto', status=200)
|
||||||
resp2 = resp1.form.submit()
|
resp2 = resp1.form.submit()
|
||||||
|
|
||||||
|
@ -207,12 +204,13 @@ def test_enable_auto_warning(mocked_post, admin_user):
|
||||||
assert resp3.text.find('Excellent respect of user rights') != -1
|
assert resp3.text.find('Excellent respect of user rights') != -1
|
||||||
|
|
||||||
@mock.patch('requests.post')
|
@mock.patch('requests.post')
|
||||||
def test_enable_auto_error(mocked_post, admin_user):
|
def test_enable_auto_error(mocked_post, app, admin_user):
|
||||||
"""error on automatic scenario"""
|
"""error on automatic scenario"""
|
||||||
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
||||||
template_name='portal-user')
|
template_name='portal-user')
|
||||||
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
||||||
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
||||||
|
login(app)
|
||||||
|
|
||||||
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS,
|
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS,
|
||||||
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
DEL_UNKNOWN_USER, MATOMO_SUCCESS,
|
||||||
|
@ -220,7 +218,6 @@ def test_enable_auto_error(mocked_post, admin_user):
|
||||||
|
|
||||||
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
mocked_post.side_effect = requests_post_mocked_replies(contents)
|
||||||
with override_settings(MATOMO_SERVER=CONFIG):
|
with override_settings(MATOMO_SERVER=CONFIG):
|
||||||
app = login(TestApp(application))
|
|
||||||
resp1 = app.get('/visits-tracking/enable-auto', status=200)
|
resp1 = app.get('/visits-tracking/enable-auto', status=200)
|
||||||
resp2 = resp1.form.submit()
|
resp2 = resp1.form.submit()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
import json
|
import json
|
||||||
from webtest import TestApp
|
|
||||||
|
|
||||||
import hobo.scrutiny.wsgi.middleware
|
import hobo.scrutiny.wsgi.middleware
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue