GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RegistrationViewWithDefaultRegistrationSupplementTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 39.29 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_registration_view_get() 0 15 1
A test_registration_view_post_no_remarks_failure() 16 16 1
A test_registration_view_post_success() 0 20 1
A test_registration_view_post_failure() 17 17 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
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3
"""
4
"""
5
__author__ = 'Alisue <[email protected]>'
6
from django.test import TestCase
7
from django.core import mail
8
from django.core.urlresolvers import reverse
9
from django.core.exceptions import ImproperlyConfigured
10
11
from registration import forms
12
from registration.supplements import get_supplement_class
13
from registration.models import RegistrationProfile
14
from registration.tests.utils import with_apps
15
from registration.tests.compat import override_settings
16
17
18
class RegistrationSupplementRetrievalTests(TestCase):
19
20
    def test_get_supplement_class(self):
21
        from registration.supplements.default.models import DefaultRegistrationSupplement
22
        supplement_class = get_supplement_class(
23
                'registration.supplements.default.models.DefaultRegistrationSupplement')
24
        self.failUnless(supplement_class is DefaultRegistrationSupplement)
25
26
    def test_supplement_error_invalid(self):
27
        self.assertRaises(ImproperlyConfigured, get_supplement_class,
28
                'registration.supplements.doesnotexist.NonExistenBackend')
29
30
    def test_supplement_attribute_error(self):
31
        self.assertRaises(ImproperlyConfigured, get_supplement_class,
32
                'registration.supplements.default.NonexistenBackend')
33
34
35
@with_apps(
36
    'django.contrib.contenttypes',
37
    'registration.supplements.default'
38
)
39
@override_settings(
40
        ACCOUNT_ACTIVATION_DAYS=7,
41
        REGISTRATION_OPEN=True,
42
        REGISTRATION_SUPPLEMENT_CLASS=(
43
            'registration.supplements.default.models.DefaultRegistrationSupplement'),
44
        REGISTRATION_BACKEND_CLASS=(
45
            'registration.backends.default.DefaultRegistrationBackend'),
46
    )
47
class RegistrationViewWithDefaultRegistrationSupplementTestCase(TestCase):
48
    def test_registration_view_get(self):
49
        """
50
        A ``GET`` to the ``register`` view uses the appropriate
51
        template and populates the registration form into the context.
52
53
        """
54
        from registration.supplements.default.models import DefaultRegistrationSupplement
55
        response = self.client.get(reverse('registration_register'))
56
        self.assertEqual(response.status_code, 200)
57
        self.assertTemplateUsed(response,
58
                                'registration/registration_form.html')
59
        self.failUnless(isinstance(response.context['form'],
60
                                   forms.RegistrationForm))
61
        self.failUnless(isinstance(response.context['supplement_form'].instance,
62
                                   DefaultRegistrationSupplement))
63
64
    def test_registration_view_post_success(self):
65
        """
66
        A ``POST`` to the ``register`` view with valid data properly
67
        creates a new user and issues a redirect.
68
69
        """
70
        from registration.supplements.default.models import DefaultRegistrationSupplement
71
        response = self.client.post(reverse('registration_register'),
72
                                    data={'username': 'alice',
73
                                          'email1': '[email protected]',
74
                                          'email2': '[email protected]',
75
                                          'remarks': 'Hello'})
76
        self.assertRedirects(response,
77
                             'http://testserver%s' % reverse('registration_complete'))
78
        self.assertEqual(RegistrationProfile.objects.count(), 1)
79
        self.assertEqual(DefaultRegistrationSupplement.objects.count(), 1)
80
        self.assertEqual(len(mail.outbox), 1)
81
82
        profile = RegistrationProfile.objects.get(user__username='alice')
83
        self.assertEqual(profile.supplement.remarks, 'Hello')
84
85 View Code Duplication
    def test_registration_view_post_failure(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
86
        """
87
        A ``POST`` to the ``register`` view with invalid data does not
88
        create a user, and displays appropriate error messages.
89
90
        """
91
        response = self.client.post(reverse('registration_register'),
92
                                    data={'username': 'bob',
93
                                          'email1': '[email protected]',
94
                                          'email2': '[email protected]',
95
                                          'remarks': 'Hello'})
96
        self.assertEqual(response.status_code, 200)
97
        self.failIf(response.context['form'].is_valid())
98
        self.failUnless(response.context['supplement_form'].is_valid())
99
        self.assertFormError(response, 'form', field=None,
100
                             errors="The two email fields didn't match.")
101
        self.assertEqual(len(mail.outbox), 0)
102
103 View Code Duplication
    def test_registration_view_post_no_remarks_failure(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
104
        """
105
        A ``POST`` to the ``register`` view with invalid data does not
106
        create a user, and displays appropriate error messages.
107
108
        """
109
        response = self.client.post(reverse('registration_register'),
110
                                    data={'username': 'bob',
111
                                          'email1': '[email protected]',
112
                                          'email2': '[email protected]'})
113
        self.assertEqual(response.status_code, 200)
114
        self.failUnless(response.context['form'].is_valid())
115
        self.failIf(response.context['supplement_form'].is_valid())
116
        self.assertFormError(response, 'supplement_form', field='remarks',
117
                             errors="This field is required.")
118
        self.assertEqual(len(mail.outbox), 0)
119