|
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 |
from hobo.profile.models import AttributeDefinition
|
|
11 |
|
|
12 |
pytestmark = pytest.mark.django_db
|
|
13 |
|
|
14 |
|
|
15 |
def test_authentic_update_settings_from_path(tmpdir):
|
|
16 |
a = Authentic(title='bar', slug='bar', base_url='http://bar.example.net')
|
|
17 |
a.save()
|
|
18 |
|
|
19 |
env = get_hobo_json()
|
|
20 |
fields = env['profile']['fields']
|
|
21 |
assert [x['name'] for x in fields] == [
|
|
22 |
u'title', u'first_name', u'last_name', u'email', u'address',u'zipcode',
|
|
23 |
u'city', u'country', u'birthdate', u'phone', u'mobile']
|
|
24 |
|
|
25 |
# swap title and mobile fields
|
|
26 |
title = AttributeDefinition.objects.get(name='title')
|
|
27 |
mobile = AttributeDefinition.objects.get(name='mobile')
|
|
28 |
(title.order, mobile.order) = (mobile.order, title.order)
|
|
29 |
title.save()
|
|
30 |
mobile.save()
|
|
31 |
|
|
32 |
env = get_hobo_json()
|
|
33 |
fields = env['profile']['fields']
|
|
34 |
assert [x['name'] for x in fields] == [
|
|
35 |
u'mobile', u'first_name', u'last_name', u'email', u'address',u'zipcode',
|
|
36 |
u'city', u'country', u'birthdate', u'phone', u'title']
|
|
37 |
|
|
38 |
assert [x['name'] for x in fields if x['disabled']] == [u'country', u'birthdate']
|
|
39 |
profile_fields = [x['name'] for x in fields if not x['disabled']]
|
|
40 |
assert profile_fields == [
|
|
41 |
u'mobile', u'first_name', u'last_name', u'email',
|
|
42 |
u'address', u'zipcode', u'city', u'phone', u'title']
|
|
43 |
|
|
44 |
# serialize hobo.json
|
|
45 |
path = os.path.join(str(tmpdir), 'hobo.json')
|
|
46 |
json.dump(env, open(path, 'w'))
|
|
47 |
|
|
48 |
# call settings loaders
|
|
49 |
tenant_settings = UserSettingsHolder({})
|
|
50 |
assert not getattr(tenant_settings, 'A2_PROFILE_FIELDS', False)
|
|
51 |
assert not getattr(tenant_settings, 'A2_REQUIRED_FIELDS', False)
|
|
52 |
assert not getattr(tenant_settings, 'A2_REGISTRATION_FIELDS', False)
|
|
53 |
loader = AuthenticLoader()
|
|
54 |
loader.update_settings_from_path(tenant_settings, path)
|
|
55 |
assert tenant_settings.A2_PROFILE_FIELDS == profile_fields
|
|
56 |
assert tenant_settings.A2_REQUIRED_FIELDS == [u'first_name', u'last_name', u'email']
|
|
57 |
assert tenant_settings.A2_REGISTRATION_FIELDS == [u'first_name', u'last_name']
|
0 |
|
-
|