~michael.nelson/canonical-identity-provider/add-convoy-combo

« back to all changes in this revision

Viewing changes to identityprovider/tests/helpers.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2013-04-01 18:23:16 UTC
  • mfrom: (753.4.12 the-hand-is-quicker-2)
  • Revision ID: tarmac-20130401182316-ioglnxyjdmsu0xqf
[r=matiasb] - Cleanup of testing views: replaced logic from urls.py with the new decorator require_testing_enabled (moved from webui project).
- Removed dummy and dummy hooks testing views.
- Removed fixtures from leftover tests from identity provider.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
from urlparse import parse_qs
7
7
 
 
8
from django.contrib.auth.models import User
8
9
from django.core.urlresolvers import reverse
9
10
from django.test import client
10
11
from openid import fetchers
21
22
from openid.message import IDENTIFIER_SELECT
22
23
from openid.store.memstore import MemoryStore
23
24
from pyquery import PyQuery
24
 
from u1testutils.django import switch_settings
25
 
 
26
 
import identityprovider.urls  # need to reload after patching the settings
27
25
 
28
26
from identityprovider.const import LAUNCHPAD_TEAMS_NS
29
 
from identityprovider.models import AuthToken
 
27
from identityprovider.models import AuthToken, OpenIDRPConfig
30
28
from identityprovider.models.const import TokenType
31
 
from identityprovider.models.openidmodels import OpenIDRPConfig
32
29
from identityprovider.tests import DEFAULT_USER_PASSWORD
33
 
from identityprovider.tests.utils import SSOBaseTestCase
 
30
from identityprovider.tests.utils import SSOBaseTestCase, patch_settings
34
31
from webui.views.consumer import fetchers as webui_fetchers
35
32
 
36
33
 
64
61
 
65
62
 
66
63
class FunctionalTestCase(SSOBaseTestCase):
67
 
    fixtures = ['admin', 'test']
 
64
 
68
65
    base_url = 'http://testserver'
69
66
    base_openid_url = base_url + '/+openid'
70
67
    consumer_url = 'http://launchpad.dev'
77
74
    def setUp(self):
78
75
        super(FunctionalTestCase, self).setUp()
79
76
 
80
 
        self.old_settings = switch_settings(
 
77
        p = patch_settings(
81
78
            DEBUG=True,
 
79
            TESTING=True,
82
80
            SSO_ROOT_URL=self.base_url,
83
81
            SSO_PROVIDER_URL=self.base_openid_url,
84
82
            OPENID_PREAUTHORIZATION_ACL=(
85
83
                (self.consumer_url, self.consumer_url),
86
84
                (self.base_url, self.base_url),
87
85
            ),
88
 
            SSO_RESTRICT_RP = False,
 
86
            SSO_RESTRICT_RP=False,
89
87
        )
90
 
        # reload urls to avoid supurius 404
91
 
        reload(identityprovider.urls)
 
88
        p.start()
 
89
        self.addCleanup(p.stop)
92
90
 
93
 
        self.addCleanup(switch_settings, **self.old_settings)
 
91
        # Create an admin user
 
92
        User.objects.create_superuser(
 
93
            username='admin', password='Admin007', email='a@a.com')
 
94
        # Create a regular user
 
95
        self.account = self.factory.make_account(
 
96
            email=self.default_email, password=self.default_password)
 
97
        self.factory.make_email_for_account(
 
98
            email='testing@canonical.com', account=self.account)
 
99
        self.claimed_id = (self.base_url + '/+id/' +
 
100
                           self.account.openid_identifier)
94
101
 
95
102
    def reset_client(self):
96
103
        self.client = client.Client()
188
195
            msg = "Regular expression '%s' does not match '%s'"
189
196
            self.fail(msg % (regexp, string))
190
197
 
 
198
    def assert_home_page(self, response):
 
199
        title = self.title_from_response(response)
 
200
        self.assertEqual(title, "%s's details" % self.account.displayname)
 
201
 
191
202
    def create_openid_rp_config(self, **extra):
192
203
        kwargs = {
193
204
            'trust_root': self.consumer_url,
221
232
        [assoc_handle] = re.findall('assoc_handle:(.*)', response.content)
222
233
        return assoc_handle
223
234
 
224
 
    def do_request(self, mode, oid='name12_oid',
 
235
    def do_request(self, mode, oid=None,
225
236
                   with_assoc_handle=True, with_return_to=True, **extra):
226
237
 
227
238
        data = {'openid.mode': mode, 'openid.trust_root': self.consumer_url}
228
 
        if oid is not None:
229
 
            if not oid.startswith('http'):
230
 
                oid = self.base_url + '/+id/' + oid
231
 
            data['openid.identity'] = oid
 
239
        if oid is None:
 
240
            oid = self.claimed_id
 
241
        elif not oid.startswith('http'):
 
242
            oid = self.base_url + '/+id/' + oid
 
243
        data['openid.identity'] = oid
232
244
 
233
245
        if with_return_to:
234
246
            data['openid.return_to'] = self.consumer_openid_url