Projet

Général

Profil

0001-profile-remove-redundant-mobile-phone-field-69228.patch

Paul Marillonnet, 19 septembre 2022 16:18

Télécharger (11,3 ko)

Voir les différences:

Subject: [PATCH] profile: remove redundant mobile phone field (#69228)

 hobo/profile/migrations/0002_add_data.py |  1 -
 tests/test_environment.py                | 18 +++++++-------
 tests/test_settings_loaders.py           | 15 +++++-------
 tests_authentic/test_hobo_deploy.py      | 31 ++++++++----------------
 tests_schemas/example_env.json           | 13 ----------
 5 files changed, 25 insertions(+), 53 deletions(-)
hobo/profile/migrations/0002_add_data.py
18 18
        {'label': u'Pays', 'name': 'country', 'disabled': True},
19 19
        {'label': u'Date de naissance', 'name': 'birthdate', 'kind': 'birthdate', 'disabled': True},
20 20
        {'label': u'Téléphone', 'name': 'phone', 'kind': 'phone_number'},
21
        {'label': u'Mobile', 'name': 'mobile', 'kind': 'phone_number'},
22 21
    ]
23 22

  
24 23
    for i, attribute_dict in enumerate(attributes):
tests/test_environment.py
373 373
    Variable.objects.create(name='foo3', value='bar3').save()
374 374
    AttributeDefinition.objects.create(name='prefered_color', label='not empty').save()
375 375
    assert Variable.objects.count() == 3
376
    assert AttributeDefinition.objects.count() == 12
376
    assert AttributeDefinition.objects.count() == 11
377 377
    assert Variable.objects.get(name='foo').label == ''
378 378
    assert AttributeDefinition.objects.get(name='title').description == ''
379 379
    assert AttributeDefinition.objects.get(name='title').order == 1
380 380
    assert AttributeDefinition.objects.get(name='last_name').order == 3
381
    assert AttributeDefinition.objects.get(name='prefered_color').order == 12
381
    assert AttributeDefinition.objects.get(name='prefered_color').order == 11
382 382

  
383 383
    # import valid content
384 384
    resp = app.get('/', status=200)
......
386 386
    resp.form['parameters_json'] = Upload('export.json', export_json.encode('utf-8'), 'application/json')
387 387
    resp = resp.form.submit()
388 388
    assert Variable.objects.count() == 3
389
    assert AttributeDefinition.objects.count() == 12
389
    assert AttributeDefinition.objects.count() == 11
390 390
    assert Variable.objects.get(name='foo').label == 'bar'
391 391
    assert AttributeDefinition.objects.get(name='title').description == 'genre'
392 392
    assert AttributeDefinition.objects.get(name='title').order == 1
393 393
    assert AttributeDefinition.objects.get(name='last_name').label == 'Nom de naissance'
394 394
    assert AttributeDefinition.objects.get(name='last_name').order == 3
395
    assert AttributeDefinition.objects.get(name='prefered_color').order == 12
395
    assert AttributeDefinition.objects.get(name='prefered_color').order == 11
396 396

  
397 397
    # import empty json
398 398
    resp = app.get('/', status=200)
......
400 400
    resp.form['parameters_json'] = Upload('export.json', b'{}', 'application/json')
401 401
    resp = resp.form.submit()
402 402
    assert Variable.objects.count() == 3
403
    assert AttributeDefinition.objects.count() == 12
403
    assert AttributeDefinition.objects.count() == 11
404 404
    assert Variable.objects.get(name='foo').label == 'bar'
405 405
    assert AttributeDefinition.objects.get(name='title').description == 'genre'
406 406
    assert AttributeDefinition.objects.get(name='title').order == 1
407 407
    assert AttributeDefinition.objects.get(name='last_name').label == 'Nom de naissance'
408 408
    assert AttributeDefinition.objects.get(name='last_name').order == 3
409
    assert AttributeDefinition.objects.get(name='prefered_color').order == 12
409
    assert AttributeDefinition.objects.get(name='prefered_color').order == 11
410 410

  
411 411
    # import from scratch
412 412
    Variable.objects.all().delete()
......
420 420
    resp.form['parameters_json'] = Upload('export.json', export_json.encode('utf-8'), 'application/json')
421 421
    resp = resp.form.submit()
422 422
    assert Variable.objects.count() == 2
423
    assert AttributeDefinition.objects.count() == 12
423
    assert AttributeDefinition.objects.count() == 11
424 424
    assert Variable.objects.get(name='foo').label == 'bar'
425 425
    assert AttributeDefinition.objects.get(name='title').order == 4
426 426
    assert AttributeDefinition.objects.get(name='last_name').order == 2
......
432 432
    resp.form['parameters_json'] = Upload('export.json', b'garbage', 'application/json')
433 433
    resp = resp.form.submit()
434 434
    assert Variable.objects.count() == 2
435
    assert AttributeDefinition.objects.count() == 12
435
    assert AttributeDefinition.objects.count() == 11
436 436

  
437 437
    # import corrupted json
438 438
    export['variables'][0]['label'] = 'foofoo'
......
446 446
    with pytest.raises(IntegrityError):
447 447
        resp = resp.form.submit()
448 448
    assert Variable.objects.count() == 2
449
    assert AttributeDefinition.objects.count() == 12
449
    assert AttributeDefinition.objects.count() == 11
450 450
    assert Variable.objects.get(name='foo').label == 'bar'
