~juliank/software-center/debian

« back to all changes in this revision

Viewing changes to test/test_ubuntu_sso_api.py

  • Committer: Julian Andres Klode
  • Date: 2011-11-20 13:34:41 UTC
  • mfrom: (429.62.1824 software-center)
  • Revision ID: jak@debian.org-20111120133441-npw6j3nmd8v75yav
Merge from 2.0.7 up to 5.1.2 pre-release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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()