Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest
from funkwhale_api.users import serializers
@pytest.mark.parametrize(
"data, expected_error",
[
(
{
"username": "myusername",
"email": "test@hello.com",
"password1": "myusername",
},
r".*password is too similar.*",
),
(
{"username": "myusername", "email": "test@hello.com", "password1": "test"},
r".*must contain at least 8 characters.*",
),
(
{
"username": "myusername",
"email": "test@hello.com",
"password1": "superman",
},
r".*password is too common.*",
),
(
{
"username": "myusername",
"email": "test@hello.com",
"password1": "123457809878",
},
r".*password is entirely numeric.*",
),
],
)
def test_registration_serializer_validates_password_properly(data, expected_error, db):
data["password2"] = data["password1"]
serializer = serializers.RegisterSerializer(data=data)
with pytest.raises(serializers.serializers.ValidationError, match=expected_error):
serializer.is_valid(raise_exception=True)