~paolorotolo/software-center/fix-for-963309

« back to all changes in this revision

Viewing changes to test/test_database.py

  • Committer: Danny Tamez
  • Date: 2012-01-19 16:17:34 UTC
  • mfrom: (2682 trunk)
  • mto: This revision was merged to the branch mainline in revision 2683.
  • Revision ID: danny.tamez@canonical.com-20120119161734-8viwvv83ph9d4kfx
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    def test_update_from_desktop_file(self):
37
37
        # ensure we index with german locales to test i18n
38
38
        os.environ["LANGUAGE"] = "de"
39
 
        db = xapian.WritableDatabase("./data/test.db", 
 
39
        db = xapian.WritableDatabase("./data/test.db",
40
40
                                     xapian.DB_CREATE_OR_OVERWRITE)
41
41
        res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
42
42
        self.assertTrue(res)
48
48
        self.assertEqual(i, 1)
49
49
 
50
50
    def test_update_from_appstream_xml(self):
51
 
        db = xapian.WritableDatabase("./data/test.db", 
 
51
        db = xapian.WritableDatabase("./data/test.db",
52
52
                                     xapian.DB_CREATE_OR_OVERWRITE)
53
53
        res = update_from_appstream_xml(db, self.cache, "./data/app-info/")
54
54
        self.assertTrue(res)
64
64
    def test_update_from_var_lib_apt_lists(self):
65
65
        # ensure we index with german locales to test i18n
66
66
        os.environ["LANGUAGE"] = "de"
67
 
        db = xapian.WritableDatabase("./data/test.db", 
 
67
        db = xapian.WritableDatabase("./data/test.db",
68
68
                                     xapian.DB_CREATE_OR_OVERWRITE)
69
69
        res = update_from_var_lib_apt_lists(db, self.cache, listsdir="./data/app-info/")
70
70
        self.assertTrue(res)
88
88
 
89
89
    def test_update_from_json_string(self):
90
90
        from softwarecenter.db.update import update_from_json_string
91
 
        db = xapian.WritableDatabase("./data/test.db", 
 
91
        db = xapian.WritableDatabase("./data/test.db",
92
92
                                     xapian.DB_CREATE_OR_OVERWRITE)
93
93
        cache = apt.Cache()
94
94
        p = os.path.abspath("./data/app-info-json/apps.json")
97
97
        self.assertEqual(db.get_doccount(), 1)
98
98
 
99
99
    def test_build_from_software_center_agent(self):
100
 
        db = xapian.WritableDatabase("./data/test.db", 
 
100
        db = xapian.WritableDatabase("./data/test.db",
101
101
                                     xapian.DB_CREATE_OR_OVERWRITE)
102
102
        cache = apt.Cache()
103
103
        # monkey patch distro to ensure we get data
114
114
            doc = db.get_document(p.docid)
115
115
            ppa = doc.get_value(XapianValues.ARCHIVE_PPA)
116
116
            self.assertTrue(ppa.startswith("commercial-ppa") and
117
 
                            ppa.count("/") == 1, 
 
117
                            ppa.count("/") == 1,
118
118
                            "ARCHIVE_PPA value incorrect, got '%s'" % ppa)
119
119
            self.assertTrue(
120
120
                "-icon-" in doc.get_value(XapianValues.ICON))
127
127
    def test_license_string_data_from_software_center_agent(self):
128
128
        from softwarecenter.testutils import get_test_pkg_info
129
129
        #os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
130
 
        os.environ["SOFTWARE_CENTER_BUY_HOST"] = "http://sc.staging.ubuntu.com/"
 
130
        os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
131
131
        # staging does not have a valid cert
132
132
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
133
133
        cache = get_test_pkg_info()
134
 
        db = xapian.WritableDatabase("./data/test.db", 
 
134
        db = xapian.WritableDatabase("./data/test.db",
135
135
                                     xapian.DB_CREATE_OR_OVERWRITE)
136
136
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
137
137
        self.assertTrue(res)
140
140
            license = doc.get_value(XapianValues.LICENSE)
141
141
            self.assertNotEqual(license, "")
142
142
            self.assertNotEqual(license, None)
143
 
        del os.environ["SOFTWARE_CENTER_BUY_HOST"]
 
143
        del os.environ["SOFTWARE_CENTER_AGENT_HOST"]
144
144
 
145
145
    def test_application(self):
146
146
        db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
149
149
        self.assertRaises(ValueError, AppDetails, db)
150
150
 
151
151
    def test_application_details(self):
152
 
        db = xapian.WritableDatabase("./data/test.db", 
 
152
        db = xapian.WritableDatabase("./data/test.db",
153
153
                                     xapian.DB_CREATE_OR_OVERWRITE)
154
154
        res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
155
155
        self.assertTrue(res)
191
191
        self.assertTrue(len(appdetails.version) > 2)
192
192
        # FIXME: screenshots will only work on ubuntu
193
193
        self.assertTrue(re.match(
194
 
                "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+", 
 
194
                "http://screenshots.ubuntu.com/screenshot-with-version/software-center/[\d.]+",
195
195
                appdetails.screenshot))
196
196
        self.assertTrue(re.match(
197
197
                "http://screenshots.ubuntu.com/thumbnail-with-version/software-center/[\d.]+",
210
210
        from softwarecenter.distro import get_distro
211
211
        distro = get_distro().get_codename()
212
212
        self.assertEqual(app.request, 'channel=' + distro + '-partner')
213
 
        
 
213
 
214
214
    def ensure_installation_date_and_lazy_history_loading(self, appdetails):
215
 
        # we run two tests, the first is to ensure that we get a 
 
215
        # we run two tests, the first is to ensure that we get a
216
216
        # result from installation_data immediately (at this point the
217
217
        # history is not loaded yet) so we expect "None"
218
218
        self.assertEqual(appdetails.installation_date, None)
227
227
        self.assertNotEqual(appdetails.installation_date, None)
228
228
 
229
229
    def test_package_states(self):
230
 
        db = xapian.WritableDatabase("./data/test.db", 
 
230
        db = xapian.WritableDatabase("./data/test.db",
231
231
                                     xapian.DB_CREATE_OR_OVERWRITE)
232
232
        res = update_from_app_install_data(db, self.cache, datadir="./data/desktop")
233
233
        self.assertTrue(res)
282
282
            doc = m.document
283
283
            doc.get_value(value_time) >= last_time
284
284
            last_time = doc.get_value(value_time)
285
 
            
 
285
 
286
286
    # FIXME: re-enable both tests once sc.staging.ubuntu.com has the new
287
287
    #        version of scagent with support for the publication date
288
288
    def disabled_test_for_purchase_apps_date_published(self):
289
289
        from softwarecenter.testutils import get_test_pkg_info
290
290
        #os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
291
 
        os.environ["SOFTWARE_CENTER_BUY_HOST"] = "http://sc.staging.ubuntu.com/"
 
291
        os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
292
292
        # staging does not have a valid cert
293
293
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
294
294
        cache = get_test_pkg_info()
295
 
        db = xapian.WritableDatabase("./data/test.db", 
 
295
        db = xapian.WritableDatabase("./data/test.db",
296
296
                                     xapian.DB_CREATE_OR_OVERWRITE)
297
297
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
298
298
        self.assertTrue(res)
299
 
        
 
299
 
300
300
        for p in db.postlist(""):
301
301
            doc = db.get_document(p.docid)
302
302
            date_published = doc.get_value(XapianValues.DATE_PUBLISHED)
303
303
            # make sure that a date_published value is provided
304
304
            self.assertNotEqual(date_published, "")
305
305
            self.assertNotEqual(date_published, None)
306
 
        del os.environ["SOFTWARE_CENTER_BUY_HOST"]
307
 
        
 
306
        del os.environ["SOFTWARE_CENTER_AGENT_HOST"]
 
307
 
308
308
    def disabled_test_for_purchase_apps_cataloged_time(self):
309
309
        from softwarecenter.testutils import get_test_pkg_info
310
310
        #os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
311
 
        os.environ["SOFTWARE_CENTER_BUY_HOST"] = "http://sc.staging.ubuntu.com/"
 
311
        os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
312
312
        # staging does not have a valid cert
313
313
        os.environ["PISTON_MINI_CLIENT_DISABLE_SSL_VALIDATION"] = "1"
314
314
        cache = get_test_pkg_info()
315
 
        db = xapian.WritableDatabase("./data/test.db", 
 
315
        db = xapian.WritableDatabase("./data/test.db",
316
316
                                     xapian.DB_CREATE_OR_OVERWRITE)
317
317
        res = update_from_software_center_agent(db, cache, ignore_cache=True)
318
318
        self.assertTrue(res)
333
333
        # later time than axi package Ubuntu Software Center
334
334
        self.assertTrue(for_purch_cataloged_time > sc_cataloged_time)
335
335
 
336
 
        del os.environ["SOFTWARE_CENTER_BUY_HOST"]
 
336
        del os.environ["SOFTWARE_CENTER_AGENT_HOST"]
337
337
 
338
338
    def test_parse_axi_values_file(self):
339
339
        s = """