Code Duplication    Length = 14-21 lines in 4 locations

tests/pipelines/test_password_reset.py 1 location

@@ 35-48 (lines=14) @@
32
33
    assert 'serializer' in result
34
35
36
@pytest.mark.django_db(transaction=False)
37
def test_invalid_serialize_request_email_show_not_found(settings):
38
    settings.DJOSER = dict(
39
        settings.DJOSER, **{'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': True}
40
    )
41
    request = mock.MagicMock()
42
    request.data = {
43
        'email': '[email protected]',
44
    }
45
    context = {'request': request}
46
    with pytest.raises(exceptions.ValidationError) as e:
47
        pipelines.password_reset.serialize_request(**context)
48
49
    assert e.value.errors == {
50
        'email': ['User with given email does not exist.']
51
    }

tests/pipelines/test_username_update.py 1 location

@@ 64-84 (lines=21) @@
61
    assert 'Enter a valid username.' in e.value.errors['username'][0]
62
63
64
@pytest.mark.django_db(transaction=False)
65
def test_invalid_serialize_request_retype_mismatch(settings, test_user):
66
    settings.DJOSER = dict(settings.DJOSER, **{
67
        'SERIALIZERS': {
68
            'username_update':
69
                'djoser.serializers.UsernameUpdateRetypeSerializer'
70
        }
71
    })
72
73
    request = mock.MagicMock()
74
    request.user = test_user
75
    request.data = {
76
        User.USERNAME_FIELD: 'new_username',
77
        're_' + User.USERNAME_FIELD: 'spanish_inquisition',
78
        'current_password': 'testing123',
79
    }
80
    context = {'request': request}
81
    with pytest.raises(exceptions.ValidationError) as e:
82
        pipelines.username_update.serialize_request(**context)
83
84
    assert e.value.errors == {
85
        'non_field_errors': ["The two username fields didn't match."]
86
    }
87

tests/pipelines/test_password_update.py 1 location

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

tests/pipelines/test_password_reset_confirm.py 1 location

@@ 83-102 (lines=20) @@
80
    }
81
82
83
@pytest.mark.django_db(transaction=False)
84
def test_invalid_serialize_request_retype_mismatch(settings, test_user):
85
    settings.DJOSER = dict(settings.DJOSER, **{
86
        'SERIALIZERS': {
87
            'password_reset_confirm':
88
                'djoser.serializers.PasswordResetConfirmRetypeSerializer'
89
        }
90
    })
91
92
    request = mock.MagicMock()
93
    request.data = {
94
        'uid': utils.encode_uid(test_user.pk),
95
        'token': default_token_generator.make_token(test_user),
96
        'new_password': 'whatever-123',
97
        're_new_password': 'meh',
98
    }
99
    context = {'request': request}
100
    with pytest.raises(exceptions.ValidationError) as e:
101
        pipelines.password_reset_confirm.serialize_request(**context)
102
    assert e.value.errors == {
103
        'non_field_errors': [constants.PASSWORD_MISMATCH_ERROR]
104
    }
105