profile: remove redundant mobile phone field (#69228)

This commit is contained in:
Paul Marillonnet 2022-09-19 15:43:24 +02:00
parent 4fbb177534
commit c13cbfb21d
5 changed files with 25 additions and 53 deletions

View File

@ -15,7 +15,6 @@ def add_initial_data(apps, schema_editor):
{'label': 'Pays', 'name': 'country', 'disabled': True},
{'label': 'Date de naissance', 'name': 'birthdate', 'kind': 'birthdate', 'disabled': True},
{'label': 'Téléphone', 'name': 'phone', 'kind': 'phone_number'},
{'label': 'Mobile', 'name': 'mobile', 'kind': 'phone_number'},
]
for i, attribute_dict in enumerate(attributes):

View File

@ -372,12 +372,12 @@ def test_export_import_view(app, admin_user):
Variable.objects.create(name='foo3', value='bar3').save()
AttributeDefinition.objects.create(name='prefered_color', label='not empty').save()
assert Variable.objects.count() == 3
assert AttributeDefinition.objects.count() == 12
assert AttributeDefinition.objects.count() == 11
assert Variable.objects.get(name='foo').label == ''
assert AttributeDefinition.objects.get(name='title').description == ''
assert AttributeDefinition.objects.get(name='title').order == 1
assert AttributeDefinition.objects.get(name='last_name').order == 3
assert AttributeDefinition.objects.get(name='prefered_color').order == 12
assert AttributeDefinition.objects.get(name='prefered_color').order == 11
# import valid content
resp = app.get('/', status=200)
@ -385,13 +385,13 @@ def test_export_import_view(app, admin_user):
resp.form['parameters_json'] = Upload('export.json', export_json.encode('utf-8'), 'application/json')
resp = resp.form.submit()
assert Variable.objects.count() == 3
assert AttributeDefinition.objects.count() == 12
assert AttributeDefinition.objects.count() == 11
assert Variable.objects.get(name='foo').label == 'bar'
assert AttributeDefinition.objects.get(name='title').description == 'genre'
assert AttributeDefinition.objects.get(name='title').order == 1
assert AttributeDefinition.objects.get(name='last_name').label == 'Nom de naissance'
assert AttributeDefinition.objects.get(name='last_name').order == 3
assert AttributeDefinition.objects.get(name='prefered_color').order == 12
assert AttributeDefinition.objects.get(name='prefered_color').order == 11
# import empty json
resp = app.get('/', status=200)
@ -399,13 +399,13 @@ def test_export_import_view(app, admin_user):
resp.form['parameters_json'] = Upload('export.json', b'{}', 'application/json')
resp = resp.form.submit()
assert Variable.objects.count() == 3
assert AttributeDefinition.objects.count() == 12
assert AttributeDefinition.objects.count() == 11
assert Variable.objects.get(name='foo').label == 'bar'
assert AttributeDefinition.objects.get(name='title').description == 'genre'
assert AttributeDefinition.objects.get(name='title').order == 1
assert AttributeDefinition.objects.get(name='last_name').label == 'Nom de naissance'
assert AttributeDefinition.objects.get(name='last_name').order == 3
assert AttributeDefinition.objects.get(name='prefered_color').order == 12
assert AttributeDefinition.objects.get(name='prefered_color').order == 11
# import from scratch
Variable.objects.all().delete()
@ -419,7 +419,7 @@ def test_export_import_view(app, admin_user):
resp.form['parameters_json'] = Upload('export.json', export_json.encode('utf-8'), 'application/json')
resp = resp.form.submit()
assert Variable.objects.count() == 2
assert AttributeDefinition.objects.count() == 12
assert AttributeDefinition.objects.count() == 11
assert Variable.objects.get(name='foo').label == 'bar'
assert AttributeDefinition.objects.get(name='title').order == 4
assert AttributeDefinition.objects.get(name='last_name').order == 2
@ -431,7 +431,7 @@ def test_export_import_view(app, admin_user):
resp.form['parameters_json'] = Upload('export.json', b'garbage', 'application/json')
resp = resp.form.submit()
assert Variable.objects.count() == 2
assert AttributeDefinition.objects.count() == 12
assert AttributeDefinition.objects.count() == 11
# import corrupted json
export['variables'][0]['label'] = 'foofoo'
@ -445,7 +445,7 @@ def test_export_import_view(app, admin_user):
with pytest.raises(IntegrityError):
resp = resp.form.submit()
assert Variable.objects.count() == 2
assert AttributeDefinition.objects.count() == 12
assert AttributeDefinition.objects.count() == 11
assert Variable.objects.get(name='foo').label == 'bar'

View File

