~gary-lasker/software-center/pyflakes-fixes

814.2.1 by Michael Vogt
add basic GLaunchpad gobject based backend
1
#!/usr/bin/python
2
1945.1.1 by Michael Vogt
port to gir for gobject/glib in tests/ and utils/
3
from gi.repository import GObject
4
814.2.1 by Michael Vogt
add basic GLaunchpad gobject based backend
5
import sys
6
sys.path.insert(0,"../")
7
8
import unittest
9
10
from softwarecenter.backend.launchpad import GLaunchpad
11
12
class testUbuntuSSO(unittest.TestCase):
13
14
    def setUp(self):
15
        pass
16
    
913 by Michael Vogt
test/test_launchpad.py: fix test
17
    def _cb_login_successful(self, lp, token):
814.2.1 by Michael Vogt
add basic GLaunchpad gobject based backend
18
        self._login_successful = True
19
20
    def test_launchpad_login(self):
21
        lp = GLaunchpad()
22
        lp.connect("login-successful", self._cb_login_successful)
23
        # monkey patch
24
        lp.login = lambda u,p: True
25
        lp.login("user", "password")
913 by Michael Vogt
test/test_launchpad.py: fix test
26
        lp.emit("login-successful", None)
1945.1.1 by Michael Vogt
port to gir for gobject/glib in tests/ and utils/
27
        main_loop = GObject.main_context_default()
814.2.1 by Michael Vogt
add basic GLaunchpad gobject based backend
28
        while main_loop.pending():
29
            main_loop.iteration()
30
        self.assertTrue(self._login_successful)
31
    
32
    def _monkey_get_subscribed_archives(self):
33
        return ["deb http://foo:pw@launchpad.net/ main"]
34
35
    def test_launchpad_get_subscribed_archives(self):
36
        lp = GLaunchpad()
37
        lp.get_subscribed_archives = self._monkey_get_subscribed_archives
38
        archives = lp.get_subscribed_archives()
39
        self.assertEqual(archives, ["deb http://foo:pw@launchpad.net/ main"])
40
41
if __name__ == "__main__":
42
    import logging
43
    logging.basicConfig(level=logging.DEBUG)
44
    unittest.main()