Passed
Pull Request — master (#244)
by Piotr
01:19
created

ProviderAuthViewTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_post_facebook_provider_success_returns_token() 0 16 1
A test_post_facebook_provider_code_validation_fails() 0 15 1
A test_post_facebook_provider_validation_fails_if_invalid_state() 0 11 1
A test_get_facebook_provider_provides_valid_authorization_url() 0 6 1
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 rest_framework import status
0 ignored issues
show
introduced by
Unable to import 'rest_framework'
Loading history...
3
4
from djet import assertions, restframework
0 ignored issues
show
introduced by
Unable to import 'djet'
Loading history...
5
import djoser.social.views
6
from social_core.exceptions import AuthException
0 ignored issues
show
introduced by
Unable to import 'social_core.exceptions'
Loading history...
7
8
from ..common import create_user, mock
9
10
11
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...
12
                               assertions.StatusCodeAssertionsMixin):
13
    view_class = djoser.social.views.ProviderAuthView
14
    middleware = [SessionMiddleware]
15
16
    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...
17
        request = self.factory.get()
18
        response = self.view(request, provider='facebook')
19
20
        self.assert_status_equal(response, status.HTTP_200_OK)
21
        self.assertIn('authorization_url', response.data)
22
23
    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...
24
        data = {'code': 'XYZ', 'state': 'ABC'}
25
26
        mock.patch(
27
            'social_core.backends.facebook.FacebookOAuth2.auth_complete',
28
            return_value=create_user()
29
        ).start()
30
        mock.patch(
31
            'social_core.backends.oauth.OAuthAuth.get_session_state',
32
            return_value=data['state']
33
        ).start()
34
35
        request = self.factory.post(data=data)
36
        response = self.view(request, provider='facebook')
37
        self.assert_status_equal(response, status.HTTP_201_CREATED)
38
        self.assertEqual(set(response.data.keys()), {'token', 'user'})
39
40
    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...
41
        data = {'code': 'XYZ', 'state': 'ABC'}
42
43
        mock.patch(
44
            'social_core.backends.facebook.FacebookOAuth2.auth_complete',
45
            side_effect=AuthException(backend=None)
46
        ).start()
47
        mock.patch(
48
            'social_core.backends.oauth.OAuthAuth.get_session_state',
49
            return_value=data['state']
50
        ).start()
51
52
        request = self.factory.post(data=data)
53
        response = self.view(request, provider='facebook')
54
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
55
56
    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...
57
        data = {'code': 'XYZ', 'state': 'ABC'}
58
59
        mock.patch(
60
            'social_core.backends.oauth.OAuthAuth.get_session_state',
61
            return_value=data['state'][::-1]
62
        ).start()
63
64
        request = self.factory.post(data=data)
65
        response = self.view(request, provider='facebook')
66
        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
67