1626 |
1626 |
'first_name': 'Johnny',
|
1627 |
1627 |
}
|
1628 |
1628 |
headers = basic_authorization_header(admin)
|
1629 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1630 |
|
params=payload, headers=headers, status=400)
|
|
1629 |
|
|
1630 |
# create fails
|
|
1631 |
resp = app.post_json('/api/users/', params=payload, headers=headers, status=400)
|
1631 |
1632 |
assert resp.json['result'] == 0
|
1632 |
1633 |
assert resp.json['errors']['last_name'] == ['This field is required.']
|
1633 |
1634 |
|
|
1635 |
# update from missing value to blank field fails
|
1634 |
1636 |
payload['last_name'] = ''
|
1635 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1636 |
|
params=payload, headers=headers, status=400)
|
|
1637 |
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=400)
|
1637 |
1638 |
assert resp.json['result'] == 0
|
1638 |
1639 |
assert resp.json['errors']['last_name'] == ['This field may not be blank.']
|
1639 |
1640 |
|
|
1641 |
# update with value pass
|
1640 |
1642 |
payload['last_name'] = 'Foobar'
|
1641 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1642 |
|
params=payload, headers=headers, status=200)
|
|
1643 |
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=200)
|
1643 |
1644 |
user = User.objects.get(id=simple_user.id)
|
1644 |
1645 |
assert user.last_name == 'Foobar'
|
1645 |
1646 |
|
|
1647 |
# update from non-empty value to blank fails
|
1646 |
1648 |
payload['last_name'] = ''
|
1647 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1648 |
|
params=payload, headers=headers, status=400)
|
|
1649 |
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=400)
|
1649 |
1650 |
assert resp.json['result'] == 0
|
1650 |
1651 |
assert resp.json['errors']['last_name'] == ['This field may not be blank.']
|
1651 |
1652 |
|
1652 |
1653 |
|
1653 |
|
def test_api_user_required_drf_attribute(settings, app, admin, simple_user):
|
1654 |
|
Attribute.objects.create(kind='birthdate', name='birthdate', label='birthdate', required=True)
|
1655 |
|
Attribute.objects.create(kind='string', name='prefered_color', label='prefered color', required=True)
|
1656 |
|
Attribute.objects.get(name='birthdate').required is True
|
1657 |
|
Attribute.objects.get(name='prefered_color').required is True
|
1658 |
|
|
1659 |
|
payload = {
|
1660 |
|
'username': simple_user.username,
|
1661 |
|
'id': simple_user.id,
|
1662 |
|
'email': 'john.doe@nowhere.null',
|
1663 |
|
'first_name': 'Johnny',
|
1664 |
|
'last_name': 'Doe',
|
1665 |
|
}
|
1666 |
|
headers = basic_authorization_header(admin)
|
1667 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1668 |
|
params=payload, headers=headers, status=400)
|
1669 |
|
assert resp.json['result'] == 0
|
1670 |
|
assert resp.json['errors'] == {
|
1671 |
|
'birthdate': ['This field is required.'],
|
1672 |
|
'prefered_color': ['This field is required.'],
|
1673 |
|
}
|
1674 |
|
|
1675 |
|
payload['birthdate'] = '2019-02-02'
|
1676 |
|
payload['prefered_color'] = ''
|
1677 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1678 |
|
params=payload, headers=headers, status=400)
|
1679 |
|
assert resp.json['result'] == 0
|
1680 |
|
assert resp.json['errors'] == {'prefered_color': ["This field may not be blank."]}
|
1681 |
|
|
1682 |
|
Attribute.objects.filter(name='prefered_color').update(required=False)
|
1683 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=200)
|
1684 |
|
|
1685 |
|
|
1686 |
1654 |
def test_api_users_required_date_attributes(settings, app, admin, simple_user):
|
1687 |
1655 |
Attribute.objects.create(kind='string', name='prefered_color', label='prefered color', required=True)
|
1688 |
1656 |
Attribute.objects.create(kind='date', name='date', label='date', required=True)
|
... | ... | |
1696 |
1664 |
'last_name': 'Doe',
|
1697 |
1665 |
}
|
1698 |
1666 |
headers = basic_authorization_header(admin)
|
1699 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1700 |
|
params=payload, headers=headers, status=400)
|
|
1667 |
|
|
1668 |
# create fails
|
|
1669 |
resp = app.post_json('/api/users/', params=payload, headers=headers, status=400)
|
1701 |
1670 |
assert resp.json['result'] == 0
|
1702 |
1671 |
assert resp.json['errors']['prefered_color'] == ['This field is required.']
|
1703 |
1672 |
assert resp.json['errors']['date'] == ['This field is required.']
|
1704 |
1673 |
assert resp.json['errors']['birthdate'] == ['This field is required.']
|
1705 |
1674 |
|
|
1675 |
# update from missing value to blank fails
|
1706 |
1676 |
payload['prefered_color'] = ''
|
1707 |
1677 |
payload['date'] = ''
|
1708 |
1678 |
payload['birthdate'] = ''
|
1709 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1710 |
|
params=payload, headers=headers, status=400)
|
|
1679 |
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=400)
|
1711 |
1680 |
assert resp.json['result'] == 0
|
1712 |
1681 |
assert resp.json['errors']['prefered_color'] == ['This field may not be blank.']
|
1713 |
1682 |
assert resp.json['errors']['date'] == ['This field may not be blank.']
|
1714 |
1683 |
assert resp.json['errors']['birthdate'] == ['This field may not be blank.']
|
1715 |
1684 |
|
1716 |
|
payload['prefered_color'] = '?'*257
|
|
1685 |
# update with invalid values fails
|
|
1686 |
payload['prefered_color'] = '?' * 257
|
1717 |
1687 |
payload['date'] = '0000-00-00'
|
1718 |
1688 |
payload['birthdate'] = '1899-12-31'
|
1719 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1720 |
|
params=payload, headers=headers, status=400)
|
|
1689 |
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=400)
|
1721 |
1690 |
assert resp.json['result'] == 0
|
1722 |
1691 |
assert resp.json['errors']['prefered_color'] == ['Ensure this field has no more than 256 characters.']
|
1723 |
1692 |
assert any(error.startswith('Date has wrong format.') for error in resp.json['errors']['date'])
|
1724 |
1693 |
assert resp.json['errors']['birthdate'] == ['birthdate must be in the past and greater or equal than 1900-01-01.']
|
1725 |
1694 |
|
|
1695 |
# update with values pass
|
1726 |
1696 |
payload['prefered_color'] = 'blue'
|
1727 |
1697 |
payload['date'] = '1515-1-15'
|
1728 |
1698 |
payload['birthdate'] = '1900-2-22'
|
1729 |
|
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid),
|
1730 |
|
params=payload, headers=headers, status=200)
|
1731 |
|
resp = app.get('/api/users/{}/'.format(simple_user.uuid),
|
1732 |
|
headers=headers, status=200)
|
|
1699 |
resp = app.put_json('/api/users/{}/'.format(simple_user.uuid), params=payload, headers=headers, status=200)
|
|
1700 |
|
|
1701 |
# value are properly returned on a get
|
|
1702 |
resp = app.get('/api/users/{}/'.format(simple_user.uuid), headers=headers, status=200)
|
1733 |
1703 |
assert resp.json['prefered_color'] == 'blue'
|
1734 |
1704 |
assert resp.json['date'] == '1515-01-15'
|
1735 |
1705 |
assert resp.json['birthdate'] == '1900-02-22'
|
... | ... | |
2225 |
2195 |
headers = basic_authorization_header(admin)
|
2226 |
2196 |
expected_status = 200 if drf_version > '3.9' else 404
|
2227 |
2197 |
resp = app.get('/api/statistics/login/?time_interval=month', headers=headers, status=expected_status)
|
|
2198 |
|
|
2199 |
|
|
2200 |
def test_find_duplicates_put(app, admin, settings):
|
|
2201 |
app.authorization = ('Basic', (admin.username, admin.username))
|
|
2202 |
app.put_json('/api/users/find_duplicates/', params={'first_name': 'Eleonore', 'last_name': 'aeiou'}, status=405)
|
2228 |
|
-
|