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

UserCreateViewTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 108
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_post_not_create_new_user_if_username_exists() 0 12 1
A test_post_not_register_if_fails_password_validation() 0 14 1
A test_post_create_user_with_login_and_send_confirmation_email() 0 21 1
A test_post_create_user_with_login_and_send_activation_email() 0 19 1
A test_post_return_400_for_integrity_error() 0 15 1
A test_post_create_user_without_login() 0 15 1
1
from django.conf import settings
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.conf'
Loading history...
Bug introduced by
There seems to be a cyclic import (djoser.urls.base -> djoser.views).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
Bug introduced by
There seems to be a cyclic import (djoser.urls.authtoken -> djoser.views).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
2
from django.contrib.auth import get_user_model
0 ignored issues
show
introduced by
Unable to import 'django.contrib.auth'
Loading history...
3
from django.test.utils import override_settings
0 ignored issues
show
introduced by
Unable to import 'django.test.utils'
Loading history...
4
from djet import assertions, restframework
0 ignored issues
show
introduced by
Unable to import 'djet'
Loading history...
5
from rest_framework import status
0 ignored issues
show
introduced by
Unable to import 'rest_framework'
Loading history...
6
import djoser.constants
7
import djoser.utils
8
import djoser.views
9
10
from .common import create_user, mock, perform_create_mock
11
12
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...
13
14
15
class UserCreateViewTest(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...
16
                         assertions.StatusCodeAssertionsMixin,
17
                         assertions.EmailAssertionsMixin,
18
                         assertions.InstanceAssertionsMixin):
19
    view_class = djoser.views.UserCreateView
20
21
    def test_post_create_user_without_login(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_create_user_without_login 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...
22
        data = {
23
            'username': 'john',
24
            'password': 'secret',
25
            'csrftoken': 'asdf',
26
        }
27
        request = self.factory.post(data=data)
28
29
        response = self.view(request)
30
31
        self.assert_status_equal(response, status.HTTP_201_CREATED)
32
        self.assertTrue('password' not in response.data)
33
        self.assert_instance_exists(User, username=data['username'])
34
        user = User.objects.get(username=data['username'])
35
        self.assertTrue(user.check_password(data['password']))
36
37
    @override_settings(
38
        DJOSER=dict(settings.DJOSER, **{'SEND_ACTIVATION_EMAIL': True})
39
    )
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_create_user_wi...d_send_activation_email 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...
40
    def test_post_create_user_with_login_and_send_activation_email(self):
41
        data = {
42
            'username': 'john',
43
            'email': '[email protected]',
44
            'password': 'secret',
45
        }
46
        request = self.factory.post(data=data)
47
        response = self.view(request)
48
49
        self.assert_status_equal(response, status.HTTP_201_CREATED)
50
        self.assert_instance_exists(User, username=data['username'])
51
        self.assert_emails_in_mailbox(1)
52
        self.assert_email_exists(to=[data['email']])
53
54
        user = User.objects.get(username='john')
55
        self.assertFalse(user.is_active)
56
57
    @override_settings(
58
        DJOSER=dict(settings.DJOSER, **{
59
            'SEND_ACTIVATION_EMAIL': False, 'SEND_CONFIRMATION_EMAIL': True
60
        })
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_create_user_wi...send_confirmation_email 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...
61
    )
62
    def test_post_create_user_with_login_and_send_confirmation_email(self):
63
        data = {
64
            'username': 'john',
65
            'email': '[email protected]',
66
            'password': 'secret',
67
        }
68
        request = self.factory.post(data=data)
69
        response = self.view(request)
70
71
        self.assert_status_equal(response, status.HTTP_201_CREATED)
72
        self.assert_instance_exists(User, username=data['username'])
73
        self.assert_emails_in_mailbox(1)
74
        self.assert_email_exists(to=[data['email']])
75
76
        user = User.objects.get(username='john')
77
        self.assertTrue(user.is_active)
78
79
    def test_post_not_create_new_user_if_username_exists(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_not_create_new_user_if_username_exists 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...
80
        create_user(username='john')
81
        data = {
82
            'username': 'john',
83
            'password': 'secret',
84
            'csrftoken': 'asdf',
85
        }
86
        request = self.factory.post(data=data)
87
88
        response = self.view(request)
89
90
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
91
92
    def test_post_not_register_if_fails_password_validation(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_not_register_i...ils_password_validation 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...
93
        data = {
94
            'username': 'john',
95
            'password': '666',
96
            'csrftoken': 'asdf',
97
        }
98
99
        request = self.factory.post(data=data)
100
        response = self.view(request)
101
102
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
103
        self.assertEqual(
104
            response.data,
105
            {'password': ['Password 666 is not allowed.']}
106
        )
107
108
    @mock.patch('djoser.serializers.UserRegistrationSerializer.perform_create',
109
                side_effect=perform_create_mock)
110
    def test_post_return_400_for_integrity_error(self, perform_create):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_return_400_for_integrity_error 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...
Unused Code introduced by
The argument perform_create seems to be unused.
Loading history...
111
        data = {
112
            'username': 'john',
113
            'email': '[email protected]',
114
            'password': 'secret',
115
        }
116
117
        request = self.factory.post(data=data)
118
        response = self.view(request)
119
120
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
121
        self.assertEqual(
122
            response.data, [djoser.constants.CANNOT_CREATE_USER_ERROR]
123
        )
124