~mmcg069/software-center/tweaks

« back to all changes in this revision

Viewing changes to test/test_database.py

  • Committer: Michael Vogt
  • Date: 2011-05-18 08:26:04 UTC
  • mto: This revision was merged to the branch mainline in revision 1789.
  • Revision ID: michael.vogt@ubuntu.com-20110518082604-00wiq50tjd9vedz6
tests/: make pyflakes clean, fixup test_build_from_software_center_agent()

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from softwarecenter.db.database import parse_axi_values_file
17
17
from softwarecenter.db.pkginfo import get_pkg_info
18
18
from softwarecenter.db.update import update_from_app_install_data, update_from_var_lib_apt_lists, update_from_appstream_xml
19
 
from softwarecenter.paths import *
20
 
from softwarecenter.enums import *
 
19
from softwarecenter.enums import (
 
20
    XAPIAN_VALUE_ARCHIVE_PPA,
 
21
    XAPIAN_VALUE_ICON,
 
22
    PKG_STATE_INSTALLED,
 
23
    PKG_STATE_NEEDS_SOURCE,
 
24
    PKG_STATE_NEEDS_PURCHASE,
 
25
    PKG_STATE_NOT_FOUND,
 
26
    )
21
27
 
22
28
class TestDatabase(unittest.TestCase):
23
29
    """ tests the store database """
96
102
        db = xapian.WritableDatabase("./data/test.db", 
97
103
                                     xapian.DB_CREATE_OR_OVERWRITE)
98
104
        cache = apt.Cache()
99
 
        # we test against the real https://sc.ubuntu.com so we need network
100
 
        res = update_from_software_center_agent(db, cache)
101
 
        # sofware-center.ubuntu.com down; film at 11
102
 
        return
 
105
        # monkey patch distro to ensure we get data
 
106
        import softwarecenter.distro
 
107
        distro = softwarecenter.distro.get_distro()
 
108
        distro.get_codename = lambda: "natty"
 
109
        # we test against the real https://software-center.ubuntu.com here
 
110
        # so we need network
 
111
        res = update_from_software_center_agent(db, cache, ignore_etag=True)
 
112
        # check results
103
113
        self.assertTrue(res)
104
 
        self.assertEqual(db.get_doccount(), 1)
 
114
        self.assertTrue(db.get_doccount() > 1)
105
115
        for p in db.postlist(""):
106
116
            doc = db.get_document(p.docid)
107
 
            self.assertTrue(doc.get_value(XAPIAN_VALUE_ARCHIVE_PPA),
108
 
                            "pay-owner/pay-ppa-name")
109
 
            self.assertTrue(doc.get_value(XAPIAN_VALUE_ICON).startswith("sc-agent"))
 
117
            ppa = doc.get_value(XAPIAN_VALUE_ARCHIVE_PPA)
 
118
            self.assertTrue(ppa.startswith("commercial-ppa") and
 
119
                            ppa.count("/") == 1)
 
120
            self.assertTrue(
 
121
                doc.get_value(XAPIAN_VALUE_ICON).startswith("sc-agent"))
110
122
        
111
123
    def test_application(self):
112
124
        db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
118
130
        db = xapian.WritableDatabase("./data/test.db", 
119
131
                                     xapian.DB_CREATE_OR_OVERWRITE)
120
132
        res = update_from_app_install_data(db, self.cache, datadir="./data/")
 
133
        self.assertTrue(res)
121
134
        db = StoreDatabase("./data/test.db", self.cache)
122
135
        db.open(use_axi=False, use_agent=False)
123
136
        self.assertEqual(len(db), 5)
194
207
        db = xapian.WritableDatabase("./data/test.db", 
195
208
                                     xapian.DB_CREATE_OR_OVERWRITE)
196
209
        res = update_from_app_install_data(db, self.cache, datadir="./data/")
 
210
        self.assertTrue(res)
197
211
        db = StoreDatabase("./data/test.db", self.cache)
198
212
        db.open(use_axi=False)
199
213
        # test PKG_STATE_INSTALLED
248
262
        db = xapian.WritableDatabase("./data/test.db", 
249
263
                                     xapian.DB_CREATE_OR_OVERWRITE)
250
264
        res = update_from_app_install_data(db, self.cache, datadir="./data/")
 
265
        self.assertTrue(res)
251
266
        db = StoreDatabase("./data/test.db", self.cache)
252
267
        db.open(use_axi=True)
253
268
 
283
298
app-popcon      4       # app-install .desktop popcon rank
284
299
"""
285
300
        open("axi-test-values","w").write(s)
286
 
        db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
 
301
        #db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
287
302
        axi_values = parse_axi_values_file("axi-test-values")
288
303
        self.assertNotEqual(axi_values, {})
289
304
        print axi_values