77
78
self.assertEqual(res, [ v2, v1, v0 ])
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"))
86
self.assertEqual(db.get_doccount(), 5)
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"))
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
91
96
for it in db.postlist("AAUbuntu Software Zentrum"):
93
self.assertEqual(i, 1)
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)
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)
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)
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)
718
717
self.assertEqual(app.archive_suite, "")
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
725
(http://trac.xapian.org/ticket/128)
729
datadir = os.path.join(DATA_DIR, "desktop")
730
self.db = get_test_db_from_app_install_data(datadir)
732
def test_name_mangling_for_query_parser(self):
733
# test that pkgnames with "-" get added in a mangled form
735
for it in self.db.postlist("APMsoftware_center"):
737
self.assertEqual(i, 1)
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)
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)
721
761
class TrackDBTestCase(unittest.TestCase):
723
763
def test_track_db_open(self):