~nataliabidart/software-center/winged-migration

« back to all changes in this revision

Viewing changes to tests/gtk3/test_custom_lists.py

  • Committer: Natalia B. Bidart
  • Date: 2012-05-30 18:39:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3030.
  • Revision ID: natalia.bidart@canonical.com-20120530183955-zbnjczayktmmg5tv
- Initial test cleanup:
  - Renamed test/ dir to tests/.
  - Isolated test code into tests/ directory, including moving all the
    get_test_window_foo from the gtk3 production modules to
    tests/gtk3/windows.py module.
  - Removed all the calls to Gtk.main() in gtk3 tests since that blocks the
    execution of the suite.
  - Pep8 and pyflakes fixes in the files already modified in this branch.
  - Minor bug fix in the softwarecenter/log.py module when trying to create a
    log dir with proper perms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
from gi.repository import Gtk, GObject
4
 
import time
5
1
import unittest
6
2
 
7
 
from testutils import setup_test_env
 
3
from tests.utils import (
 
4
    do_events_with_sleep,
 
5
    setup_test_env,
 
6
)
8
7
setup_test_env()
9
8
 
10
9
from softwarecenter.enums import XapianValues, ActionButtons
 
10
from tests.gtk3.windows import get_test_window_availablepane
11
11
 
12
 
TIMEOUT=300
13
12
 
14
13
class TestCustomLists(unittest.TestCase):
15
14
 
16
 
    def _debug(self, index, model, needle):
17
 
        print ("Expected '%s' at index '%s', " +
18
 
               "and custom list contained: '%s'") % (
19
 
                needle, index, model[index][0].get_value(XapianValues.PKGNAME))
20
 
 
21
15
    def assertPkgInListAtIndex(self, index, model, needle):
22
 
        doc = model[index][0]
23
 
        self.assertEqual(doc.get_value(XapianValues.PKGNAME), 
24
 
                         needle, self._debug(index, model, needle))
 
16
        doc_name = model[index][0].get_value(XapianValues.PKGNAME)
 
17
        msg = "Expected %r at index %r, and custom list contained: %r"
 
18
        self.assertEqual(doc_name, needle, msg % (needle, index, doc_name))
25
19
 
26
20
    def test_custom_lists(self):
27
 
        from softwarecenter.ui.gtk3.panes.availablepane import get_test_window
28
 
        win = get_test_window()
 
21
        win = get_test_window_availablepane()
 
22
        self.addCleanup(win.destroy)
29
23
        pane = win.get_data("pane")
30
 
        self._p()
 
24
        do_events_with_sleep()
31
25
        pane.on_search_terms_changed(None, "ark,artha,software-center")
32
 
        self._p()
 
26
        do_events_with_sleep()
33
27
        model = pane.app_view.tree_view.get_model()
34
 
        
 
28
 
35
29
        # custom list should return three items
36
30
        self.assertTrue(len(model) == 3)
37
 
        
 
31
 
38
32
        # check package names, ordering is default "by relevance"
39
33
        self.assertPkgInListAtIndex(0, model, "ark")
40
34
        self.assertPkgInListAtIndex(1, model, "software-center")
41
35
        self.assertPkgInListAtIndex(2, model, "artha")
42
 
        
 
36
 
43
37
        # check that the status bar offers to install the packages
44
38
        install_button = pane.action_bar.get_button(ActionButtons.INSTALL)
45
39
        self.assertNotEqual(install_button, None)
46
 
        
47
 
        GObject.timeout_add(TIMEOUT, lambda: win.destroy())
48
 
        Gtk.main()
49
 
        
50
 
    def _p(self):
51
 
        for i in range(10):
52
 
            time.sleep(0.1)
53
 
            while Gtk.events_pending():
54
 
                Gtk.main_iteration()
55
40
 
56
41
 
57
42
if __name__ == "__main__":
58
 
    import logging
59
 
    logging.basicConfig(level=logging.INFO)
60
43
    unittest.main()
61