451 451

  
452 452

  
tests/test_settings_loaders.py
31 31
        u'country',
32 32
        u'birthdate',
33 33
        u'phone',
34
        u'mobile',
35 34
    ]
36 35

  
37
    # swap title and mobile fields
36
    # swap title and phone fields
38 37
    title = AttributeDefinition.objects.get(name='title')
39
    mobile = AttributeDefinition.objects.get(name='mobile')
40
    (title.order, mobile.order) = (mobile.order, title.order)
38
    phone = AttributeDefinition.objects.get(name='phone')
39
    (title.order, phone.order) = (phone.order, title.order)
41 40
    title.save()
42
    mobile.save()
41
    phone.save()
43 42

  
44 43
    env = get_hobo_json()
45 44
    fields = env['profile']['fields']
46 45
    assert [x['name'] for x in fields] == [
47
        u'mobile',
46
        u'phone',
48 47
        u'first_name',
49 48
        u'last_name',
50 49
        u'email',
......
53 52
        u'city',
54 53
        u'country',
55 54
        u'birthdate',
56
        u'phone',
57 55
        u'title',
58 56
    ]
59 57

  
60 58
    assert [x['name'] for x in fields if x['disabled']] == ['country', 'birthdate', 'title']
61 59
    profile_fields = [x['name'] for x in fields if not x['disabled']]
62 60
    assert profile_fields == [
63
        u'mobile',
61
        u'phone',
64 62
        u'first_name',
65 63
        u'last_name',
66 64
        u'email',
67 65
        u'address',
68 66
        u'zipcode',
69 67
        u'city',
70
        u'phone',
71 68
    ]
72 69

  
73 70
    # serialize hobo.json
tests_authentic/test_hobo_deploy.py
245 245
                    'asked_on_registration': False,
246 246
                    'name': 'fr_phone',
247 247
                },
248
                {
249
                    'kind': 'string',
250
                    'description': '',
251
                    'required': False,
252
                    'user_visible': True,
253
                    'label': 'Mobile',
254
                    'disabled': False,
255
                    'user_editable': True,
256
                    'asked_on_registration': False,
257
                    'name': 'mobile',
258
                },
259 248
                {
260 249
                    'kind': 'string',
261 250
                    'description': '',
......
404 393
        assert user.is_staff is True
405 394
        from authentic2.models import Attribute
406 395

  
407
        assert Attribute.all_objects.count() == 12
396
        assert Attribute.all_objects.count() == 11
408 397
        for field in env['profile']['fields']:
409 398
            if field['name'] != 'email':
410 399
                at = Attribute.all_objects.get(name=field['name'])
......
437 426
        assert policy.authn_request_signed is False
438 427
        assert policy.accepted_name_id_format == ['uuid']
439 428
        assert policy.default_name_id_format == 'uuid'
440
        assert policy.attributes.count() == 16
441
        assert policy.attributes.filter(enabled=True).count() == 13
429
        assert policy.attributes.count() == 15
430
        assert policy.attributes.filter(enabled=True).count() == 12
442 431
        assert policy.attributes.filter(enabled=False).count() == 3
443
        assert policy.attributes.filter(name_format='basic').count() == 16
432
        assert policy.attributes.filter(name_format='basic').count() == 15
444 433
        assert (
445 434
            policy.attributes.filter(name='is_superuser', attribute_name='django_user_is_superuser').count()
446 435
            == 1
......
536 525

  
537 526
    # test attribute kind update
538 527
    with tenant_context(tenant):
539
        assert Attribute.objects.filter(name='mobile', kind='string').count() == 1
540
    field = env['profile']['fields'][9]
541
    assert field['name'] == 'mobile'
542
    field['kind'] = 'phone_number'
528
        assert Attribute.objects.filter(name='phone', kind='phone_number').count() == 1
529
    field = env['profile']['fields'][7]
530
    assert field['name'] == 'phone'
531
    field['kind'] = 'string'
543 532
    side_effect_iter = iter([meta1, meta2, RequestException(), meta4, meta3])
544 533
    with mock.patch('hobo.agent.authentic2.provisionning.notify_agents') as mock_notify, mock.patch(
545 534
        'hobo.agent.authentic2.management.commands.hobo_deploy.sleep', wraps=time.sleep
546 535
    ) as sleep_mock:
547 536
        call_command('hobo_deploy', 'http://sso.example.net', hobo_json(), ignore_timestamp=True)
548 537
    with tenant_context(tenant):
549
        assert Attribute.objects.filter(name='mobile', kind='string').count() == 0
550
        assert Attribute.objects.filter(name='mobile', kind='phone_number').count() == 1
538
        assert Attribute.objects.filter(name='phone', kind='phone_number').count() == 0
539
        assert Attribute.objects.filter(name='phone', kind='string').count() == 1
551 540

  
552 541

  
553 542
def test_import_template(db, tenant_base):
tests_schemas/example_env.json
130 130
                "searchable": false,
131 131
                "user_editable": true,
132 132
                "user_visible": true
133
            },
134
            {
135
                "asked_on_registration": false,
136
                "description": "",
137
                "disabled": false,
138
                "kind": "phone_number",
139
                "label": "Mobile",
140
                "name": "mobile",
141
                "required": false,
142
                "required_on_login": false,
143
                "searchable": false,
144
                "user_editable": true,
145
                "user_visible": true
146 133
            }
147 134
        ]
148 135
    },
149
-