This file is indexed.

/usr/lib/python2.7/dist-packages/registration/tests/test_model_workflow.py is in python-django-registration 2.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
Tests for the model-based activation workflow.

"""

import datetime

from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpRequest
from django.test import override_settings

from ..models import RegistrationProfile
from .. import signals

from .base import ActivationTestCase


@override_settings(ROOT_URLCONF='registration.backends.model_activation.urls')
class ModelActivationViewTests(ActivationTestCase):
    """
    Tests for the model-based activation workflow.

    """
    def test_activation(self):
        """
        Activation of an account functions properly.

        """
        resp = self.client.post(
            reverse('registration_register'),
            data=self.valid_data
        )

        profile = RegistrationProfile.objects.get(
            user__username=self.valid_data[self.user_model.USERNAME_FIELD]
        )

        with self.assertSignalSent(signals.user_activated):
            resp = self.client.get(
                reverse(
                    'registration_activate',
                    args=(),
                    kwargs={'activation_key': profile.activation_key}
                )
            )

        self.assertRedirects(resp, reverse('registration_activation_complete'))

    def test_activation_expired(self):
        """
        An expired account can't be activated.

        """
        resp = self.client.post(
            reverse('registration_register'),
            data=self.valid_data
        )

        profile = RegistrationProfile.objects.get(
            user__username=self.valid_data[self.user_model.USERNAME_FIELD]
        )
        user = profile.user
        user.date_joined -= datetime.timedelta(
            days=settings.ACCOUNT_ACTIVATION_DAYS + 1
        )
        user.save()

        with self.assertSignalNotSent(signals.user_activated):
            resp = self.client.get(
                reverse(
                    'registration_activate',
                    args=(),
                    kwargs={'activation_key': profile.activation_key}
                )
            )

        self.assertEqual(200, resp.status_code)
        self.assertTemplateUsed(resp, 'registration/activate.html')

    def test_activation_signal(self):
        self.client.post(
            reverse('registration_register'),
            data=self.valid_data
        )

        profile = RegistrationProfile.objects.get(
            user__username=self.valid_data[self.user_model.USERNAME_FIELD]
        )

        with self.assertSignalSent(signals.user_activated,
                                   required_kwargs=['user', 'request']) as cm:
            self.client.get(
                reverse(
                    'registration_activate',
                    args=(),
                    kwargs={'activation_key': profile.activation_key}
                )
            )
            self.assertEqual(
                getattr(cm.received_kwargs['user'],
                        self.user_model.USERNAME_FIELD),
                self.valid_data[self.user_model.USERNAME_FIELD]
            )
            self.assertTrue(
                isinstance(cm.received_kwargs['request'], HttpRequest)
            )


class ModelActivationCompatibilityTests(ModelActivationViewTests):
    """
    Re-run the model-activation workflow tests, but using the
    'registration.backends.default' import compatibility support, to
    ensure that it works.

    """
    def test_view_imports(self):
        """
        Importing the views from the old location works, and returns
        the correct view classes.

        """
        from registration.backends.default import views as old_views
        from registration.backends.model_activation import views as new_views

        self.assertEqual(
            old_views.ActivationView.__class__,
            new_views.ActivationView.__class__
        )

        self.assertEqual(
            old_views.RegistrationView.__class__,
            new_views.RegistrationView.__class__
        )