~gcampax/software-center/fedora

« back to all changes in this revision

Viewing changes to test/gtk3/test_custom_lists.py

  • Committer: Michael Vogt
  • Date: 2011-11-17 13:01:46 UTC
  • mfrom: (2559.1.14 software-center)
  • Revision ID: michael.vogt@ubuntu.com-20111117130146-lc5bgxd30dd0lnjz
* lp:~gary-lasker/software-center/unit-tests:
  - update tests for custom lists and for launcher integration

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