~gary-lasker/software-center/recommender-unit-test-updates

« back to all changes in this revision

Viewing changes to tests/test_database.py

mergedĀ lp:~mvo/software-center/unity-lens-plus-wildcard-fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
from tests.utils import (
14
14
    DATA_DIR,
15
15
    get_test_db,
 
16
    get_test_db_from_app_install_data,
16
17
    get_test_pkg_info,
17
18
    do_events,
18
19
    make_software_center_agent_subscription_dict,
77
78
        self.assertEqual(res, [ v2, v1, v0 ])
78
79
 
79
80
 
 
81
    def _get_db_from_test_app_install_data(self):
 
82
        db = xapian.inmemory_open()
 
83
        res = update_from_app_install_data(db, self.cache,
 
84
            datadir=os.path.join(DATA_DIR, "desktop"))
 
85
        self.assertTrue(res)
 
86
        self.assertEqual(db.get_doccount(), 5)
 
87
        return db
 
88
 
80
89
    def test_update_from_desktop_file(self):
81
90
        # ensure we index with german locales to test i18n
82
91
        os.environ["LANGUAGE"] = "de"
83
 
        db = xapian.WritableDatabase(TEST_DB,
84
 
                                     xapian.DB_CREATE_OR_OVERWRITE)
85
 
        res = update_from_app_install_data(db, self.cache,
86
 
            datadir=os.path.join(DATA_DIR, "desktop"))
87
 
        self.assertTrue(res)
88
 
        self.assertEqual(db.get_doccount(), 5)
 
92
        datadir = os.path.join(DATA_DIR, "desktop")
 
93
        db = get_test_db_from_app_install_data(datadir)
89
94
        # test if Name[de] was picked up
90
95
        i=0
91
96
        for it in db.postlist("AAUbuntu Software Zentrum"):
92
97
            i+=1
93
 
        self.assertEqual(i, 1)
94
98
 
95
99
    def test_regression_index_terms(self):
96
100
        """ this tests for a regression that we had in the term indexer
109
113
            self.assertFalse(len(t.term) == 1)
110
114
 
111
115
    def test_update_from_appstream_xml(self):
112
 
        db = xapian.WritableDatabase(TEST_DB,
113
 
                                     xapian.DB_CREATE_OR_OVERWRITE)
 
116
        db = xapian.inmemory_open()
114
117
        res = update_from_appstream_xml(db, self.cache,
115
118
            os.path.join(DATA_DIR, "app-info"))
116
119
        self.assertTrue(res)
129
132
    def test_update_from_var_lib_apt_lists(self):
130
133
        # ensure we index with german locales to test i18n
131
134
        os.environ["LANGUAGE"] = "de"
132
 
        db = xapian.WritableDatabase(TEST_DB,
133
 
                                     xapian.DB_CREATE_OR_OVERWRITE)
 
135
        db = xapian.inmemory_open()
134
136
        res = update_from_var_lib_apt_lists(db, self.cache,
135
137
            listsdir=os.path.join(DATA_DIR, "app-info"))
136
138
        self.assertTrue(res)
153
155
        self.assertTrue(found_gettext_translation)
154
156
 
155
157
    def test_update_from_json_string(self):
156
 
        db = xapian.WritableDatabase(TEST_DB,
157
 
                                     xapian.DB_CREATE_OR_OVERWRITE)
 
158
        db = xapian.inmemory_open()
158
159
        cache = apt.Cache()
159
160
        p = os.path.join(DATA_DIR, "app-info-json", "apps.json")
160
161
        res = update_from_json_string(db, cache, open(p).read(), origin=p)
162
163
        self.assertEqual(db.get_doccount(), 1)
163
164
 
164
165
    def test_build_from_software_center_agent(self):
165
 
        db = xapian.WritableDatabase(TEST_DB,
166
 
                                     xapian.DB_CREATE_OR_OVERWRITE)
 
166
        db = xapian.inmemory_open()
167
167
        cache = apt.Cache()
168
168
        # monkey patch distro to ensure we get data
169
169
        distro = softwarecenter.distro.get_distro()
359
359
        # staging does not have a valid cert
360
360
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
361
361
        cache = get_test_pkg_info()
362
 
        db = xapian.WritableDatabase(TEST_DB,
363
 
                                     xapian.DB_CREATE_OR_OVERWRITE)
 
362
        db = xapian.inmemory_open()
364
363
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
365
364
        self.assertTrue(res)
366
365
 
718
717
        self.assertEqual(app.archive_suite, "")
719
718
 
720
719
 
 
720
class XapianQueryParserWorkarounds(unittest.TestCase):
 
721
    """This TestCase demonstrates the issues around the query
 
722
       parser wildcard support if the "-" char is part of the 
 
723
       pkgname and tests the workaround for this
 
724
 
 
725
       (http://trac.xapian.org/ticket/128)
 
726
    """
 
727
 
 
728
    def setUp(self):
 
729
        datadir = os.path.join(DATA_DIR, "desktop")
 
730
        self.db = get_test_db_from_app_install_data(datadir)
 
731
 
 
732
    def test_name_mangling_for_query_parser(self):
 
733
        # test that pkgnames with "-" get added in a mangled form
 
734
        i=0
 
735
        for it in self.db.postlist("APMsoftware_center"):
 
736
            i+=1
 
737
        self.assertEqual(i, 1)
 
738
 
 
739
    def test_query_parser_wildcard(self):
 
740
        enquire = xapian.Enquire(self.db)
 
741
        parser = xapian.QueryParser()
 
742
        parser.set_database(self.db)
 
743
        parser.add_prefix("pkg_wildcard", "AP")
 
744
        # this demonstrates the xapian bug with the query parser 
 
745
        # and "-" special chars, note that once this test fails (i.e.
 
746
        # the returned mset is "1" we can remove this workaround
 
747
        query = parser.parse_query(
 
748
            "pkg_wildcard:software-*", xapian.QueryParser.FLAG_WILDCARD)
 
749
        enquire.set_query(query)
 
750
        mset = enquire.get_mset(0, 100)
 
751
        self.assertEqual(len(mset), 0)
 
752
        # and the workaround
 
753
        parser.add_prefix("pkg_wildcard", "APM")
 
754
        query = parser.parse_query(
 
755
            "pkg_wildcard:software_*", xapian.QueryParser.FLAG_WILDCARD)
 
756
        enquire.set_query(query)
 
757
        mset = enquire.get_mset(0, 100)
 
758
        self.assertEqual(len(mset), 1)
 
759
 
 
760
 
721
761
class TrackDBTestCase(unittest.TestCase):
722
762
 
723
763
    def test_track_db_open(self):