1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
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)
10
class ConsumerTestCase(BasicAccountTestCase):
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)
16
self.assertEquals(account.id, consumer.account.id)
17
self.assertEquals(consumer.id, account.oauth_consumer.id)
20
class CreateOAuthTokenForAccountTestCase(BasicAccountTestCase):
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)
26
token = create_oauth_token_for_account(account, 'new-token')
28
self.assertEquals(token.consumer.id, consumer.id)
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()
34
token = create_oauth_token_for_account(account, 'new-token')
36
self.assertEquals(token.consumer.account.id, account.id)