~canonical-isd-hackers/canonical-identity-provider/sst-changes

« back to all changes in this revision

Viewing changes to identityprovider/tests/test_models_oauthtoken.py

  • Committer: Danny Tamez
  • Date: 2010-04-21 15:29:24 UTC
  • Revision ID: danny.tamez@canonical.com-20100421152924-lq1m92tstk2iz75a
Canonical SSO Provider (Open Source) - Initial Commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
from identityprovider.tests.utils import BasicAccountTestCase
 
5
from identityprovider.models.account import Account
 
6
from identityprovider.models.oauthtoken import (Consumer,
 
7
                                                create_oauth_token_for_account)
 
8
 
 
9
 
 
10
class ConsumerTestCase(BasicAccountTestCase):
 
11
 
 
12
    def test_one_to_one_relationship_with_account(self):
 
13
        account = Account.objects.get_by_email('test@canonical.com')
 
14
        consumer, _ = Consumer.objects.get_or_create(account=account)
 
15
 
 
16
        self.assertEquals(account.id, consumer.account.id)
 
17
        self.assertEquals(consumer.id, account.oauth_consumer.id)
 
18
 
 
19
 
 
20
class CreateOAuthTokenForAccountTestCase(BasicAccountTestCase):
 
21
 
 
22
    def test_when_account_has_associated_consumer(self):
 
23
        account = Account.objects.get_by_email('test@canonical.com')
 
24
        consumer, _ = Consumer.objects.get_or_create(account=account)
 
25
 
 
26
        token = create_oauth_token_for_account(account, 'new-token')
 
27
 
 
28
        self.assertEquals(token.consumer.id, consumer.id)
 
29
 
 
30
    def test_when_account_has_no_associated_consumer(self):
 
31
        account = Account.objects.get_by_email('test@canonical.com')
 
32
        Consumer.objects.filter(account=account).delete()
 
33
 
 
34
        token = create_oauth_token_for_account(account, 'new-token')
 
35
 
 
36
        self.assertEquals(token.consumer.account.id, account.id)