~mvo/software-center/lp955005

1046.1.1 by Michael Vogt
start on "where is it" implementation
1
#!/usr/bin/python
2
1782.3.4 by Michael Vogt
tests/: make pyflakes clean, fixup test_build_from_software_center_agent()
3
import os
1046.1.1 by Michael Vogt
start on "where is it" implementation
4
import unittest
5
2653.1.2 by Michael Vogt
further cleanup to avoid fiddling with sys.path in every test file
6
from testutils import setup_test_env
7
setup_test_env()
1471 by Michael Vogt
* softwarecenter/paths.py:
8
from softwarecenter.paths import XAPIAN_BASE_PATH
2142 by Michael Vogt
test/test_where_is_it.py, test/test_where_is_it_gtk2.py: fix tests
9
from softwarecenter.ui.gtk3.gmenusearch import GMenuSearcher
1773.1.5 by Michael Vogt
move AptCache out of the source and info the pkginfo abstraction
10
from softwarecenter.db.pkginfo import get_pkg_info
1046.1.1 by Michael Vogt
start on "where is it" implementation
11
from softwarecenter.db.database import StoreDatabase
1782.3.4 by Michael Vogt
tests/: make pyflakes clean, fixup test_build_from_software_center_agent()
12
from softwarecenter.db.application import Application
1046.1.1 by Michael Vogt
start on "where is it" implementation
13
14
15
class TestWhereIsit(unittest.TestCase):
16
    """ tests the "where is it in the menu" code """
17
18
    def setUp(self):
1773.1.5 by Michael Vogt
move AptCache out of the source and info the pkginfo abstraction
19
        cache = get_pkg_info()
1046.1.2 by Michael Vogt
move main_menu_path_for_desktop_file into utils.py
20
        cache.open()
1046.1.1 by Michael Vogt
start on "where is it" implementation
21
        xapian_base_path = XAPIAN_BASE_PATH
22
        pathname = os.path.join(xapian_base_path, "xapian")
23
        self.db = StoreDatabase(pathname, cache)
24
        self.db.open()
25
1831 by Michael Vogt
fix tests (mostly updating to the new enums style)
26
    # mvo: disabled for now (2011-06-06) because the new gnome-panel
27
    #      does not have "System" anymore and its not clear to me yet
28
    #      where those items will appear. Once that is settled it
29
    #      should be re-enabled
30
    def disabled_for_now_test_where_is_it_in_system(self):
1046.1.1 by Michael Vogt
start on "where is it" implementation
31
        app = Application("Hardware Drivers", "jockey-gtk")
32
        details = app.get_details(self.db)
33
        self.assertEqual(details.desktop_file, 
34
                         "/usr/share/app-install/desktop/jockey-gtk.desktop")
35
        # search the settings menu
1046.1.3 by Michael Vogt
cleanup and make searcher a class
36
        searcher = GMenuSearcher()
37
        found = searcher.get_main_menu_path(details.desktop_file)
1831 by Michael Vogt
fix tests (mostly updating to the new enums style)
38
        self.assertEqual(found[0].get_name(), "Desktop")
1046.1.2 by Michael Vogt
move main_menu_path_for_desktop_file into utils.py
39
        self.assertEqual(found[0].get_icon(), "preferences-other")
40
        self.assertEqual(found[1].get_name(), "Administration")
41
        self.assertEqual(found[1].get_icon(), "preferences-system")
42
43
    def test_where_is_it_in_applications(self):
44
        app = Application("Calculator", "gcalctool")
45
        details = app.get_details(self.db)
46
        self.assertEqual(details.desktop_file, 
2038 by Michael Vogt
* pyflakes fixes
47
                         "/usr/share/app-install/desktop/gcalctool:gcalctool.desktop")
1046.1.2 by Michael Vogt
move main_menu_path_for_desktop_file into utils.py
48
        # search the settings menu
1046.1.3 by Michael Vogt
cleanup and make searcher a class
49
        searcher = GMenuSearcher()
1288 by Michael Vogt
test/test_where_is_it.py, test/data/fake-applications.menu:
50
        found = searcher.get_main_menu_path(
51
            details.desktop_file,
52
            [os.path.abspath("./data/fake-applications.menu")])
1046.1.2 by Michael Vogt
move main_menu_path_for_desktop_file into utils.py
53
        self.assertEqual(found[0].get_name(), "Applications")
2099.1.3 by Michael Vogt
* softwarecenter/gmenusearch.py:
54
        self.assertEqual(found[0].get_icon().get_names()[0], 
55
                         "applications-other")
1046.1.2 by Michael Vogt
move main_menu_path_for_desktop_file into utils.py
56
        self.assertEqual(found[1].get_name(), "Accessories")
2099.1.3 by Michael Vogt
* softwarecenter/gmenusearch.py:
57
        self.assertEqual(found[1].get_icon().get_names()[0], 
58
                         "applications-utilities")
1197 by Michael Vogt
fix where-is-it for kde4 apps (LP: #635684)
59
    
60
    def test_where_is_it_kde4(self):
61
        app = Application("", "ark")
62
        details = app.get_details(self.db)
63
        self.assertEqual(details.desktop_file, 
2038 by Michael Vogt
* pyflakes fixes
64
                         "/usr/share/app-install/desktop/ark:kde4__ark.desktop")
1197 by Michael Vogt
fix where-is-it for kde4 apps (LP: #635684)
65
        # search the settings menu
66
        searcher = GMenuSearcher()
1288 by Michael Vogt
test/test_where_is_it.py, test/data/fake-applications.menu:
67
        found = searcher.get_main_menu_path(
68
            details.desktop_file,
69
            [os.path.abspath("./data/fake-applications.menu")])
1197 by Michael Vogt
fix where-is-it for kde4 apps (LP: #635684)
70
        self.assertEqual(found[0].get_name(), "Applications")
2099.1.3 by Michael Vogt
* softwarecenter/gmenusearch.py:
71
        self.assertEqual(found[0].get_icon().get_names()[0], 
72
                         "applications-other")
1197 by Michael Vogt
fix where-is-it for kde4 apps (LP: #635684)
73
        self.assertEqual(found[1].get_name(), "Accessories")
2099.1.3 by Michael Vogt
* softwarecenter/gmenusearch.py:
74
        self.assertEqual(found[1].get_icon().get_names()[0], 
75
                         "applications-utilities")
1046.1.1 by Michael Vogt
start on "where is it" implementation
76
        
77
78
if __name__ == "__main__":
79
    import logging
80
    logging.basicConfig(level=logging.DEBUG)
81
    unittest.main()