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
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for the OAuth database classes."""
__metaclass__ = type
__all__ = []
import unittest
from storm.zope.interfaces import IZStorm
from zope.component import getUtility
from lp.services.oauth.model import (
OAuthAccessToken,
OAuthConsumer,
OAuthNonce,
OAuthRequestToken,
)
from lp.services.webapp.interfaces import (
MAIN_STORE,
MASTER_FLAVOR,
)
from lp.testing.layers import DatabaseFunctionalLayer
class BaseOAuthTestCase(unittest.TestCase):
"""Base tests for the OAuth database classes."""
layer = DatabaseFunctionalLayer
def test__get_store_should_return_the_main_master_store(self):
"""We want all OAuth classes to use the master store.
Otherwise, the OAuth exchanges will fail because the authorize
screen won't probably find the new request token on the slave store.
"""
zstorm = getUtility(IZStorm)
self.assertEquals(
'%s-%s' % (MAIN_STORE, MASTER_FLAVOR),
zstorm.get_name(self.class_._get_store()))
class OAuthAccessTokenTestCase(BaseOAuthTestCase):
class_ = OAuthAccessToken
class OAuthRequestTokenTestCase(BaseOAuthTestCase):
class_ = OAuthRequestToken
class OAuthConsumerTestCase(BaseOAuthTestCase):
class_ = OAuthConsumer
class OAuthNonceTestCase(BaseOAuthTestCase):
class_ = OAuthNonce
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(OAuthAccessTokenTestCase),
unittest.makeSuite(OAuthRequestTokenTestCase),
unittest.makeSuite(OAuthNonceTestCase),
unittest.makeSuite(OAuthConsumerTestCase),
))
|