~mvo/software-center/trivial-renaming

1444 by Michael Vogt
test/test_gwibber.py, softwarecenter/gwibber_helper.py: fix gwibber tests
1
import os
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
2
import unittest
2653.1.2 by Michael Vogt
further cleanup to avoid fiddling with sys.path in every test file
3
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
4
Gwibber = None
5
try:
6
    from gi.repository import Gwibber
7
except ImportError:
8
    pass
9
3020.1.1 by Natalia B. Bidart
- Initial test cleanup:
10
from tests.utils import (
11
    setup_test_env,
12
)
2653.1.2 by Michael Vogt
further cleanup to avoid fiddling with sys.path in every test file
13
setup_test_env()
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
14
from softwarecenter.gwibber_helper import GwibberHelper, GwibberHelperMock
15
16
NOT_DEFINED = object()
17
18
19
@unittest.skipIf(Gwibber is None,
20
    "Please install the gwibber gir bindings to run this test case.")
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
21
class TestGwibber(unittest.TestCase):
3020.1.1 by Natalia B. Bidart
- Initial test cleanup:
22
    """Tests the "where is it in the menu" code."""
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
23
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
24
    patch_vars = (("SOFTWARE_CENTER_GWIBBER_MOCK_USERS", "2"),
25
                  ("SOFTWARE_CENTER_GWIBBER_MOCK_NO_FAIL", "1"))
26
27
    def setUp(self):
28
        for env_var, value in self.patch_vars:
29
            real = os.environ.get(env_var, NOT_DEFINED)
30
            if real is NOT_DEFINED:
31
                self.addCleanup(os.environ.pop, env_var)
32
            else:
33
                self.addCleanup(os.environ.__setitem__, env_var, real)
34
            os.environ[env_var] = value
35
1444 by Michael Vogt
test/test_gwibber.py, softwarecenter/gwibber_helper.py: fix gwibber tests
36
    def test_gwibber_helper_mock(self):
37
        gh = GwibberHelperMock()
38
        accounts = gh.accounts()
39
        self.assertEqual(len(accounts), 2)
40
        #print accounts
41
        # we can not test the real gwibber here, otherwise it will
42
        # post our test data to real services
43
        self.assertEqual(gh.send_message ("test"), True)
44
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
45
    def test_gwibber_helper(self):
1444 by Michael Vogt
test/test_gwibber.py, softwarecenter/gwibber_helper.py: fix gwibber tests
46
        # readonly test as there maybe be real accounts
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
47
        gh = GwibberHelper()
1444 by Michael Vogt
test/test_gwibber.py, softwarecenter/gwibber_helper.py: fix gwibber tests
48
        have_accounts = gh.has_accounts_in_sqlite()
49
        self.assertTrue(isinstance(have_accounts, bool))
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
50
        accounts = gh.accounts()
1444 by Michael Vogt
test/test_gwibber.py, softwarecenter/gwibber_helper.py: fix gwibber tests
51
        self.assertTrue(isinstance(accounts, list))
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
52
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
53
    @unittest.skip('not_working_because_gi_does_not_provide_list_test_gwibber')
54
    def test_gwibber_send_message(self):
55
        service = Gwibber.Service()
56
        self.addCleanup(service.quit)
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
57
        # get account data
58
        accounts = Gwibber.Accounts()
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
59
        # print dir(accounts)
60
        self.assertTrue(len(accounts.list()) > 0)
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
61
        # check single account for send enabled, only do if "True"
62
        #print accounts.send_enabled(accounts.list[0])
63
        # first check gwibber available
64
        service = Gwibber.Service()
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
65
        # print dir(service)
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
66
        service.service_available(False)
3020.1.3 by Natalia B. Bidart
- Got all tests passing but only ig each one is run on a different python
67
        service.send_message("test")
68
1247.1.118 by Michael Vogt
add gwibber helper for the reviews stuff
69
70
if __name__ == "__main__":
71
    unittest.main()