tests: add tests for apps.publik services.js

This commit is contained in:
Frédéric Péters 2016-07-13 08:19:10 +02:00
parent 58e2b80e1c
commit f1827dcbf9
2 changed files with 60 additions and 3 deletions

View File

@ -3,17 +3,22 @@ LANGUAGE_CODE = 'en-us'
KNOWN_SERVICES = {
'wcs': {
'default': {'title': 'test', 'url': 'http://127.0.0.1:8999/',
'secret': 'combo', 'orig': 'combo'},
'secret': 'combo', 'orig': 'combo',
'backoffice-menu-url': 'http://127.0.0.1:8999/backoffice/',},
'other': {'title': 'test2', 'url': 'http://127.0.0.2:8999/',
'secret': 'combo', 'orig': 'combo'},
'secret': 'combo', 'orig': 'combo',
'backoffice-menu-url': 'http://127.0.0.2:8999/backoffice/',},
},
'passerelle': {
'default': {'title': 'test', 'url': 'http://example.org',
'secret': 'combo', 'orig': 'combo'}
'secret': 'combo', 'orig': 'combo',
'backoffice-menu-url': 'http://example.org/manage/',}
}
}
LINGO_API_SIGN_KEY = '12345'
TEMPLATE_VARS = {}
import tempfile
MEDIA_ROOT = tempfile.mkdtemp('combo-test')

52
tests/test_publik.py Normal file
View File

@ -0,0 +1,52 @@
import pytest
from webtest import TestApp
from django.conf import settings
pytestmark = pytest.mark.django_db
class KnownServices(object):
def __init__(self, known_services):
self.known_services = known_services
self.orig_value = settings.KNOWN_SERVICES
def __enter__(self):
settings.KNOWN_SERVICES = self.known_services
def __exit__(self, *args, **kwargs):
settings.KNOWN_SERVICES = self.orig_value
def test_services_js_no_services(app):
with KnownServices({}):
resp = app.get('/__services.js', status=404)
def test_services_js_multiple_wcs(app):
resp = app.get('/__services.js', status=200)
assert resp.content_type == 'text/javascript'
assert 'var PUBLIK_ENVIRONMENT_LABEL = null' in resp.body
assert 'var PUBLIK_PORTAL_AGENT_URL = null' in resp.body
assert '"uniq": false' in resp.body
def test_services_js_portal_agent(app):
known_services = {
'combo': {
'portal-agent': {
'title': 'Portal Agent',
'url': 'http://example.net',
'backoffice-menu-url': 'http://example.net/manage/',
'is-portal-agent': True,
},
'portal-user': {
'title': 'Portal User',
'url': 'http://example.com',
'backoffice-menu-url': 'http://example.com/manage/',
},
}
}
with KnownServices(known_services):
resp = app.get('/__services.js', status=200)
assert resp.content_type == 'text/javascript'
assert 'var PUBLIK_PORTAL_AGENT_URL = "http://example.net";' in resp.body
assert 'var PUBLIK_PORTAL_AGENT_TITLE = "Portal Agent"' in resp.body