0001-misc-do-not-modify-email-when-marking-users-as-delet.patch
src/authentic2/api_views.py | ||
---|---|---|
157 | 157 |
'this ou')) |
158 | 158 |
User = get_user_model() |
159 | 159 |
if ou: |
160 |
if ou.email_is_unique and \ |
|
161 |
User.objects.filter(ou=ou, email__iexact=data['email']).exists(): |
|
162 |
raise serializers.ValidationError( |
|
163 |
_('You already have an account')) |
|
164 |
if (ou.username_is_unique |
|
165 |
and 'username' not in data): |
|
166 |
raise serializers.ValidationError( |
|
167 |
_('Username is required in this ou')) |
|
168 |
if ou.username_is_unique and User.objects.filter( |
|
169 |
ou=data['ou'], username=data['username']).exists(): |
|
170 |
raise serializers.ValidationError(_('You already have an account')) |
|
160 |
if (app_settings.A2_EMAIL_IS_UNIQUE or |
|
161 |
app_settings.A2_REGISTRATION_EMAIL_IS_UNIQUE): |
|
162 |
if 'email' not in data: |
|
163 |
raise serializers.ValidationError( |
|
164 |
_('Email is required')) |
|
165 |
if User.objects.filter( |
|
166 |
email__iexact=data['email'], |
|
167 |
deleted__isnull=True).exists(): |
|
168 |
raise serializers.ValidationError( |
|
169 |
_('You already have an account')) |
|
170 | ||
171 |
if ou.email_is_unique: |
|
172 |
if 'email' not in data: |
|
173 |
raise serializers.ValidationError( |
|
174 |
_('Email is required in this ou')) |
|
175 |
if User.objects.filter( |
|
176 |
ou=ou, email__iexact=data['email'], |
|
177 |
deleted__isnull=True).exists(): |
|
178 |
raise serializers.ValidationError( |
|
179 |
_('You already have an account in this ou')) |
|
180 | ||
181 |
if (app_settings.A2_USERNAME_IS_UNIQUE or |
|
182 |
app_settings.A2_REGISTRATION_USERNAME_IS_UNIQUE): |
|
183 |
if 'username' not in data: |
|
184 |
raise serializers.ValidationError( |
|
185 |
_('Username is required')) |
|
186 |
if User.objects.filter( |
|
187 |
username=data['username'], |
|
188 |
deleted__isnull=True).exists(): |
|
189 |
raise serializers.ValidationError( |
|
190 |
_('You already have an account')) |
|
191 | ||
192 |
if ou.username_is_unique: |
|
193 |
if 'username' not in data: |
|
194 |
raise serializers.ValidationError( |
|
195 |
_('Username is required in this ou')) |
|
196 |
if User.objects.filter( |
|
197 |
ou=ou, username=data['username'], |
|
198 |
deleted__isnull=True).exists(): |
|
199 |
raise serializers.ValidationError( |
|
200 |
_('You already have an account in this ou')) |
|
171 | 201 |
return data |
172 | 202 | |
173 | 203 | |
... | ... | |
310 | 340 | |
311 | 341 |
def validate(self, data): |
312 | 342 |
User = get_user_model() |
313 |
qs = User.objects.filter(email=data['email']) |
|
343 |
qs = User.objects.filter(email=data['email'], deleted__isnull=True)
|
|
314 | 344 |
if data['ou']: |
315 | 345 |
qs = qs.filter(ou=data['ou']) |
316 | 346 |
try: |
... | ... | |
495 | 525 |
and 'email' not in update_or_create_fields |
496 | 526 |
and data.get('email') |
497 | 527 |
and (not self.instance or data.get('email') != self.instance.email)): |
498 |
if app_settings.A2_EMAIL_IS_UNIQUE and qs.filter(email=data['email']).exists(): |
|
528 |
if app_settings.A2_EMAIL_IS_UNIQUE and qs.filter( |
|
529 |
email=data['email'], deleted__isnull=True).exists(): |
|
499 | 530 |
already_used = True |
500 |
if ou and ou.email_is_unique and qs.filter(ou=ou, email=data['email']).exists(): |
|
531 |
if ou and ou.email_is_unique and qs.filter( |
|
532 |
ou=ou, email=data['email'], deleted__isnull=True).exists(): |
|
501 | 533 |
already_used = True |
502 | 534 | |
503 | 535 |
errors = {} |
... | ... | |
719 | 751 | |
720 | 752 |
def get_queryset(self): |
721 | 753 |
User = get_user_model() |
722 |
qs = User.objects.all()
|
|
754 |
qs = User.objects.filter(deleted__isnull=True)
|
|
723 | 755 |
if self.request.method == 'GET': |
724 | 756 |
qs = qs.prefetch_related('attribute_values', 'attribute_values__attribute') |
725 | 757 |
qs = self.request.user.filter_by_perm(['custom_user.view_user'], qs) |
src/authentic2/app_settings.py | ||
---|---|---|
144 | 144 |
definition='Email of users must be unique'), |
145 | 145 |
A2_REGISTRATION_EMAIL_IS_UNIQUE=Setting( |
146 | 146 |
default=False, |
147 |
definition='Email of registererd accounts must be unique'),
|
|
147 |
definition='Email of registered accounts must be unique'), |
|
148 | 148 |
A2_REGISTRATION_FORM_USERNAME_REGEX=Setting( |
149 | 149 |
default=r'^[\w.@+-]+$', |
150 | 150 |
definition='Regex to validate usernames'), |
src/authentic2/apps/journal/search_engine.py | ||
---|---|---|
116 | 116 |
return models.EventQuerySet._which_references_query(users) |
117 | 117 | |
118 | 118 |
def search_by_email(self, email): |
119 |
users = User.objects.filter(email__iexact=email.lower()) |
|
119 |
users = User.objects.filter(email__iexact=email.lower(), deleted__isnull=True)
|
|
120 | 120 |
yield (self.query_for_users(users) | Q(data__email__iexact=email.lower())) |
121 | 121 | |
122 | 122 |
search_by_event.documentation = _( |
src/authentic2/backends/models_backend.py | ||
---|---|---|
46 | 46 |
try: |
47 | 47 |
if app_settings.A2_ACCEPT_EMAIL_AUTHENTICATION \ |
48 | 48 |
and UserModel._meta.get_field('email'): |
49 |
queries.append(models.Q(**{'email__iexact': username})) |
|
49 |
queries.append(models.Q(**{ |
|
50 |
'email__iexact': username, 'deleted__isnull': True})) |
|
50 | 51 |
except models.FieldDoesNotExist: |
51 | 52 |
pass |
52 | 53 |
src/authentic2/csv_import.py | ||
---|---|---|
643 | 643 |
key_value = row[header_key].value |
644 | 644 |
if header_key.field: |
645 | 645 |
users = User.objects.filter( |
646 |
**{header_key.name: key_value}) |
|
646 |
**{header_key.name: key_value}, deleted__isnull=True)
|
|
647 | 647 |
elif header_key.attribute: |
648 | 648 |
atvs = AttributeValue.objects.filter(attribute__name=header_key.name, content=key_value) |
649 |
users = User.objects.filter(attribute_values__in=atvs) |
|
649 |
users = User.objects.filter( |
|
650 |
attribute_values__in=atvs, deleted__isnull=True) |
|
650 | 651 |
users = users[:2] |
651 | 652 | |
652 | 653 |
if users: |
src/authentic2/custom_user/models.py | ||
---|---|---|
292 | 292 |
email_qs = qs.filter(ou=self.ou) |
293 | 293 |
try: |
294 | 294 |
try: |
295 |
email_qs.get(email__iexact=self.email) |
|
295 |
email_qs.get(email__iexact=self.email, deleted__isnull=True)
|
|
296 | 296 |
except MultipleObjectsReturned: |
297 | 297 |
pass |
298 | 298 |
except model.DoesNotExist: |
... | ... | |
363 | 363 | |
364 | 364 |
def mark_as_deleted(self, timestamp=None, force=True, save=True): |
365 | 365 |
self.is_active = False |
366 |
self.email_verified = False |
|
367 |
if self.email and '#' not in self.email: |
|
368 |
self.email += '#%d' % random.randint(1, 10000000) |
|
369 | 366 |
if force or not self.deleted: |
370 | 367 |
self.deleted = timestamp or timezone.now() |
371 | 368 |
if save: |
372 |
self.save(update_fields=['email', 'email_verified', 'is_active', 'deleted'])
|
|
369 |
self.save(update_fields=['is_active', 'deleted']) |
|
373 | 370 | |
374 | 371 | |
375 | 372 |
class DeletedUser(models.Model): |
src/authentic2/forms/passwords.py | ||
---|---|---|
45 | 45 |
""" |
46 | 46 |
email = self.cleaned_data["email"].strip() |
47 | 47 |
users = get_user_queryset() |
48 |
active_users = users.filter(email__iexact=email, is_active=True)
|
|
48 |
active_users = users.filter(email__iexact=email, deleted__isnull=True)
|
|
49 | 49 |
for user in active_users: |
50 | 50 |
# we don't set the password to a random string, as some users should not have |
51 | 51 |
# a password |
src/authentic2/forms/registration.py | ||
---|---|---|
95 | 95 |
if app_settings.A2_REGISTRATION_EMAIL_IS_UNIQUE: |
96 | 96 |
exist = False |
97 | 97 |
try: |
98 |
User.objects.get(email__iexact=email) |
|
98 |
User.objects.get(email__iexact=email, deleted__isnull=True)
|
|
99 | 99 |
except User.DoesNotExist: |
100 | 100 |
pass |
101 | 101 |
except User.MultipleObjectsReturned: |
src/authentic2/management/commands/check-and-repair.py | ||
---|---|---|
394 | 394 |
if not emails: |
395 | 395 |
return |
396 | 396 |
users = qs.annotate(iemail=Lower('email')) |
397 |
count = users.filter(iemail__in=emails).count() |
|
397 |
count = users.filter(iemail__in=emails, deleted__isnull=True).count()
|
|
398 | 398 |
self.warning('%s, found %%d user accounts with same email:' % msg, count) |
399 | 399 |
for email in emails: |
400 | 400 |
self.notice('- %s :', email) |
src/authentic2/utils/__init__.py | ||
---|---|---|
732 | 732 |
**kwargs) |
733 | 733 | |
734 | 734 |
# existing accounts |
735 |
existing_accounts = User.objects.filter(email=email) |
|
735 |
existing_accounts = User.objects.filter(email=email, deleted__isnull=True)
|
|
736 | 736 |
if not app_settings.A2_EMAIL_IS_UNIQUE: |
737 | 737 |
existing_accounts = existing_accounts.filter(ou=ou, email=email) |
738 | 738 |
src/authentic2/views.py | ||
---|---|---|
209 | 209 |
user = User.objects.get(pk=user_pk) |
210 | 210 |
non_unique = False |
211 | 211 |
if app_settings.A2_EMAIL_IS_UNIQUE: |
212 |
non_unique = User.objects.filter(email=email).exclude(pk=user_pk).exists() |
|
212 |
non_unique = User.objects.filter( |
|
213 |
email=email, deleted__isnull=True).exclude(pk=user_pk).exists() |
|
213 | 214 |
elif user.ou and user.ou.email_is_unique: |
214 |
non_unique = User.objects.filter(email=email, ou=user.ou).exclude( |
|
215 |
pk=user_pk).exists() |
|
215 |
non_unique = User.objects.filter( |
|
216 |
email=email, ou=user.ou, deleted__isnull=True).exclude( |
|
217 |
pk=user_pk).exists() |
|
216 | 218 |
if non_unique: |
217 | 219 |
raise ValidationError(_('This email is already used by another account.')) |
218 | 220 |
old_email = user.email |
... | ... | |
935 | 937 |
self.ou = OU.objects.get(pk=self.token['ou']) |
936 | 938 |
else: |
937 | 939 |
self.ou = get_default_ou() |
938 |
self.users = User.objects.filter(email__iexact=self.email) \ |
|
940 |
self.users = User.objects.filter(email__iexact=self.email, deleted__isnull=True) \
|
|
939 | 941 |
.order_by('date_joined') |
940 | 942 |
if self.ou: |
941 | 943 |
self.users = self.users.filter(ou=self.ou) |
src/authentic2_auth_fc/views.py | ||
---|---|---|
414 | 414 |
if not user and self.user_info.get('email') and email_is_unique: |
415 | 415 |
email = self.user_info['email'] |
416 | 416 |
User = get_user_model() |
417 |
qs = User.objects.filter(email__iexact=email) |
|
417 |
qs = User.objects.filter(email__iexact=email, deleted__isnull=True)
|
|
418 | 418 |
if not a2_app_settings.A2_EMAIL_IS_UNIQUE and default_ou.email_is_unique: |
419 | 419 |
qs = qs.filter(ou=default_ou) |
420 | 420 |
tests/test_all.py | ||
---|---|---|
523 | 523 |
content_type='application/json', |
524 | 524 |
data=json.dumps(payload)) |
525 | 525 |
self.assertEqual(response.data['errors']['__all__'], |
526 |
[_('You already have an account')]) |
|
526 |
[_('You already have an account in this ou')])
|
|
527 | 527 |
# Username is required |
528 | 528 |
payload = { |
529 | 529 |
'email': '1' + email, |
... | ... | |
535 | 535 |
content_type='application/json', |
536 | 536 |
data=json.dumps(payload)) |
537 | 537 |
self.assertEqual(response.data['errors']['__all__'], |
538 |
[_('Username is required in this ou')])
|
|
538 |
[_('Username is required')]) |
|
539 | 539 |
# Test username is unique |
540 | 540 |
payload = { |
541 | 541 |
'email': '1' + email, |
... | ... | |
637 | 637 |
content_type='application/json', |
638 | 638 |
data=json.dumps(payload)) |
639 | 639 |
self.assertEqual(response.data['errors']['__all__'], |
640 |
[_('You already have an account')]) |
|
640 |
[_('You already have an account in this ou')])
|
|
641 | 641 |
# Username is required |
642 | 642 |
payload = { |
643 | 643 |
'email': '1' + email, |
... | ... | |
649 | 649 |
content_type='application/json', |
650 | 650 |
data=json.dumps(payload)) |
651 | 651 |
self.assertEqual(response.data['errors']['__all__'], |
652 |
[_('Username is required in this ou')])
|
|
652 |
[_('Username is required')]) |
|
653 | 653 |
# Test username is unique |
654 | 654 |
payload = { |
655 | 655 |
'email': '1' + email, |
tests/test_api.py | ||
---|---|---|
364 | 364 |
def test_api_users_list_search_text(app, superuser): |
365 | 365 |
app.authorization = ('Basic', (superuser.username, superuser.username)) |
366 | 366 |
User = get_user_model() |
367 |
User.objects.create(username='someuser') |
|
367 |
someuser = User.objects.create(username='someuser')
|
|
368 | 368 |
resp = app.get('/api/users/?q=some') |
369 | 369 |
results = resp.json['results'] |
370 | 370 |
assert len(results) == 1 |
371 | 371 |
assert results[0]['username'] == 'someuser' |
372 |
someuser.mark_as_deleted() |
|
373 |
resp = app.get('/api/users/?q=some') |
|
374 |
results = resp.json['results'] |
|
375 |
assert not len(results) |
|
372 | 376 | |
373 | 377 | |
374 | 378 |
def test_api_users_create(settings, app, api_user): |
... | ... | |
872 | 876 |
assert resp.json['errors'] == ["List elements of the 'data' dict entry must be dictionaries"] |
873 | 877 | |
874 | 878 | |
875 |
def test_register_no_email_validation(app, admin, django_user_model): |
|
879 |
def test_register_no_email_validation(settings, app, admin, django_user_model): |
|
880 |
settings.A2_USERNAME_IS_UNIQUE = False |
|
881 |
settings.A2_REGISTRATION_USERNAME_IS_UNIQUE = False |
|
876 | 882 |
User = django_user_model |
877 | 883 |
password = '12XYab' |
878 | 884 |
username = 'john.doe' |
... | ... | |
928 | 934 |
assert user.check_password(password) |
929 | 935 | |
930 | 936 | |
931 |
def test_register_ou_no_email_validation(app, admin, django_user_model): |
|
937 |
def test_register_ou_no_email_validation(settings, app, admin, django_user_model): |
|
938 |
settings.A2_USERNAME_IS_UNIQUE = False |
|
939 |
settings.A2_REGISTRATION_USERNAME_IS_UNIQUE = False |
|
932 | 940 |
User = django_user_model |
933 | 941 |
password = '12XYab' |
934 | 942 |
username = 'john.doe' |
... | ... | |
1973 | 1981 |
resp = app.get('/api/address-autocomplete/', params=params) |
1974 | 1982 |
assert resp.json == {} |
1975 | 1983 |
assert requests_get.call_args_list == [] |
1984 | ||
1985 | ||
1986 |
def test_api_users_mark_as_deleted(app, settings, admin): |
|
1987 |
email='foo@example.net' |
|
1988 |
user1 = User.objects.create(username='foo', email=email) |
|
1989 |
user1.mark_as_deleted() |
|
1990 |
user2 = User.objects.create(username='foo2', email=email) |
|
1991 | ||
1992 |
app.authorization = ('Basic', (admin.username, admin.username)) |
|
1993 |
resp = app.get('/api/users/?email={}'.format(email)) |
|
1994 |
assert len(resp.json['results']) == 1 |
|
1995 | ||
1996 |
payload = { |
|
1997 |
'username': 'foo3', |
|
1998 |
'email': email, |
|
1999 |
'first_name': 'John', |
|
2000 |
'last_name': 'Doe', |
|
2001 |
} |
|
2002 |
headers = basic_authorization_header(admin) |
|
2003 |
app.post_json('/api/users/', headers=headers, params=payload, status=201) |
|
2004 | ||
2005 |
resp = app.get('/api/users/?email={}'.format(email)) |
|
2006 |
assert len(resp.json['results']) == 2 |
|
2007 | ||
2008 |
user2.mark_as_deleted() |
|
2009 |
resp = app.get('/api/users/?email={}'.format(email)) |
|
2010 |
assert len(resp.json['results']) == 1 |
|
2011 | ||
2012 |
settings.A2_EMAIL_IS_UNIQUE = True |
|
2013 |
# email already used |
|
2014 |
resp = app.post_json('/api/users/', headers=headers, params=payload, status=400) |
|
2015 |
assert resp.json['errors'] == {'email': ['email already used']} |
|
2016 | ||
2017 | ||
2018 |
def test_api_register_mark_as_deleted(app, settings, admin): |
|
2019 |
settings.A2_EMAIL_IS_UNIQUE = True |
|
2020 | ||
2021 |
user = User.objects.create(username='foo', email='john.doe@example.com', ou=get_default_ou()) |
|
2022 | ||
2023 |
headers = basic_authorization_header(admin) |
|
2024 |
payload = { |
|
2025 |
'username': 'john.doe', |
|
2026 |
'email': 'john.doe@example.com', |
|
2027 |
'first_name': 'John', |
|
2028 |
'last_name': 'Doe', |
|
2029 |
'password': '12XYab', |
|
2030 |
'no_email_validation': True, |
|
2031 |
'return_url': 'http://sp.example.com/validate/', |
|
2032 |
'ou': 'default', |
|
2033 |
} |
|
2034 |
response = app.post_json( |
|
2035 |
reverse('a2-api-register'), params=payload, headers=headers, status=400) |
|
2036 |
assert response.json['errors'] == {'__all__': ['You already have an account']} |
|
2037 | ||
2038 |
user.mark_as_deleted() |
|
2039 |
response = app.post_json( |
|
2040 |
reverse('a2-api-register'), params=payload, headers=headers, status=201) |
|
2041 | ||
2042 | ||
2043 |
def test_api_password_change_mark_as_deleted(app, settings, admin, ou1): |
|
2044 |
app.authorization = ('Basic', (admin.username, admin.username)) |
|
2045 |
user1 = User.objects.create( |
|
2046 |
username='john.doe', email='john.doe@example.com', ou=ou1) |
|
2047 |
user1.set_password('password') |
|
2048 |
user1.save() |
|
2049 |
user2 = User.objects.create( |
|
2050 |
username='john.doe2', email='john.doe@example.com', ou=ou1) |
|
2051 |
user2.set_password('password') |
|
2052 |
user1.save() |
|
2053 | ||
2054 |
payload = { |
|
2055 |
'email': 'john.doe@example.com', |
|
2056 |
'ou': ou1.slug, |
|
2057 |
'old_password': 'password', |
|
2058 |
'new_password': 'password2', |
|
2059 |
} |
|
2060 |
url = reverse('a2-api-password-change') |
|
2061 |
response = app.post_json(url, params=payload, status=400) |
|
2062 |
user2.mark_as_deleted() |
|
2063 |
response = app.post_json(url, params=payload) |
|
2064 |
assert User.objects.get(username='john.doe').check_password('password2') |
tests/test_custom_user.py | ||
---|---|---|
58 | 58 |
self.assertIn(r.id, [rparent1.id, rparent2.id]) |
59 | 59 |
self.assertEqual(r.member, []) |
60 | 60 | |
61 |
def test_user_mark_as_deleted(self): |
|
62 |
user1 = User.objects.create(username='foo', email='foo@example.net') |
|
63 |
user1.mark_as_deleted() |
|
64 |
user2 = User.objects.create(username='foo2', email='foo@example.net') |
|
65 |
assert len(User.objects.filter(email='foo@example.net')) == 2 |
|
66 |
assert len(User.objects.filter( |
|
67 |
email='foo@example.net', deleted__isnull=True)) == 1 |
tests/test_manager.py | ||
---|---|---|
266 | 266 |
assert User.objects.filter(ou=ou2).count() == 1 |
267 | 267 |
assert 'This email address is already in use.' in response |
268 | 268 | |
269 |
# first user with john.doe@gmail.com/ou2 marked as deleted |
|
270 |
john = User.objects.get(email='john.doe@gmail.com', ou=ou2) |
|
271 |
john.mark_as_deleted() |
|
272 |
john.save() |
|
273 |
ou_add = app.get(url) |
|
274 |
form = ou_add.form |
|
275 |
form.set('first_name', 'John') |
|
276 |
form.set('last_name', 'Doe') |
|
277 |
form.set('email', 'john.doe@gmail.com') |
|
278 |
form.set('password1', 'ABcd1234') |
|
279 |
form.set('password2', 'ABcd1234') |
|
280 |
response = form.submit() |
|
281 |
assert User.objects.filter(ou=ou2).count() == 2 |
|
282 |
assert User.objects.filter(ou=ou2, deleted__isnull=True).count() == 1 |
|
283 | ||
269 | 284 |
# create first user with john.doe2@gmail.com ou OU2 : OK |
270 | 285 |
ou_add = app.get(url) |
271 | 286 |
form = ou_add.form |
... | ... | |
275 | 290 |
form.set('password1', 'ABcd1234') |
276 | 291 |
form.set('password2', 'ABcd1234') |
277 | 292 |
response = form.submit().follow() |
278 |
assert User.objects.filter(ou=ou2).count() == 2 |
|
293 |
assert User.objects.filter(ou=ou2, deleted__isnull=True).count() == 2
|
|
279 | 294 | |
280 | 295 |
# try to change user email from john.doe2@gmail.com to |
281 | 296 |
# john.doe@gmail.com in OU2 : NOK |
tests/test_user_manager.py | ||
---|---|---|
270 | 270 |
# now we see only simple_user |
271 | 271 |
assert visible_users(response) == {simple_user.username} |
272 | 272 | |
273 |
simple_user.mark_as_deleted() |
|
274 |
response.form['search-text'] = 'avenue' |
|
275 |
response = response.form.submit() |
|
276 | ||
277 |
assert visible_users(response) == set() |
|
278 | ||
273 | 279 | |
274 | 280 |
def test_export_csv(settings, app, superuser, django_assert_num_queries): |
275 | 281 |
AT_COUNT = 30 |
... | ... | |
328 | 334 |
assert len(line) == num_col |
329 | 335 | |
330 | 336 | |
337 |
def test_export_csv_mark_as_deleted(settings, app, superuser): |
|
338 |
for i in range(10): |
|
339 |
User.objects.create(username='user-%s' % i) |
|
340 | ||
341 |
# users marked as deleted should not show up |
|
342 |
for user in User.objects.all()[0:3]: |
|
343 |
user.mark_as_deleted() |
|
344 | ||
345 |
response = login(app, superuser, reverse('a2-manager-users')) |
|
346 |
settings.A2_CACHE_ENABLED = True |
|
347 |
response = response.click('CSV') |
|
348 |
table = list(csv.reader(response.text.splitlines())) |
|
349 |
# superuser + ten created users + csv header - three users marked as deteled |
|
350 |
assert len(table) == (1 + 10 + 1 - 3) |
|
351 | ||
352 | ||
331 | 353 |
def test_user_table(app, admin, user_ou1, ou1): |
332 | 354 |
from authentic2.manager.utils import has_show_username |
333 | 355 | |
... | ... | |
367 | 389 |
def test_user_import(encoding, transactional_db, app, admin, ou1, admin_ou1): |
368 | 390 |
Attribute.objects.create(name='phone', kind='phone_number', label='Numéro de téléphone') |
369 | 391 | |
392 |
deleted_user = User.objects.create( |
|
393 |
email='john.doe@entrouvert.com', username='jdoe', |
|
394 |
first_name='John', last_name='doe') |
|
395 |
deleted_user.mark_as_deleted() |
|
396 | ||
370 | 397 |
user_count = User.objects.count() |
371 | 398 | |
372 | 399 |
assert Attribute.objects.count() == 3 |
... | ... | |
377 | 404 |
response.form.set('import_file', |
378 | 405 |
Upload( |
379 | 406 |
'users.csv', |
380 |
u'''email key verified,first_name,last_name,phone
|
|
407 |
'''email key verified,first_name,last_name,phone |
|
381 | 408 |
tnoel@entrouvert.com,Thomas,Noël,1234 |
382 | 409 |
fpeters@entrouvert.com,Frédéric,Péters,5678 |
410 |
john.doe@entrouvert.com,John,Doe,9101112 |
|
383 | 411 |
x,x,x,x'''.encode(encoding), |
384 | 412 |
'application/octet-stream')) |
385 | 413 |
response.form.set('encoding', encoding) |
... | ... | |
425 | 453 | |
426 | 454 |
response = response.click(href=simulate.uuid) |
427 | 455 | |
428 |
assert len(response.pyquery('table.main tbody tr')) == 4
|
|
429 |
assert len(response.pyquery('table.main tbody tr.row-valid')) == 2
|
|
456 |
assert len(response.pyquery('table.main tbody tr')) == 5
|
|
457 |
assert len(response.pyquery('table.main tbody tr.row-valid')) == 3
|
|
430 | 458 |
assert len(response.pyquery('table.main tbody tr.row-invalid')) == 2 |
431 | 459 | |
432 | 460 |
assert len(response.pyquery('tr.row-errors')) == 0 |
... | ... | |
446 | 474 |
response = response.follow() |
447 | 475 |
response = assert_timeout(2, wait_finished) |
448 | 476 | |
449 |
assert User.objects.count() == user_count + 2
|
|
477 |
assert User.objects.count() == user_count + 3
|
|
450 | 478 |
assert User.objects.filter( |
451 | 479 |
email='tnoel@entrouvert.com', |
452 |
first_name=u'Thomas',
|
|
453 |
last_name=u'Noël',
|
|
480 |
first_name='Thomas', |
|
481 |
last_name='Noël', |
|
454 | 482 |
attribute_values__content='1234').count() == 1 |
455 | 483 |
assert User.objects.filter( |
456 | 484 |
email='fpeters@entrouvert.com', |
457 |
first_name=u'Frédéric',
|
|
458 |
last_name=u'Péters',
|
|
485 |
first_name='Frédéric', |
|
486 |
last_name='Péters', |
|
459 | 487 |
attribute_values__content='5678').count() == 1 |
488 |
assert User.objects.filter( |
|
489 |
email='john.doe@entrouvert.com', |
|
490 |
first_name='John', |
|
491 |
last_name='Doe', |
|
492 |
attribute_values__content='9101112').count() == 1 |
|
460 | 493 | |
461 | 494 |
# logout |
462 | 495 |
app.session.flush() |
... | ... | |
590 | 623 |
app.get(url, status=404) |
591 | 624 | |
592 | 625 | |
626 |
def test_user_table_mark_as_deleted(app, admin, user_ou1, ou1): |
|
627 |
response = login(app, admin, '/manage/users/') |
|
628 |
assert len(response.pyquery('table.main tbody tr')) == 2 |
|
629 |
user_ou1.mark_as_deleted() |
|
630 |
response = app.get('/manage/users/') |
|
631 |
assert len(response.pyquery('table.main tbody tr')) == 1 |
|
632 | ||
633 | ||
593 | 634 |
def test_user_import_row_error_display(transactional_db, app, admin): |
594 | 635 |
User.objects.create(first_name='Elliott', last_name='1', ou=get_default_ou()) |
595 | 636 |
User.objects.create(first_name='Elliott', last_name='2', ou=get_default_ou()) |
tests/test_views.py | ||
---|---|---|
72 | 72 |
simple_user.refresh_from_db() |
73 | 73 |
assert not simple_user.is_active |
74 | 74 |
assert simple_user.deleted |
75 |
assert simple_user.email != email |
|
75 |
# no de-activation suffix on the address anymore: |
|
76 |
assert simple_user.email == email |
|
76 | 77 |
assert len(mailoutbox) == 2 |
77 | 78 |
assert 'Account deletion on testserver' == mailoutbox[1].subject |
78 | 79 |
assert mailoutbox[0].to == [email] |
79 |
- |