352 |
352 |
new_app.get(su_url).maybe_follow()
|
353 |
353 |
assert new_app.session['_auth_user_id'] == str(simple_user.pk)
|
354 |
354 |
|
|
355 |
|
|
356 |
def import_csv(csv_content, app):
|
|
357 |
response = app.get('/manage/users/')
|
|
358 |
response = response.click('Import users')
|
|
359 |
index = [i for i in response.forms if 'import_file' in response.forms[i].fields][0]
|
|
360 |
response.forms[index].set(
|
|
361 |
'import_file',
|
|
362 |
Upload('users.csv', csv_content.encode('utf-8'), 'application/octet-stream'))
|
|
363 |
response.forms[index].set('encoding', 'utf-8')
|
|
364 |
response.forms[index].set('ou', str(get_default_ou().pk))
|
|
365 |
response = response.forms[index].submit().follow()
|
|
366 |
response = response.forms['action-form'].submit(name='execute').follow()
|
|
367 |
|
|
368 |
start = time.time()
|
|
369 |
response = response.click('Users Import')
|
|
370 |
while 'Running' in response.text:
|
|
371 |
response = response.click('Users Import')
|
|
372 |
assert time.time() - start < 2
|
|
373 |
time.sleep(.1)
|
|
374 |
|
|
375 |
# report
|
|
376 |
urls = re.findall('<a href="(/manage/users/import/[^/]+/[^/]+/)">', response.content)
|
|
377 |
response = app.get(urls[0])
|
|
378 |
return response
|
|
379 |
|
|
380 |
|
355 |
381 |
@skipif_sqlite
|
356 |
382 |
def test_user_import_attributes(transactional_db, app, admin, media):
|
357 |
383 |
Attribute.objects.create(name='more', kind='string', label='Signe particulier')
|
... | ... | |
365 |
391 |
user_count = User.objects.count()
|
366 |
392 |
login(app, admin, '/manage/users/')
|
367 |
393 |
|
368 |
|
def import_csv(csv_content):
|
369 |
|
response = app.get('/manage/users/')
|
370 |
|
response = response.click('Import users')
|
371 |
|
index = [i for i in response.forms if 'import_file' in response.forms[i].fields][0]
|
372 |
|
response.forms[index].set(
|
373 |
|
'import_file',
|
374 |
|
Upload('users.csv', csv_content.encode('utf-8'), 'application/octet-stream'))
|
375 |
|
response.forms[index].set('encoding', 'utf-8')
|
376 |
|
response.forms[index].set('ou', str(get_default_ou().pk))
|
377 |
|
response = response.forms[index].submit().follow()
|
378 |
|
response = response.forms['action-form'].submit(name='execute').follow()
|
379 |
|
|
380 |
|
start = time.time()
|
381 |
|
response = response.click('Users Import')
|
382 |
|
while 'Running' in response.text:
|
383 |
|
response = response.click('Users Import')
|
384 |
|
assert time.time() - start < 2
|
385 |
|
time.sleep(.1)
|
386 |
|
|
387 |
|
# report
|
388 |
|
urls = re.findall('<a href="(/manage/users/import/[^/]+/[^/]+/)">', response.content)
|
389 |
|
response = app.get(urls[0])
|
390 |
|
return response
|
391 |
394 |
|
392 |
395 |
csv_lines = [
|
393 |
396 |
u"email key verified,first_name,last_name,more,title,bike,saintsday,birthdate,zip,phone",
|
394 |
397 |
u"elliot@universalpictures.com,Elliott,Thomas,petit,Mr,True,2019-7-20,1972-05-26,75014,1234",
|
395 |
398 |
u"et@universalpictures.com,ET,the Extra-Terrestrial,long,??,False,1/2/3/4,0002-2-22,42,home"]
|
396 |
|
response = import_csv('\n'.join(csv_lines))
|
|
399 |
response = import_csv('\n'.join(csv_lines), app)
|
397 |
400 |
urls = re.findall('<a href="(/manage/users/import/[^/]+/[^/]+/)">', response.content)
|
398 |
401 |
response = app.get(urls[0])
|
399 |
402 |
assert 'Select a valid choice. ?? is not one of the available choices.' in response.content
|
... | ... | |
414 |
417 |
|
415 |
418 |
csv_lines[2] = \
|
416 |
419 |
u"et@universalpictures.com,ET,the Extra-Terrestrial,,,,,,42000,+888 5678"
|
417 |
|
response = import_csv('\n'.join(csv_lines))
|
|
420 |
response = import_csv('\n'.join(csv_lines), app)
|
418 |
421 |
assert '0 rows have errors' in response.content
|
419 |
422 |
|
420 |
423 |
assert User.objects.count() == user_count + 2
|
... | ... | |
426 |
429 |
assert 'birthdate' not in et.attributes.values
|
427 |
430 |
assert et.attributes.values['zip'].content == '42000'
|
428 |
431 |
assert et.attributes.values['phone'].content == '+8885678'
|
|
432 |
|
|
433 |
|
|
434 |
@skipif_sqlite
|
|
435 |
def test_user_import_row_error_display(transactional_db, app, admin, media):
|
|
436 |
User.objects.create(first_name='Elliott', last_name='1', ou=get_default_ou())
|
|
437 |
User.objects.create(first_name='Elliott', last_name='2', ou=get_default_ou())
|
|
438 |
content = '''first_name key,last_name update
|
|
439 |
Elliott,3'''
|
|
440 |
login(app, admin, '/manage/users/')
|
|
441 |
response = import_csv(content, app)
|
|
442 |
assert 'row-invalid' in response.content
|
429 |
|
-
|