Passed
Pull Request — master (#259)
by Piotr
01:48
created

test_invalid_serialize_request_wrong_password()   A

Complexity

Conditions 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
1
import pytest
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
introduced by
Unable to import 'pytest'
Loading history...
2
3
from django.contrib.auth import get_user_model
0 ignored issues
show
introduced by
Unable to import 'django.contrib.auth'
Loading history...
4
5
from djoser import exceptions, pipelines, signals
6
from tests.common import catch_signal, mock
7
8
User = get_user_model()
0 ignored issues
show
Coding Style Naming introduced by
The name User does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
9
10
11 View Code Duplication
@pytest.mark.django_db(transaction=False)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
def test_valid_serialize_request(test_user):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
13
    request = mock.MagicMock()
14
    request.data = {'current_password': 'testing123'}
15
    request.user = test_user
16
    context = {'request': request}
17
    result = pipelines.user_delete.serialize_request(**context)
18
19
    assert User.objects.count() == 1
20
    assert result['serializer'].context['request'].user == test_user
21
22
23
@pytest.mark.django_db(transaction=False)
24
def test_invalid_serialize_request_wrong_password(test_user):
0 ignored issues
show
Coding Style Naming introduced by
The name test_invalid_serialize_request_wrong_password does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
25
    request = mock.MagicMock()
26
    request.data = {'current_password': 'lolwut'}
27
    request.user = test_user
28
    context = {'request': request}
29
30
    with pytest.raises(exceptions.ValidationError) as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
31
        pipelines.user_delete.serialize_request(**context)
32
33
    assert e.value.errors == {'current_password': ['Invalid password.']}
34
35
36
@pytest.mark.django_db(transaction=False)
37
def test_valid_perform(test_user):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
38
    request = mock.MagicMock()
39
    request.user = test_user
40
    context = {'request': request}
41
    result = pipelines.user_delete.perform(**context)
42
43
    assert User.objects.count() == 0
44
    assert 'user' in result
45
    assert result['user'].username == test_user.username
46
    assert result['user'].email == test_user.email
47
48
49
def test_valid_signal(test_user):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
50
    request = mock.MagicMock()
51
    context = {'request': request, 'user': test_user}
52
53
    with catch_signal(signals.user_deleted) as handler:
54
        pipelines.user_delete.signal(**context)
55
56
    handler.assert_called_once_with(
57
        sender=mock.ANY,
58
        signal=signals.user_deleted,
59
        user=test_user,
60
        request=request
61
    )
62
63 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
64
@pytest.mark.django_db(transaction=False)
65
def test_valid_pipeline(test_user):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
66
    request = mock.MagicMock()
67
    request.data = {'current_password': 'testing123'}
68
    request.user = test_user
69
70
    pipeline = pipelines.user_delete.Pipeline(request)
71
    with catch_signal(signals.user_deleted) as handler:
72
        result = pipeline.run()
73
74
    handler.assert_called_once_with(
75
        sender=mock.ANY,
76
        signal=signals.user_deleted,
77
        user=result['user'],
78
        request=request
79
    )
80
81
    assert not User.objects.exists()
82