Source

django-registration-plus / registration / tests / backends.py

Full commit
  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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
import datetime

from django.conf import settings
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.sites.models import Site
from django.core import mail
from django.core.exceptions import ImproperlyConfigured
from django.core.handlers.wsgi import WSGIRequest
from django.test import Client
from django.test import TestCase

from registration import forms
from registration import signals
from registration.admin import EmailValidationAdmin
from registration.backends import get_backend
from registration.backends.default import DefaultBackend, OptionalValidationBackend
from registration.backends.simple import SimpleBackend, NoLoginSimpleBackend
from registration.models import EmailValidation


class _MockRequestClient(Client):
    """
    A ``django.test.Client`` subclass which can return mock
    ``HttpRequest`` objects.
    
    """
    def request(self, **request):
        """
        Rather than issuing a request and returning the response, this
        simply constructs an ``HttpRequest`` object and returns it.
        
        """
        environ = {
            'HTTP_COOKIE': self.cookies,
            'PATH_INFO': '/',
            'QUERY_STRING': '',
            'REMOTE_ADDR': '127.0.0.1',
            'REQUEST_METHOD': 'GET',
            'SCRIPT_NAME': '',
            'SERVER_NAME': 'testserver',
            'SERVER_PORT': '80',
            'SERVER_PROTOCOL': 'HTTP/1.1',
            'wsgi.version': (1,0),
            'wsgi.url_scheme': 'http',
            'wsgi.errors': self.errors,
            'wsgi.multiprocess':True,
            'wsgi.multithread': False,
            'wsgi.run_once': False,
            'wsgi.input': None,
            }
        environ.update(self.defaults)
        environ.update(request)
        request = WSGIRequest(environ)
        
        # We have to manually add a session since we'll be bypassing
        # the middleware chain.
        session_middleware = SessionMiddleware()
        session_middleware.process_request(request)
        return request
    

def _mock_request():
    """
    Construct and return a mock ``HttpRequest`` object; this is used
    in testing backend methods which expect an ``HttpRequest`` but
    which are not being called from views.
    
    """
    return _MockRequestClient().request()
    

class BackendRetrievalTests(TestCase):
    """
    Test that utilities for retrieving the active backend work
    properly.
    
    """
    def test_get_backend(self):
        """
        Verify that ``get_backend()`` returns the correct value when
        passed a valid backend.

        """
        self.failUnless(isinstance(get_backend('registration.backends.default.DefaultBackend'),
                                   DefaultBackend))
    
    def test_backend_error_invalid(self):
        """
        Test that a nonexistent/unimportable backend raises the
        correct exception.
    
        """
        self.assertRaises(ImproperlyConfigured, get_backend,
                          'registration.backends.doesnotexist.NonExistentBackend')
    
    def test_backend_attribute_error(self):
        """
        Test that a backend module which exists but does not have a
        class of the specified name raises the correct exception.
        
        """
        self.assertRaises(ImproperlyConfigured, get_backend,
                          'registration.backends.default.NonexistentBackend')
    

