Completed
Push — master ( aa58e4...09baaa )
by Piotr
05:40
created

TokenCreateViewTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 81
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_post_should_not_login_if_invalid_credentials() 0 17 1
A setUp() 0 2 1
A signal_receiver() 0 2 1
A test_post_should_login_user() 0 14 1
A test_post_should_not_login_if_empty_request() 0 10 1
B test_post_should_not_login_if_user_is_not_active() 0 26 2
1
from django.contrib.auth import user_logged_in, user_login_failed
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 'django.contrib.auth'
Loading history...
2
from djet import assertions, restframework
0 ignored issues
show
introduced by
Unable to import 'djet'
Loading history...
3
from rest_framework import status
0 ignored issues
show
introduced by
Unable to import 'rest_framework'
Loading history...
4
import django
0 ignored issues
show
introduced by
Unable to import 'django'
Loading history...
introduced by
Imports from package django are not grouped
Loading history...
5
import djoser.constants
6
import djoser.utils
7
import djoser.views
8
9
from .common import create_user
10
11
12
class TokenCreateViewTest(restframework.APIViewTestCase,
0 ignored issues
show
Coding Style introduced by
This class 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
                          assertions.StatusCodeAssertionsMixin,
14
                          assertions.InstanceAssertionsMixin):
15
    view_class = djoser.views.TokenCreateView
16
17
    def setUp(self):
0 ignored issues
show
Coding Style Naming introduced by
The name setUp does not conform to the method 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 method 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...
18
        self.signal_sent = False
19
20
    def signal_receiver(self, *args, **kwargs):
0 ignored issues
show
Coding Style introduced by
This method 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...
Unused Code introduced by
The argument args seems to be unused.
Loading history...
Unused Code introduced by
The argument kwargs seems to be unused.
Loading history...
21
        self.signal_sent = True
22
23
    def test_post_should_login_user(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
24
        user = create_user()
25
        data = {
26
            'username': user.username,
27
            'password': user.raw_password,
28
        }
29
        user_logged_in.connect(self.signal_receiver)
30
        request = self.factory.post(data=data)
31
32
        response = self.view(request)
33
34
        self.assert_status_equal(response, status.HTTP_200_OK)
35
        self.assertEqual(response.data['auth_token'], user.auth_token.key)
36
        self.assertTrue(self.signal_sent)
37
38
    def test_post_should_not_login_if_user_is_not_active(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_should_not_login_if_user_is_not_active does not conform to the method 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...
39
        """
40
        In Django >= 1.10 authenticate() returns None if
41
        user is inactive, while in Django < 1.10 authenticate()
42
        succeeds if user is inactive.
43
        """
44
        user = create_user()
45
        data = {
46
            'username': user.username,
47
            'password': user.raw_password,
48
        }
49
        user.is_active = False
50
        user.save()
51
        user_logged_in.connect(self.signal_receiver)
52
        request = self.factory.post(data=data)
53
54
        response = self.view(request)
55
56
        if django.VERSION >= (1, 10):
57
            expected_errors = [djoser.constants.INVALID_CREDENTIALS_ERROR]
58
        else:
59
            expected_errors = [djoser.constants.INACTIVE_ACCOUNT_ERROR]
60
61
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
62
        self.assertEqual(response.data['non_field_errors'], expected_errors)
63
        self.assertFalse(self.signal_sent)
64
65
    def test_post_should_not_login_if_invalid_credentials(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_should_not_login_if_invalid_credentials does not conform to the method 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 method 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
        user = create_user()
67
        data = {
68
            'username': user.username,
69
            'password': 'wrong',
70
        }
71
        user_login_failed.connect(self.signal_receiver)
72
        request = self.factory.post(data=data)
73
74
        response = self.view(request)
75
76
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
77
        self.assertEqual(
78
            response.data['non_field_errors'],
79
            [djoser.constants.INVALID_CREDENTIALS_ERROR]
80
        )
81
        self.assertTrue(self.signal_sent)
82
83
    def test_post_should_not_login_if_empty_request(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_should_not_login_if_empty_request does not conform to the method 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 method 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...
84
        data = {}
85
        request = self.factory.post(data=data)
86
87
        response = self.view(request)
88
89
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
90
        self.assertEqual(
91
            response.data['non_field_errors'],
92
            [djoser.constants.INVALID_CREDENTIALS_ERROR]
93
        )
94