33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from __future__ import unicode_literals
|
|
import pytest
|
|
|
|
from hobo.multitenant.middleware import TenantMiddleware
|
|
|
|
|
|
def test_hostname2schema():
|
|
assert TenantMiddleware.hostname2schema('x' * 63) == ('x' * 63)
|
|
shortened = TenantMiddleware.hostname2schema('x' * 64)
|
|
# no more than 63 characters
|
|
assert len(shortened) == 63
|
|
# it's different than just the 63 first characters
|
|
assert shortened != ('x' * 63)
|
|
# but it matches the prefix
|
|
assert shortened[:20] == ('x' * 20)
|
|
# and it matches the suffix
|
|
assert shortened[-20:] == ('x' * 20)
|
|
|
|
|
|
def test_internalipmiddleware(app, tenants, settings):
|
|
settings.INTERNAL_IPS = []
|
|
settings.ALLOWED_HOSTS = ['*']
|
|
settings.DEBUG_PROPAGATE_EXCEPTIONS = False
|
|
app.get('/?raise', status=404)
|
|
response = app.get('/?raise', status=500, extra_environ={'HTTP_HOST': tenants[0].domain_url})
|
|
assert response.text == '<h1>Server Error (500)</h1>'
|
|
|
|
settings.INTERNAL_IPS = ['127.0.0.1']
|
|
|
|
response = app.get('/?raise', status=500, extra_environ={'HTTP_HOST': tenants[0].domain_url})
|
|
assert 'You\'re seeing this error because you have' in response.text
|
|
|