~nataliabidart/software-center/winged-migration

« back to all changes in this revision

Viewing changes to tests/test_categories.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
1
import unittest
4
2
import xapian
5
3
from mock import patch
6
4
 
7
 
from testutils import setup_test_env
 
5
from tests.utils import (
 
6
    DATA_DIR,
 
7
    get_test_db,
 
8
    make_recommender_agent_recommend_me_dict,
 
9
    setup_test_env,
 
10
)
8
11
setup_test_env()
9
12
 
10
13
from softwarecenter.db.categories import (
11
14
    CategoriesParser,
12
15
    RecommendedForYouCategory,
13
16
    get_category_by_name, get_query_for_category)
14
 
from softwarecenter.testutils import (get_test_db,
15
 
                                      make_recommender_agent_recommend_me_dict)
 
17
 
16
18
 
17
19
class TestCategories(unittest.TestCase):
18
 
    
 
20
 
19
21
    def setUp(self):
20
22
        self.db = get_test_db()
21
23
 
29
31
        self.assertTrue(agent_mock_instance.query_recommend_me.called)
30
32
        # ensure we get a query when the callback is called
31
33
        recommends_cat._recommend_me_result(
32
 
                                None, 
 
34
                                None,
33
35
                                make_recommender_agent_recommend_me_dict())
34
36
        self.assertNotEqual(recommends_cat.get_documents(self.db), [])
35
37
 
37
39
    def test_recommends_in_category_category(self, AgentMockCls):
38
40
        # ensure we use the same instance in test and code
39
41
        parser = CategoriesParser(self.db)
40
 
        cats = parser.parse_applications_menu("./data")
 
42
        cats = parser.parse_applications_menu(DATA_DIR)
41
43
        # "2" is a multimedia query
42
44
        #     see ./test/data/desktop/software-center.menu
43
45
        recommends_cat = RecommendedForYouCategory(cats[2])
44
46
        # ensure we get a query when the callback is called
45
47
        recommends_cat._recommend_me_result(
46
 
                                None, 
 
48
                                None,
47
49
                                make_recommender_agent_recommend_me_dict())
48
50
        recommendations_in_cat = recommends_cat.get_documents(self.db)
49
 
        print recommendations_in_cat
50
51
        self.assertNotEqual(recommendations_in_cat, [])
51
52
 
52
53
    def test_get_query(self):
85
86
    def setUpClass(cls):
86
87
        cls.db = get_test_db()
87
88
        cls.parser = CategoriesParser(cls.db)
88
 
        cls.cats = cls.parser.parse_applications_menu("./data/")
 
89
        cls.cats = cls.parser.parse_applications_menu(DATA_DIR)
89
90
 
90
91
    def test_category_debtags(self):
91
92
        cat = get_category_by_name(self.cats, 'Debtag')
92
93
        self.assertEqual(
93
 
            "%s" % cat.query, 
 
94
            "%s" % cat.query,
94
95
            "Xapian::Query((<alldocuments> AND XTregion::de))")
95
96
 
96
97
    @patch("softwarecenter.db.categories.get_region_cached")
97
98
    def test_category_dynamic_categories(self, mock_get_region_cached):
98
 
        mock_get_region_cached.return_value = { "countrycode" : "us", 
 
99
        mock_get_region_cached.return_value = { "countrycode" : "us",
99
100
                                              }
100
101
        parser = CategoriesParser(self.db)
101
 
        cats = parser.parse_applications_menu("./data/")
 
102
        cats = parser.parse_applications_menu(DATA_DIR)
102
103
        cat = get_category_by_name(cats, 'Dynamic')
103
104
        self.assertEqual(
104
 
            "%s" % cat.query, 
 
105
            "%s" % cat.query,
105
106
            "Xapian::Query((<alldocuments> AND XTregion::us))")
106
107
 
107
108
 
108
109
if __name__ == "__main__":
109
 
    #import logging
110
 
    #logging.basicConfig(level=logging.DEBUG)
111
110
    unittest.main()