0001-api-allow-changing-profile-image-52949.patch
src/authentic2/attribute_kinds.py | ||
---|---|---|
322 | 322 |
'field_class': fields.ProfileImageField, |
323 | 323 |
'serialize': profile_image_serialize, |
324 | 324 |
'deserialize': profile_image_deserialize, |
325 |
'rest_framework_field_class': serializers.FileField,
|
|
325 |
'rest_framework_field_class': serializers.ImageField,
|
|
326 | 326 |
'rest_framework_field_kwargs': { |
327 |
'read_only': True, |
|
328 | 327 |
'use_url': True, |
328 |
'allow_empty_file': True, |
|
329 |
'_DjangoImageField': fields.ProfileImageField, |
|
329 | 330 |
}, |
330 | 331 |
'html_value': profile_image_html_value, |
331 | 332 |
'attributes_ng_serialize': profile_attributes_ng_serialize, |
tests/test_attribute_kinds.py | ||
---|---|---|
440 | 440 |
form = response.form |
441 | 441 |
assert form['cityscape_image'].attrs['accept'] == 'image/*' |
442 | 442 | |
443 |
# clear image using API |
|
444 |
response = app.put('/api/users/%s/' % john().uuid, params={'cityscape_image': ''}) |
|
445 |
assert john().attributes.cityscape_image == None |
|
446 | ||
447 |
# put back first image using API |
|
448 |
response = app.put( |
|
449 |
'/api/users/%s/' % john().uuid, params={'cityscape_image': Upload('tests/200x200.jpg')} |
|
450 |
) |
|
451 |
assert john().attributes.cityscape_image |
|
452 |
profile_filename = john().attributes.cityscape_image.name |
|
453 |
assert profile_filename.endswith('.jpeg') |
|
454 | ||
455 |
# verify 201x201 image is accepted and resized by API |
|
456 |
response = app.put( |
|
457 |
'/api/users/%s/' % john().uuid, params={'cityscape_image': Upload('tests/201x201.jpg')} |
|
458 |
) |
|
459 |
with PIL.Image.open(os.path.join(settings.MEDIA_ROOT, john().attributes.cityscape_image.name)) as image: |
|
460 |
assert image.width == 200 |
|
461 |
assert image.height == 200 |
|
462 |
assert john().attributes.cityscape_image.name != profile_filename |
|
463 | ||
443 | 464 | |
444 | 465 |
def test_multiple_attribute_setter(db, app, simple_user): |
445 | 466 |
nicks = Attribute.objects.create( |
446 |
- |