Code Duplication    Length = 14-17 lines in 4 locations

tests/pipelines/test_password_reset_confirm.py 1 location

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

tests/pipelines/test_username_update.py 1 location

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

tests/pipelines/test_password_update.py 1 location

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

tests/pipelines/test_password_reset.py 1 location

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