~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to tests/test_testutils.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import unittest
2
2
 
3
3
import dbus
4
 
import time
5
 
from gi.repository import GObject
6
4
 
7
5
from tests.utils import (
 
6
    do_events_with_sleep,
8
7
    setup_test_env,
9
8
    start_dummy_backend,
10
9
    stop_dummy_backend,
 
10
    get_mock_app_properties_helper,
 
11
    url_accessable,
11
12
)
12
13
setup_test_env()
13
14
 
15
16
from softwarecenter.backend.installbackend_impl.aptd import get_dbus_bus
16
17
 
17
18
 
18
 
class TestTestUtils(unittest.TestCase):
 
19
class DummyBackendTestUtilsTestCase(unittest.TestCase):
19
20
 
20
21
    def setUp(self):
21
22
        start_dummy_backend()
32
33
        # get names and ...
33
34
        names = bus.list_names()
34
35
        # ensure we have the  following:
35
 
        #  org.freedesktop.DBus, 
 
36
        #  org.freedesktop.DBus,
36
37
        #  org.freedesktop.PolicyKit1
37
38
        #  org.debian.apt
38
39
        # (and :1.0, :1.1, :1.2)
39
40
        self.assertEqual(len(names), 6)
40
41
 
41
42
    def test_fake_aptd(self):
42
 
        from softwarecenter.backend import get_install_backend
 
43
        from softwarecenter.backend.installbackend import get_install_backend
43
44
        backend = get_install_backend()
44
45
        backend.install(Application("2vcard", ""), iconname="")
45
 
        self._p()
46
 
 
47
 
    def _p(self):
48
 
        context = GObject.main_context_default()
49
 
        for i in range(10):
50
 
            while context.pending():
51
 
                context.iteration()
52
 
            time.sleep(0.1)
53
 
 
 
46
        do_events_with_sleep()
 
47
 
 
48
 
 
49
class TestUtilsTestCase(unittest.TestCase):
 
50
 
 
51
    def test_app_properties_helper_mock_with_defaults(self):
 
52
        app_properties_helper = get_mock_app_properties_helper()
 
53
        self.assertEqual(
 
54
            app_properties_helper.get_pkgname(None), "apkg")
 
55
 
 
56
    def test_app_properties_helper_mock_with_custom_values(self):
 
57
        my_defaults = {'pkgname': 'diemoldau',
 
58
                      }
 
59
        app_properties_helper = get_mock_app_properties_helper(my_defaults)
 
60
        self.assertEqual(
 
61
            app_properties_helper.get_pkgname(None), "diemoldau")
 
62
 
 
63
    def test_url_accessable(self):
 
64
        self.assertTrue(
 
65
            url_accessable("http://archive.ubuntu.com/ubuntu/", "dists/"))
 
66
        self.assertFalse(
 
67
            url_accessable("http://archive.ubuntu.com/ubuntu/",
 
68
                           "mooobaalalala"))
 
69
    
54
70
 
55
71
if __name__ == "__main__":
56
72
    unittest.main()