53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
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.text
|
|
assert 'var PUBLIK_PORTAL_AGENT_URL = null' in resp.text
|
|
assert '"uniq": false' in resp.text
|
|
|
|
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.text
|
|
assert 'var PUBLIK_PORTAL_AGENT_TITLE = "Portal Agent"' in resp.text
|