class DefaultBackendTests(TestCase):
    """
    Test the default registration backend.
    
    Running these tests successfully will require two templates to be
    created for the sending of validation emails; details on these
    templates and their contexts may be found in the documentation for
    the default backend.
    
    """
    backend = DefaultBackend()
    
    def setUp(self):
        """
        Create an instance of the default backend for use in testing,
        and set ``EMAIL_VALIDATION_DAYS`` if it's not set already.
        
        """
        self.old_validation = getattr(settings, 'EMAIL_VALIDATION_DAYS', None)
        if self.old_validation is None:
            settings.EMAIL_VALIDATION_DAYS = 7 # pragma: no cover
    
    def tearDown(self):
        """
        Yank out ``EMAIL_VALIDATION_DAYS`` back out if it wasn't
        originally set.
        
        """
        if self.old_validation is None:
            settings.EMAIL_VALIDATION_DAYS = self.old_validation # pragma: no 
            # cover
    
    def test_registration(self):
        """
        Test the registration process: registration creates a new
        inactive account and a new validation with validation key,
        populates the correct account data and sends a validation
        email.
        
        """
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        
        # Details of the returned user must match what went in.
        self.assertEqual(new_user.username, 'bob')
        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, 'bob@example.com')

        # New user must not be active.
        self.failIf(new_user.is_active)

        # A registration validation was created, and a validation email
        # was sent.
        self.assertEqual(EmailValidation.objects.count(), 1)
        self.assertEqual(len(mail.outbox), 1)

    def test_registration_no_sites(self):
        """
        Test that registration still functions properly when
        ``django.contrib.sites`` is not installed; the fallback will
        be a ``RequestSite`` instance.
        
        """
        Site._meta.installed = False
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        
        self.assertEqual(new_user.username, 'bob')
        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, 'bob@example.com')
        
        self.failIf(new_user.is_active)
        
        self.assertEqual(EmailValidation.objects.count(), 1)
        self.assertEqual(len(mail.outbox), 1)
        
        Site._meta.installed = True
    
    def test_valid_validation(self):
        """
        Test the validation process: validating within the permitted
        window sets the account's ``is_active`` field to ``True`` and
        resets the validation key.
        
        """
        valid_user = self.backend.register(_mock_request(),
                                           username='alice',
                                           email='alice@example.com',
                                           password1='swordfish')
        
        valid_validation = EmailValidation.objects.get(user=valid_user)
        validated = self.backend.validate(_mock_request(),
                                          valid_validation.validation_key)
        self.assertEqual(validated.username, valid_user.username)
        self.failUnless(validated.is_active)
        
        # Fetch the validation again to verify its validation key has
        # been reset.
        valid_validation = EmailValidation.objects.get(user=valid_user)
        self.assertEqual(valid_validation.validation_key,
                         EmailValidation.VALIDATED)
    
    def test_invalid_validation(self):
        """
        Test the validation process: trying to validate outside the
        permitted window fails, and leaves the account inactive.
        
        """
        expired_user = self.backend.register(_mock_request(),
                                             username='bob',
                                             email='bob@example.com',
                                             password1='secret')
        expired_validation = EmailValidation.objects.get(user=expired_user)
        expired_validation.created -= datetime.timedelta(days=settings
                                                         .EMAIL_VALIDATION_DAYS + 1)
        expired_validation.save()
        self.failIf(self.backend.validate(_mock_request(),
                                          expired_validation.validation_key))
        self.failUnless(expired_validation.validation_key_expired())
    
    def test_allow(self):
        """
        Test that the setting ``REGISTRATION_OPEN`` appropriately
        controls whether registration is permitted.
        
        """
        old_allowed = getattr(settings, 'REGISTRATION_OPEN', True)
        settings.REGISTRATION_OPEN = True
        self.failUnless(self.backend.registration_allowed(_mock_request()))
        
        settings.REGISTRATION_OPEN = False
        self.failIf(self.backend.registration_allowed(_mock_request()))
        settings.REGISTRATION_OPEN = old_allowed
    
    def test_form_class(self):
        """
        Test that the default form class returned is
        ``registration.forms.RegistrationForm``.
        
        """
        self.failUnless(self.backend.get_form_class(_mock_request()) is forms.RegistrationForm)
    
    def test_post_registration_redirect(self):
        """
        Test that the default post-registration redirect is the named
        pattern ``registration_complete``.
        
        """
        self.assertEqual(self.backend.post_registration_redirect(_mock_request(), User()),
                         ('registration_complete', (), {}))
    
    def test_registration_signal(self):
        """
        Test that registering a user sends the ``user_registered``
        signal.
        
        """
        def receiver(sender, **kwargs):
            self.failUnless('user' in kwargs)
            self.assertEqual(kwargs['user'].username, 'bob')
            self.failUnless('request' in kwargs)
            self.failUnless(isinstance(kwargs['request'], WSGIRequest))
            received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.user_registered.connect(receiver, sender=self.backend.__class__)
        
        self.backend.register(_mock_request(),
                              username='bob',
                              email='bob@example.com',
                              password1='secret')
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.user_registered])
    
    def test_activation_signal_success(self):
        """
        Test that successfully validating a user sends the
        ``user_validated`` signal.
        
        """
        def receiver(sender, **kwargs):
            self.failUnless('user' in kwargs)
            self.assertEqual(kwargs['user'].username, 'bob')
            self.failUnless('request' in kwargs)
            self.failUnless(isinstance(kwargs['request'], WSGIRequest))
            received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.user_activated.connect(receiver, sender=self.backend.__class__)
        
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        validation = EmailValidation.objects.get(user=new_user)
        self.backend.validate(_mock_request(), validation.validation_key)
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.user_activated])
    
    def test_validation_signal_success(self):
        """
        Test that successfully validating a user sends the
        ``user_validated`` signal.
        
        """
        def receiver(sender, **kwargs):
            self.failUnless('user' in kwargs)
            self.assertEqual(kwargs['user'].username, 'bob')
            self.failUnless('request' in kwargs)
            self.failUnless(isinstance(kwargs['request'], WSGIRequest))
            received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.email_validated.connect(receiver, sender=self.backend.__class__)
        
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        validation = EmailValidation.objects.get(user=new_user)
        self.backend.validate(_mock_request(), validation.validation_key)
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.email_validated])
    
    def test_activation_signal_failure(self):
        """
        Test that an unsuccessful validation attempt does not send the
        ``user_validated`` signal.
        
        """
        receiver = lambda sender, **kwargs: received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.user_activated.connect(receiver, sender=self.backend.__class__)
        
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        validation = EmailValidation.objects.get(user=new_user)
        validation.created -= datetime.timedelta(days=settings.EMAIL_VALIDATION_DAYS + 1)
        validation.save()
        self.backend.validate(_mock_request(), validation.validation_key)
        
        self.assertEqual(len(received_signals), 0)
    
    def test_email_send_action(self):
        """
        Test re-sending of validation emails via admin action.
        
        """
        admin_class = EmailValidationAdmin(EmailValidation, admin.site)
        
        alice = self.backend.register(_mock_request(),
                                      username='alice',
                                      email='alice@example.com',
                                      password1='swordfish')
        
        admin_class.resend_validation_email(_mock_request(),
                                            EmailValidation.objects.all())
        self.assertEqual(len(mail.outbox), 2) # One on registering, one more on the resend.
        
        EmailValidation.objects.filter(user=alice).update(validation_key=EmailValidation.VALIDATED)
        admin_class.resend_validation_email(_mock_request(),
                                            EmailValidation.objects.all())
        self.assertEqual(len(mail.outbox), 2) # No additional email because the account has validated.
    
    def test_email_send_action_no_sites(self):
        """
        Test re-sending of validation emails via admin action when
        ``django.contrib.sites`` is not installed; the fallback will
        be a ``RequestSite`` instance.
        
        """
        Site._meta.installed = False
        admin_class = EmailValidationAdmin(EmailValidation, admin.site)
        
        alice = self.backend.register(_mock_request(),
                                      username='alice',
                                      email='alice@example.com',
                                      password1='swordfish')
        
        admin_class.resend_validation_email(_mock_request(),
                                            EmailValidation.objects.all())
        self.assertEqual(len(mail.outbox), 2) # One on registering, one more on the resend.
        
        EmailValidation.objects.filter(user=alice).update(validation_key=EmailValidation.VALIDATED)
        admin_class.resend_validation_email(_mock_request(),
                                            EmailValidation.objects.all())
        self.assertEqual(len(mail.outbox), 2) # No additional email because the account has validated.
        Site._meta.installed = True
    
    def test_validation_action(self):
        """
        Test manual validation of users view admin action.
        
        """
        admin_class = EmailValidationAdmin(EmailValidation, admin.site)
        
        alice = self.backend.register(_mock_request(),
                                      username='alice',
                                      email='alice@example.com',
                                      password1='swordfish')
        
        admin_class.validate_users(_mock_request(),
                                   EmailValidation.objects.all())
        self.failUnless(User.objects.get(username='alice').is_active)
    
    def test_invite(self):
        """
        Test that validating against this backend is an error.
        
        """
        self.assertRaises(NotImplementedError, self.backend.invite,
                          request=_mock_request())
    
    def test_post_invitation_redirect(self):
        """
        Test that asking for a post-validation redirect from this
        backend is an error.
        
        """
        self.assertRaises(NotImplementedError, 
                          self.backend.post_invitation_redirect,
                          request=_mock_request(), user=User())
    

