Passed
Push — master ( cb96a6...03dbbf )
by Piotr
01:10
created

UserViewTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 35.71 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 3
c 5
b 0
f 0
dl 15
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get_return_user() 0 9 1
A test_email_change_with_send_activation_email_false() 0 10 1
A test_email_change_with_send_activation_email_true() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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...
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, utils
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.views
7
8
from .common import create_user
9
10
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...
11
12
13
class UserViewTest(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...
14
                   assertions.EmailAssertionsMixin,
15
                   assertions.StatusCodeAssertionsMixin):
16
    view_class = djoser.views.UserView
17
18
    def test_get_return_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...
19
        user = create_user()
20
        request = self.factory.get(user=user)
21
22
        response = self.view(request)
23
24
        self.assert_status_equal(response, status.HTTP_200_OK)
25
        self.assertEqual(set(response.data.keys()), set(
26
            [User.USERNAME_FIELD, User._meta.pk.name] + User.REQUIRED_FIELDS
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _meta was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
27
        ))
28
29
    def test_email_change_with_send_activation_email_false(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_email_change_with_send_activation_email_false 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...
30
        user = create_user()
31
        data = {'email': '[email protected]'}
32
        request = self.factory.put(user=user, data=data)
33
        response = self.view(request)
34
35
        self.assert_status_equal(response, status.HTTP_200_OK)
36
        user = utils.refresh(user)
37
        self.assertEqual(data['email'], user.email)
38
        self.assertTrue(user.is_active)
39
40 View Code Duplication
    @override_settings(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
41
        DJOSER=dict(settings.DJOSER, **{'SEND_ACTIVATION_EMAIL': True})
42
    )
0 ignored issues
show
Coding Style Naming introduced by
The name test_email_change_with_send_activation_email_true 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...
43
    def test_email_change_with_send_activation_email_true(self):
44
        user = create_user()
45
        data = {'email': '[email protected]'}
46
        request = self.factory.put(user=user, data=data)
47
        response = self.view(request)
48
49
        self.assert_status_equal(response, status.HTTP_200_OK)
50
        user = utils.refresh(user)
51
        self.assertEqual(data['email'], user.email)
52
        self.assertFalse(user.is_active)
53
        self.assert_emails_in_mailbox(1)
54
        self.assert_email_exists(to=[data['email']])
55