@ -31,20 +31,19 @@ def test_authentic_update_settings_from_path(tmpdir):
'country',
'birthdate',
'phone',
'mobile',
]
# swap title and mobile fields
# swap title and phone fields
title = AttributeDefinition.objects.get(name='title')
mobile = AttributeDefinition.objects.get(name='mobile')
(title.order, mobile.order) = (mobile.order, title.order)
phone = AttributeDefinition.objects.get(name='phone')
(title.order, phone.order) = (phone.order, title.order)
title.save()
mobile.save()
phone.save()
env = get_hobo_json()
fields = env['profile']['fields']
assert [x['name'] for x in fields] == [
'mobile',
'phone',
'first_name',
'last_name',
'email',
@ -53,21 +52,19 @@ def test_authentic_update_settings_from_path(tmpdir):
'city',
'country',
'birthdate',
'phone',
'title',
]
assert [x['name'] for x in fields if x['disabled']] == ['country', 'birthdate', 'title']
profile_fields = [x['name'] for x in fields if not x['disabled']]
assert profile_fields == [
'mobile',
'phone',
'first_name',
'last_name',
'email',
'address',
'zipcode',
'city',
'phone',
]
# serialize hobo.json

View File

@ -244,17 +244,6 @@ def test_hobo_deploy(monkeypatch, tenant_base, mocker, skeleton_dir, tmp_path):
'asked_on_registration': False,
'name': 'fr_phone',
},
{
'kind': 'string',
'description': '',
'required': False,
'user_visible': True,
'label': 'Mobile',
'disabled': False,
'user_editable': True,
'asked_on_registration': False,
'name': 'mobile',
},
{
'kind': 'string',
'description': '',
@ -403,7 +392,7 @@ def test_hobo_deploy(monkeypatch, tenant_base, mocker, skeleton_dir, tmp_path):
assert user.is_staff is True
from authentic2.models import Attribute
assert Attribute.all_objects.count() == 12
assert Attribute.all_objects.count() == 11
for field in env['profile']['fields']:
if field['name'] != 'email':
at = Attribute.all_objects.get(name=field['name'])
@ -436,10 +425,10 @@ def test_hobo_deploy(monkeypatch, tenant_base, mocker, skeleton_dir, tmp_path):
assert policy.authn_request_signed is False
assert policy.accepted_name_id_format == ['uuid']
assert policy.default_name_id_format == 'uuid'
assert policy.attributes.count() == 16
assert policy.attributes.filter(enabled=True).count() == 13
assert policy.attributes.count() == 15
assert policy.attributes.filter(enabled=True).count() == 12
assert policy.attributes.filter(enabled=False).count() == 3
assert policy.attributes.filter(name_format='basic').count() == 16
assert policy.attributes.filter(name_format='basic').count() == 15
assert (
policy.attributes.filter(name='is_superuser', attribute_name='django_user_is_superuser').count()
== 1
@ -535,18 +524,18 @@ def test_hobo_deploy(monkeypatch, tenant_base, mocker, skeleton_dir, tmp_path):
# test attribute kind update
with tenant_context(tenant):
assert Attribute.objects.filter(name='mobile', kind='string').count() == 1
field = env['profile']['fields'][9]
assert field['name'] == 'mobile'
field['kind'] = 'phone_number'
assert Attribute.objects.filter(name='phone', kind='phone_number').count() == 1
field = env['profile']['fields'][7]
assert field['name'] == 'phone'
field['kind'] = 'string'
side_effect_iter = iter([meta1, meta2, RequestException(), meta4, meta3])
with mock.patch('hobo.agent.authentic2.provisionning.notify_agents') as mock_notify, mock.patch(
'hobo.agent.authentic2.management.commands.hobo_deploy.sleep', wraps=time.sleep
) as sleep_mock:
call_command('hobo_deploy', 'http://sso.example.net', hobo_json(), ignore_timestamp=True)
with tenant_context(tenant):
assert Attribute.objects.filter(name='mobile', kind='string').count() == 0
assert Attribute.objects.filter(name='mobile', kind='phone_number').count() == 1
assert Attribute.objects.filter(name='phone', kind='phone_number').count() == 0
assert Attribute.objects.filter(name='phone', kind='string').count() == 1
def test_import_template(db, tenant_base):

View File

@ -130,19 +130,6 @@
"searchable": false,
"user_editable": true,
"user_visible": true
},
{
"asked_on_registration": false,
"description": "",
"disabled": false,
"kind": "phone_number",
"label": "Mobile",
"name": "mobile",
"required": false,
"required_on_login": false,
"searchable": false,
"user_editable": true,
"user_visible": true
}
]
},