class OptionalValidationBackendTests(TestCase):
    """
    Test the optional validation registration backend.
    
    Running these tests successfully will require two templates to be
    created for the sending of validation emails; details on these
    templates and their contexts may be found in the documentation for
    the default backend.
    
    """
    backend = OptionalValidationBackend()
    
    def setUp(self):
        """
        Create an instance of the default backend for use in testing,
        and set ``EMAIL_VALIDATION_DAYS`` if it's not set already.
        
        """
        self.old_validation = getattr(settings, 'EMAIL_VALIDATION_DAYS', None)
        if self.old_validation is None:
            settings.EMAIL_VALIDATION_DAYS = 7 # pragma: no cover
    
    def tearDown(self):
        """
        Yank out ``EMAIL_VALIDATION_DAYS`` back out if it wasn't
        originally set.
        
        """
        if self.old_validation is None:
            settings.EMAIL_VALIDATION_DAYS = self.old_validation # pragma: no cover
    
    def test_registration(self):
        """
        Test the registration process: registration creates a new
        active account and a new validation with validation key,
        populates the correct account data and sends a validation
        email.
        
        """
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        
        # Details of the returned user must match what went in.
        self.assertEqual(new_user.username, 'bob')
        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, 'bob@example.com')
        
        # New user must be active.
        self.failUnless(new_user.is_active)
        
        # An email validation was created, and a validation email
        # was sent.
        self.assertEqual(EmailValidation.objects.count(), 1)
        self.assertEqual(len(mail.outbox), 1)
    
    def test_registration_signal(self):
        """
        Test that registering a user sends the ``user_registered``
        signal.
        
        """
        def receiver(sender, **kwargs):
           self.failUnless('user' in kwargs)
           self.assertEqual(kwargs['user'].username, 'bob')
           self.failUnless('request' in kwargs)
           self.failUnless(isinstance(kwargs['request'], WSGIRequest))
           received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.user_registered.connect(receiver, sender=self.backend.__class__)
        
        self.backend.register(_mock_request(),
                             username='bob',
                             email='bob@example.com',
                             password1='secret')
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.user_registered])
    
    def test_activation_signal(self):
        """
        Test that registering a user sends the ``user_activated``
        signal.
        
        """
        def receiver(sender, **kwargs):
           self.failUnless('user' in kwargs)
           self.assertEqual(kwargs['user'].username, 'bob')
           self.failUnless('request' in kwargs)
           self.failUnless(isinstance(kwargs['request'], WSGIRequest))
           received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.user_activated.connect(receiver, sender=self.backend.__class__)
        
        self.backend.register(_mock_request(),
                             username='bob',
                             email='bob@example.com',
                             password1='secret')
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.user_activated])
    
    def test_validation_signal_success(self):
        """
        Test that successfully validating a user sends the
        ``user_validated`` signal.
        
        """
        def receiver(sender, **kwargs):
            self.failUnless('user' in kwargs)
            self.assertEqual(kwargs['user'].username, 'bob')
            self.failUnless('request' in kwargs)
            self.failUnless(isinstance(kwargs['request'], WSGIRequest))
            received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.email_validated.connect(receiver, sender=self.backend.__class__)
        
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        validation = EmailValidation.objects.get(user=new_user)
        self.backend.validate(_mock_request(), validation.validation_key)
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.email_validated])
    
    def test_validation_signal_failure(self):
        """
        Test that an unsuccessful validation attempt does not send the
        ``user_validated`` signal.
        
        """
        receiver = lambda sender, **kwargs: received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.email_validated.connect(receiver, sender=self.backend.__class__)
        
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        validation = EmailValidation.objects.get(user=new_user)
        validation.created -= datetime.timedelta(days=settings.EMAIL_VALIDATION_DAYS + 1)
        validation.save()
        self.backend.validate(_mock_request(), validation.validation_key)
        
        self.assertEqual(len(received_signals), 0)
    

