~mmcg069/software-center/multi-screenshot-gallery

« back to all changes in this revision

Viewing changes to test/gtk3/test_appview.py

  • Committer: Michael Vogt
  • Date: 2011-10-07 10:44:12 UTC
  • mfrom: (2434.4.4 sort-sel-tweaks)
  • Revision ID: michael.vogt@ubuntu.com-20111007104412-j5llcrzi4zia04re
* lp:~mmcg069/software-center/bug861778:
  - improved method, use less widgets and fix case where user 
    changes sort method in a search results list (LP: #861778)

* test/gtk3/test_appview.py:
  - add regression test for bug #861778

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 mock import Mock
 
12
 
 
13
TIMEOUT=300
 
14
 
 
15
import softwarecenter.paths
 
16
softwarecenter.paths.datadir = "../data"
 
17
 
 
18
class TestViews(unittest.TestCase):
 
19
 
 
20
    def test_appview_search_combo(self):
 
21
        from softwarecenter.ui.gtk3.views.appview import get_test_window
 
22
        from softwarecenter.testutils import get_test_enquirer_matches
 
23
 
 
24
        # test if combox sort option "by relevance" vanishes for non-searches
 
25
        # LP: #861778
 
26
        expected_normal = ["By Name", "By Top Rated", "By Newest First"]
 
27
        expected_search = ["By Name", "By Top Rated", "By Newest First", 
 
28
                           "By Relevance"]
 
29
 
 
30
        # setup goo
 
31
        win = get_test_window()
 
32
        self._p()
 
33
        appview = win.get_data("appview")
 
34
 
 
35
        # test normal window (no search)
 
36
        model = appview.sort_methods_combobox.get_model()
 
37
        # collect items in the model
 
38
        in_model = []
 
39
        for item in model:
 
40
            in_model.append(model.get_value(item.iter, 0))
 
41
        # this is what we expect there
 
42
        self.assertEqual(expected_normal, in_model)
 
43
 
 
44
        # now repeat and simulate a search
 
45
        matches = get_test_enquirer_matches(appview.helper.db)
 
46
        appview.display_matches(matches, is_search=True)
 
47
        self._p()
 
48
        in_model = []
 
49
        for item in model:
 
50
            in_model.append(model.get_value(item.iter, 0))
 
51
        self.assertEqual(in_model, expected_search)
 
52
 
 
53
        # and back again to no search
 
54
        matches = get_test_enquirer_matches(appview.helper.db)
 
55
        appview.display_matches(matches, is_search=False)
 
56
        self._p()
 
57
        # collect items in the model
 
58
        in_model = []
 
59
        for item in model:
 
60
            in_model.append(model.get_value(item.iter, 0))
 
61
        self.assertEqual(expected_normal, in_model)
 
62
 
 
63
        # destroy
 
64
        GObject.timeout_add(TIMEOUT, lambda: win.destroy())
 
65
        Gtk.main()
 
66
 
 
67
    def _p(self):
 
68
        for i in range(10):
 
69
            time.sleep(0.1)
 
70
            while Gtk.events_pending():
 
71
                Gtk.main_iteration()
 
72
 
 
73
if __name__ == "__main__":
 
74
    import logging
 
75
    logging.basicConfig(level=logging.DEBUG)
 
76
    unittest.main()