Projet

Général

Profil

0001-csv_import-ignore-empty-role-values-50158.patch

Valentin Deniaud, 23 février 2021 16:03

Télécharger (1,5 ko)

Voir les différences:

Subject: [PATCH] csv_import: ignore empty role values (#50158)

 src/authentic2/csv_import.py | 2 ++
 tests/test_csv_import.py     | 6 ++++++
 2 files changed, 8 insertions(+)
src/authentic2/csv_import.py
744 744
        return success
745 745

  
746 746
    def add_role(self, cell, user, do_clear=False):
747
        if not cell.value:
748
            return True
747 749
        try:
748 750
            if cell.header.name == ROLE_NAME:
749 751
                role = Role.objects.get(name=cell.value, ou=self.ou)
tests/test_csv_import.py
496 496
    assert importer.has_errors
497 497
    assert importer.errors[0].code == 'invalid-role-column'
498 498

  
499
    # empty role name doesn't raise error
500
    content_name_error = '\n'.join((base_header + '_role_name', base_user + ''))
501
    importer = user_csv_importer_factory(content_name_error)
502
    assert importer.run()
503
    assert not importer.has_errors
504

  
499 505

  
500 506
def test_csv_registration_options(profile, user_csv_importer_factory):
501 507
    content = '''email key,first_name,last_name,@registration
502
-