|
1 |
import json
|
|
2 |
import os
|
|
3 |
import pytest
|
|
4 |
|
|
5 |
from django.conf import UserSettingsHolder
|
|
6 |
|
|
7 |
from hobo.deploy.utils import get_hobo_json
|
|
8 |
from hobo.environment.models import Authentic
|
|
9 |
from hobo.multitenant.settings_loaders import Authentic as AuthenticLoader
|
|
10 |
|
|
11 |
pytestmark = pytest.mark.django_db
|
|
12 |
|
|
13 |
|
|
14 |
def test_authentic_update_settings_from_path(tmpdir):
|
|
15 |
a = Authentic(title='bar', slug='bar', base_url='http://bar.example.net')
|
|
16 |
a.save()
|
|
17 |
env = get_hobo_json()
|
|
18 |
fields = env['profile']['fields']
|
|
19 |
assert [x['name'] for x in fields if x['disabled']] == [u'country', u'birthdate']
|
|
20 |
profile_fields = [x['name'] for x in fields if not x['disabled']]
|
|
21 |
|
|
22 |
# integer field are not exported to hobo.json
|
|
23 |
assert [x.get('order', 'undef') for x in env['profile']['fields']] == ['undef',] * 11
|
|
24 |
|
|
25 |
# serialize hobo.json
|
|
26 |
path = os.path.join(str(tmpdir), 'hobo.json')
|
|
27 |
json.dump(env, open(path, 'w'))
|
|
28 |
|
|
29 |
# call settings loaders
|
|
30 |
tenant_settings = UserSettingsHolder({})
|
|
31 |
assert not getattr(tenant_settings, 'A2_PROFILE_FIELDS', False)
|
|
32 |
assert not getattr(tenant_settings, 'A2_REQUIRED_FIELDS', False)
|
|
33 |
assert not getattr(tenant_settings, 'A2_REGISTRATION_FIELDS', False)
|
|
34 |
loader = AuthenticLoader()
|
|
35 |
loader.update_settings_from_path(tenant_settings, path)
|
|
36 |
assert tenant_settings.A2_PROFILE_FIELDS == profile_fields
|
|
37 |
assert tenant_settings.A2_REQUIRED_FIELDS == [u'first_name', u'last_name', u'email']
|
|
38 |
assert tenant_settings.A2_REGISTRATION_FIELDS == [u'first_name', u'last_name']
|
0 |
|
-
|