0001-models-order-AttributeValue-according-to-correspondi.patch
src/authentic2/models.py | ||
---|---|---|
336 | 336 | |
337 | 337 |
class Meta: |
338 | 338 |
verbose_name = _('attribute value') |
339 |
ordering = ('attribute__order', 'id') |
|
339 | 340 |
verbose_name_plural = _('attribute values') |
340 | 341 |
unique_together = ( |
341 | 342 |
('content_type', 'object_id', 'attribute', 'multiple', 'content'), |
tests/test_user_model.py | ||
---|---|---|
16 | 16 |
# authentic2 |
17 | 17 | |
18 | 18 |
import pytest |
19 |
import datetime |
|
19 | 20 | |
20 | 21 |
from django.core.exceptions import ValidationError |
21 | 22 |
from django.core import management |
... | ... | |
215 | 216 |
assert not hasattr(user.verified_attributes, 'email') |
216 | 217 |
assert hasattr(user.verified_attributes, 'first_name') |
217 | 218 |
assert user.verified_attributes.last_name is None |
219 | ||
220 | ||
221 |
def test_attribute_values_order(db): |
|
222 |
phone = Attribute.objects.create(name='phone', label='phone', kind='string', order=9) |
|
223 |
birthdate = Attribute.objects.create(name='birthdate', label='birthdate', kind='birthdate', order=10) |
|
224 |
user = User.objects.create(first_name='john', last_name='Doe') |
|
225 |
user.attributes.phone = '0123456789' |
|
226 |
user.attributes.birthdate = datetime.date(year=1980, month=1, day=2) |
|
227 | ||
228 |
attribute_values = user.attribute_values.all().reverse() |
|
229 |
val1, val2 = attribute_values[:2] |
|
230 |
assert val1.attribute.label == 'birthdate' |
|
231 |
assert val2.attribute.label == 'phone' |
|
232 | ||
233 |
phone.order, birthdate.order = birthdate.order, phone.order |
|
234 |
phone.save() |
|
235 |
birthdate.save() |
|
236 |
val1, val2 = attribute_values[:2] |
|
237 |
assert val1.attribute.label == 'phone' |
|
238 |
assert val2.attribute.label == 'birthdate' |
|
218 |
- |