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

test_invalid_perform_none_token_model()   A

Complexity

Conditions 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 0
loc 10
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 constants, 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
def test_valid_perform(test_user, settings):
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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    from djoser.conf import settings as djoser_settings
13
14
    settings.DJOSER = dict(
15
        settings.DJOSER,
16
        **{'TOKEN_MODEL': 'rest_framework.authtoken.models.Token'}
17
    )
18
19
    request = mock.MagicMock()
20
    request.user = test_user
21
    context = {'request': request}
22
23
    djoser_settings.TOKEN_MODEL.objects.get_or_create(user=test_user)
24
    assert djoser_settings.TOKEN_MODEL.objects.count() == 1
25
26
    result = pipelines.token_destroy.perform(**context)
27
    assert result['user'] == test_user
28
    assert djoser_settings.TOKEN_MODEL.objects.count() == 0
29
30
31
@pytest.mark.django_db(transaction=False)
32
def test_invalid_perform_none_token_model(test_user):
0 ignored issues
show
Coding Style Naming introduced by
The name test_invalid_perform_none_token_model 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...
33
    request = mock.MagicMock()
34
    request.user = test_user
35
    context = {'request': request}
36
37
    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...
38
        pipelines.token_destroy.perform(**context)
39
40
    assert e.value.errors == constants.TOKEN_MODEL_NONE_ERROR
41
42
43
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...
44
    request = mock.MagicMock()
45
    context = {'request': request, 'user': test_user}
46
47
    with catch_signal(signals.token_destroyed) as handler:
48
        pipelines.token_destroy.signal(**context)
49
50
    handler.assert_called_once_with(
51
        sender=mock.ANY,
52
        signal=signals.token_destroyed,
53
        user=test_user,
54
        request=request
55
    )
56
57
58 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...
59
def test_valid_pipeline(test_user, settings):
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...
60
    from djoser.conf import settings as djoser_settings
61
62
    settings.DJOSER = dict(
63
        settings.DJOSER,
64
        **{'TOKEN_MODEL': 'rest_framework.authtoken.models.Token'}
65
    )
66
67
    request = mock.MagicMock()
68
    request.user = test_user
69
70
    djoser_settings.TOKEN_MODEL.objects.get_or_create(user=test_user)
71
    assert djoser_settings.TOKEN_MODEL.objects.count() == 1
72
73
    pipeline = pipelines.token_destroy.Pipeline(request)
74
    with catch_signal(signals.token_destroyed) as handler:
75
        result = pipeline.run()
76
77
    handler.assert_called_once_with(
78
        sender=mock.ANY,
79
        signal=signals.token_destroyed,
80
        user=result['user'],
81
        request=request
82
    )
83
84
    assert result['user'] == test_user
85
    assert djoser_settings.TOKEN_MODEL.objects.count() == 0
86