Code Duplication    Length = 13-17 lines in 3 locations

tests/pipelines/test_username_update.py 2 locations

@@ 65-81 (lines=17) @@
62
    assert 'Enter a valid username.' in e.value.errors['username'][0]
63
64
65
@pytest.mark.django_db(transaction=False)
66
@override_settings(
67
    DJOSER=dict(settings.DJOSER, **{'SET_USERNAME_RETYPE': True})
68
)
69
def test_invalid_serialize_request_username_retype_mismatch(test_user):
70
    request = mock.MagicMock()
71
    request.user = test_user
72
    request.data = {
73
        User.USERNAME_FIELD: 'new_username',
74
        're_' + User.USERNAME_FIELD: 'spanish_inquisition',
75
        'current_password': 'testing123',
76
    }
77
    context = {'request': request}
78
    with pytest.raises(exceptions.ValidationError) as e:
79
        pipelines.username_update.serialize_request(request, context)
80
81
    assert e.value.errors == {
82
        'non_field_errors': ["The two username fields didn't match."]
83
    }
84
@@ 31-43 (lines=13) @@
28
    }
29
30
31
@pytest.mark.django_db(transaction=False)
32
def test_invalid_serialize_request_same_username(test_user):
33
    request = mock.MagicMock()
34
    request.user = test_user
35
    request.data = {
36
        User.USERNAME_FIELD: getattr(test_user, User.USERNAME_FIELD),
37
        'current_password': 'testing123',
38
    }
39
    context = {'request': request}
40
    with pytest.raises(exceptions.ValidationError) as e:
41
        pipelines.username_update.serialize_request(request, context)
42
43
    assert e.value.errors == {
44
        'username': ['A user with that username already exists.']
45
    }
46

tests/pipelines/test_password_update.py 1 location

@@ 44-60 (lines=17) @@
41
    }
42
43
44
@pytest.mark.django_db(transaction=False)
45
@override_settings(
46
    DJOSER=dict(settings.DJOSER, **{'SET_PASSWORD_RETYPE': True})
47
)
48
def test_invalid_serialize_request_password_retype_mismatch(test_user):
49
    request = mock.MagicMock()
50
    request.data = {
51
        'current_password': 'testing123',
52
        'new_password': 'newpass123',
53
        're_new_password': 'wrong-password',
54
    }
55
    request.user = test_user
56
    context = {'request': request}
57
    with pytest.raises(exceptions.ValidationError) as e:
58
        pipelines.password_update.serialize_request(request, context)
59
60
    assert e.value.errors == {
61
        'non_field_errors': ["The two password fields didn't match."]
62
    }
63