Projet

Général

Profil

0001-csv_import-set-verification-source-for-user-attribut.patch

Paul Marillonnet, 09 juin 2022 09:34

Télécharger (2,88 ko)

Voir les différences:

Subject: [PATCH] csv_import: set verification source for user attributes
 (#66053)

 src/authentic2/csv_import.py |  2 +-
 tests/test_csv_import.py     | 33 ++++++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)
src/authentic2/csv_import.py
740 740
                if cell.header.verified:
741 741
                    attributes = user.verified_attributes
742 742
                if getattr(attributes, cell.header.name) != cell.value:
743
                    setattr(attributes, cell.header.name, cell.value)
743
                    attributes._set_sourced_attr(cell.header.name, cell.value, 'csv')
744 744
                    cell.action = 'updated'
745 745
                    continue
746 746
            cell.action = 'nothing'
tests/test_csv_import.py
27 27
from authentic2.a2_rbac.utils import get_default_ou
28 28
from authentic2.csv_import import CsvHeader, CsvImporter, Error, LineError, UserCsvImporter
29 29
from authentic2.custom_user.models import User
30
from authentic2.models import Attribute, PasswordReset
30
from authentic2.models import Attribute, AttributeValue, PasswordReset
31 31

  
32 32
ENCODINGS = [
33 33
    'iso-8859-1',
......
698 698
    user2.refresh_from_db()
699 699
    assert user1.last_name == 'Doe'
700 700
    assert user2.last_name == 'Doe2'
701

  
702

  
703
def test_user_attributes_verified(db, profile, user_csv_importer_factory):
704
    content = '''email key,first_name,last_name,phone verified
705
jdoe@nowhere.null,John,Doe,1234
706
jsmith@nowhere.null,Jimmy,Smith,5678'''
707
    importer = user_csv_importer_factory(content)
708

  
709
    assert importer.run(), importer.errors
710
    assert importer.headers == [
711
        CsvHeader(1, 'email', field=True, key=True, verified=True),
712
        CsvHeader(2, 'first_name', field=True),
713
        CsvHeader(3, 'last_name', field=True),
714
        CsvHeader(4, 'phone', attribute=True, verified=True),
715
    ]
716

  
717
    jdoe = User.objects.get(email='jdoe@nowhere.null')
718
    assert jdoe.verified_attributes.phone == '1234'
719

  
720
    jsmith = User.objects.get(email='jsmith@nowhere.null')
721
    assert jsmith.verified_attributes.phone == '5678'
722

  
723
    for user in (
724
        jdoe,
725
        jsmith,
726
    ):
727
        attribute = Attribute.objects.get(name='phone')
728
        av = AttributeValue.objects.with_owner(user).get(attribute=attribute)
729
        assert av.verified
730
        assert av.verification_sources == ['csv']
731
        assert av.last_verified_on
701
-