Projet

Général

Profil

0001-user-export-csv-exclude-disabled-attributes-30103.patch

Emmanuel Cazenave, 25 janvier 2019 15:35

Télécharger (2,47 ko)

Voir les différences:

Subject: [PATCH] user export csv : exclude disabled attributes (#30103)

 src/authentic2/manager/user_views.py |  4 +++-
 tests/test_user_manager.py           | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
src/authentic2/manager/user_views.py
355 355

  
356 356
        at_mapping = {a.id: a for a in Attribute.objects.all()}
357 357
        avs = AttributeValue.objects.filter(
358
            content_type=ContentType.objects.get_for_model(get_user_model())).values()
358
            content_type=ContentType.objects.get_for_model(get_user_model()))\
359
            .filter(attribute__disabled=False).values()
360

  
359 361
        user_attrs = collections.defaultdict(dict)
360 362
        for av in avs:
361 363
            user_attrs[av['object_id']][at_mapping[av['attribute_id']].name] = av['content']
tests/test_user_manager.py
131 131
    assert len(table) == (user_count + 1)
132 132
    assert len(table[0]) == (15 + AT_COUNT)
133 133

  
134

  
135
@skipif_sqlite
136
def test_export_csv_disabled_attribute(settings, app, superuser):
137
    attr = Attribute.objects.create(name='attr', label='Attr', kind='string')
138
    attr_d = Attribute.objects.create(name='attrd', label='Attrd', kind='string')
139

  
140
    user = User.objects.create(username='user-foo')
141
    AttributeValue.objects.create(owner=user, attribute=attr, content='attr-value')
142
    AttributeValue.objects.create(owner=user, attribute=attr_d, content='attrd-value')
143

  
144
    attr_d.disabled = True
145
    attr_d.save()
146

  
147
    response = login(app, superuser, reverse('a2-manager-users'))
148
    settings.A2_CACHE_ENABLED = True
149
    response = response.click('CSV')
150

  
151
    user_count = User.objects.count()
152
    table = list(csv.reader(response.content.splitlines()))
153
    assert len(table) == (user_count + 1)
154
    num_col = 15 + 1  # 1 is the number active attributes,
155
    # disabled attribute should not show up
156
    for line in table:
157
        assert len(line) == num_col
134
-