class SimpleBackendTests(TestCase):
    """
    Test the simple registration backend, which does signup and
    immediate validation.
    
    """
    backend = SimpleBackend()
    
    def test_registration(self):
        """
        Test the registration process: registration creates a new
        inactive account and a new validation with validation key,
        populates the correct account data and sends an validation
        email.
        
        """
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        
        # Details of the returned user must match what went in.
        self.assertEqual(new_user.username, 'bob')
        self.failUnless(new_user.check_password('secret'))
        self.assertEqual(new_user.email, 'bob@example.com')
        
        # New user must not be active.
        self.failUnless(new_user.is_active)
    
    def test_allow(self):
        """
        Test that the setting ``REGISTRATION_OPEN`` appropriately
        controls whether registration is permitted.
        
        """
        old_allowed = getattr(settings, 'REGISTRATION_OPEN', True)
        settings.REGISTRATION_OPEN = True
        self.failUnless(self.backend.registration_allowed(_mock_request()))
        
        settings.REGISTRATION_OPEN = False
        self.failIf(self.backend.registration_allowed(_mock_request()))
        settings.REGISTRATION_OPEN = old_allowed
    
    def test_form_class(self):
        """
        Test that the default form class returned is
        ``registration.forms.RegistrationForm``.
        
        """
        self.failUnless(self.backend.get_form_class(_mock_request()) is forms.RegistrationForm)
    
    def test_post_registration_redirect(self):
        """
        Test that the default post-registration redirect is the public
        URL of the new user account.
        
        """
        new_user = self.backend.register(_mock_request(),
                                         username='bob',
                                         email='bob@example.com',
                                         password1='secret')
        
        self.assertEqual(self.backend.post_registration_redirect(_mock_request(), new_user),
                         (new_user.get_absolute_url(), (), {}))
    
    def test_registration_signal(self):
        """
        Test that registering a user sends the ``user_registered``
        signal.
        
        """
        def receiver(sender, **kwargs):
            self.failUnless('user' in kwargs)
            self.assertEqual(kwargs['user'].username, 'bob')
            self.failUnless('request' in kwargs)
            self.failUnless(isinstance(kwargs['request'], WSGIRequest))
            received_signals.append(kwargs.get('signal'))
        
        received_signals = []
        signals.user_registered.connect(receiver, sender=self.backend.__class__)
        
        self.backend.register(_mock_request(),
                              username='bob',
                              email='bob@example.com',
                              password1='secret')
        
        self.assertEqual(len(received_signals), 1)
        self.assertEqual(received_signals, [signals.user_registered])
    
    def test_validation(self):
        """
        Test that validating against this backend is an error.
        
        """
        self.assertRaises(NotImplementedError, self.backend.validate,
                          request=_mock_request(), validation_key="")
    
    def test_post_validation_redirect(self):
        """
        Test that asking for a post-validation redirect from this
        backend is an error.
        
        """
        self.assertRaises(NotImplementedError, 
                          self.backend.post_validation_redirect,
                          request=_mock_request(), user=User())
    
    def test_invite(self):
        """
        Test that validating against this backend is an error.
        
        """
        self.assertRaises(NotImplementedError, self.backend.invite,
                          request=_mock_request())
    
    def test_post_invitation_redirect(self):
        """
        Test that asking for a post-validation redirect from this
        backend is an error.
        
        """
        self.assertRaises(NotImplementedError, 
                          self.backend.post_invitation_redirect,
                          request=_mock_request(), user=User())