Passed
Push — master ( c2c2f1...c3caf7 )
by Piotr
01:10
created

ProviderAuthViewTestCase   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 45.21 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 9
c 3
b 0
f 0
dl 33
loc 73
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_post_facebook_provider_success_returns_token() 17 17 2
A test_get_facebook_provider_fails_if_wrong_redirect_uri() 0 5 1
A test_get_facebook_provider_fails_if_no_redirect_uri() 0 5 1
A test_post_facebook_provider_code_validation_fails() 16 16 2
A test_post_facebook_provider_validation_fails_if_invalid_state() 0 12 2
A test_get_facebook_provider_provides_valid_authorization_url() 0 8 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.contrib.sessions.middleware import SessionMiddleware
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.sessions.middleware'
Loading history...
2
from django.utils import six
0 ignored issues
show
introduced by
Unable to import 'django.utils'
Loading history...
3
from rest_framework import status
0 ignored issues
show
introduced by
Unable to import 'rest_framework'
Loading history...
4
5
from djet import assertions, restframework
0 ignored issues
show
introduced by
Unable to import 'djet'
Loading history...
6
import djoser.social.views
7
from social_core.exceptions import AuthException
0 ignored issues
show
introduced by
Unable to import 'social_core.exceptions'
Loading history...
8
9
from ..common import create_user, mock
10
11
12
class ProviderAuthViewTestCase(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
    view_class = djoser.social.views.ProviderAuthView
15
    middleware = [SessionMiddleware]
16
17
    def test_get_facebook_provider_fails_if_no_redirect_uri(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_facebook_provid...ails_if_no_redirect_uri 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
        request = self.factory.get()
19
        response = self.view(request, provider='facebook')
20
21
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
22
23
    def test_get_facebook_provider_fails_if_wrong_redirect_uri(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_facebook_provid...s_if_wrong_redirect_uri 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...
24
        request = self.factory.get(data={'redirect_uri': 'http://yolo.com/'})
25
        response = self.view(request, provider='facebook')
26
27
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
28
29
    def test_get_facebook_provider_provides_valid_authorization_url(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_facebook_provid...valid_authorization_url 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
        request = self.factory.get(data={
31
            'redirect_uri': 'http://test.localhost/'
32
        })
33
        response = self.view(request, provider='facebook')
34
35
        self.assert_status_equal(response, status.HTTP_200_OK)
36
        self.assertIn('authorization_url', response.data)
37
38 View Code Duplication
    def test_post_facebook_provider_success_returns_token(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_facebook_provider_success_returns_token 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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
39
        data = {'code': 'XYZ', 'state': 'ABC'}
40
41
        mock.patch(
42
            'social_core.backends.facebook.FacebookOAuth2.auth_complete',
43
            return_value=create_user()
44
        ).start()
45
        mock.patch(
46
            'social_core.backends.oauth.OAuthAuth.get_session_state',
47
            return_value=data['state']
48
        ).start()
49
50
        request = self.factory.post()
51
        request.GET = {k: v for k, v in six.iteritems(data)}
52
        response = self.view(request, provider='facebook')
53
        self.assert_status_equal(response, status.HTTP_201_CREATED)
54
        self.assertEqual(set(response.data.keys()), {'token', 'user'})
55
56 View Code Duplication
    def test_post_facebook_provider_code_validation_fails(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_facebook_provider_code_validation_fails 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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
57
        data = {'code': 'XYZ', 'state': 'ABC'}
58
59
        mock.patch(
60
            'social_core.backends.facebook.FacebookOAuth2.auth_complete',
61
            side_effect=AuthException(backend=None)
62
        ).start()
63
        mock.patch(
64
            'social_core.backends.oauth.OAuthAuth.get_session_state',
65
            return_value=data['state']
66
        ).start()
67
68
        request = self.factory.post()
69
        request.GET = {k: v for k, v in six.iteritems(data)}
70
        response = self.view(request, provider='facebook')
71
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
72
73
    def test_post_facebook_provider_validation_fails_if_invalid_state(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_post_facebook_provi..._fails_if_invalid_state 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...
74
        data = {'code': 'XYZ', 'state': 'ABC'}
75
76
        mock.patch(
77
            'social_core.backends.oauth.OAuthAuth.get_session_state',
78
            return_value=data['state'][::-1]
79
        ).start()
80
81
        request = self.factory.post()
82
        request.GET = {k: v for k, v in six.iteritems(data)}
83
        response = self.view(request, provider='facebook')
84
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
85