1839.2.1
by Michael Vogt
merged from lp:~aaronp/software-center/tests and tweak a little bit |
1 |
#!/usr/bin/python
|
2 |
||
3 |
||
4 |
import sys |
|
5 |
sys.path.insert(0,"../") |
|
6 |
||
7 |
import os |
|
8 |
import unittest |
|
9 |
from softwarecenter.backend.restfulclient import (UbuntuSSOAPIFake, |
|
10 |
UbuntuSSOAPI, |
|
11 |
get_ubuntu_sso_backend, |
|
12 |
)
|
|
13 |
||
14 |
class TestSSOAPI(unittest.TestCase): |
|
15 |
""" tests the ubuntu sso backend stuff """
|
|
16 |
||
17 |
def test_fake_and_real_provide_similar_methods(self): |
|
18 |
""" test if the real and fake sso provide the same functions """
|
|
19 |
sso_real = UbuntuSSOAPI |
|
20 |
sso_fake = UbuntuSSOAPIFake |
|
21 |
# ensure that both fake and real implement the same methods
|
|
22 |
self.assertEqual( |
|
23 |
set([x for x in dir(sso_real) if not x.startswith("_")]), |
|
24 |
set([x for x in dir(sso_fake) if not x.startswith("_")])) |
|
25 |
||
26 |
def test_get_ubuntu_backend(self): |
|
27 |
token = { 'token' : 'tokenvalue', |
|
28 |
'token_secret' : 'tokensecretvalue', |
|
29 |
'consumer_key' : 'consumerkeyvalue', |
|
30 |
'consumer_secret' : 'consumersecretvalue', |
|
31 |
}
|
|
32 |
# test that we get the real one
|
|
33 |
self.assertEqual(type(get_ubuntu_sso_backend(token)), |
|
34 |
UbuntuSSOAPI) |
|
35 |
# test that we get the fake one
|
|
36 |
os.environ["SOFTWARE_CENTER_FAKE_REVIEW_API"] = "1" |
|
37 |
self.assertEqual(type(get_ubuntu_sso_backend(token)), |
|
38 |
UbuntuSSOAPIFake) |
|
39 |
# clean the environment
|
|
40 |
del os.environ["SOFTWARE_CENTER_FAKE_REVIEW_API"] |
|
41 |
||
42 |
||
43 |
if __name__ == "__main__": |
|
44 |
import logging |
|
45 |
logging.basicConfig(level=logging.DEBUG) |
|
46 |
unittest.main() |