|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
1 |
#!/usr/bin/python
|
2 |
||
3 |
||
4 |
import sys |
|
5 |
sys.path.insert(0,"../") |
|
6 |
||
7 |
import apt |
|
|
857.1.5
by Michael Vogt
make i18n in DesktopTagSectionParser |
8 |
import os |
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
9 |
import unittest |
|
857.1.1
by Michael Vogt
start with the code that can update using /var/lib/apt/lists |
10 |
import xapian |
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
11 |
|
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
12 |
from softwarecenter.db.application import Application, AppDetails |
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
13 |
from softwarecenter.db.database import StoreDatabase |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
14 |
from softwarecenter.db.update import update_from_app_install_data, update_from_var_lib_apt_lists |
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
15 |
from softwarecenter.enums import * |
16 |
||
17 |
class testDatabase(unittest.TestCase): |
|
18 |
""" tests the store database """
|
|
19 |
||
20 |
def setUp(self): |
|
21 |
# FIXME: create a fixture DB instead of using the system one
|
|
22 |
# but for now that does not matter that much, only if we
|
|
23 |
# call open the db is actually read and the path checked
|
|
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
24 |
self.cache = apt.Cache() |
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
25 |
self.db = StoreDatabase("/var/cache/software-center/xapian", |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
26 |
self.cache) |
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
27 |
|
28 |
def test_comma_seperation(self): |
|
29 |
# normal
|
|
30 |
querries = self.db._comma_expansion("apt,2vcard,7zip") |
|
31 |
self.assertEqual(len(querries), 3) |
|
32 |
# multiple identical
|
|
33 |
querries = self.db._comma_expansion("apt,apt,apt") |
|
34 |
self.assertEqual(len(querries), 1) |
|
35 |
# too many commas
|
|
36 |
querries = self.db._comma_expansion(",,,apt,xxx,,,") |
|
37 |
self.assertEqual(len(querries), 2) |
|
38 |
# invalid query
|
|
39 |
querries = self.db._comma_expansion("??") |
|
40 |
self.assertEqual(querries, None) |
|
41 |
||
|
857.1.2
by Michael Vogt
add dekstop file test, move to a more generic parser class so that we can parse both desktop files and tagfiles |
42 |
def test_update_from_desktop_file(self): |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
43 |
# ensure we index with german locales to test i18n
|
44 |
os.environ["LANGUAGE"] = "de" |
|
|
857.1.2
by Michael Vogt
add dekstop file test, move to a more generic parser class so that we can parse both desktop files and tagfiles |
45 |
db = xapian.WritableDatabase("./data/test.db", |
46 |
xapian.DB_CREATE_OR_OVERWRITE) |
|
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
47 |
res = update_from_app_install_data(db, self.cache, datadir="./data/") |
|
857.1.2
by Michael Vogt
add dekstop file test, move to a more generic parser class so that we can parse both desktop files and tagfiles |
48 |
self.assertTrue(res) |
49 |
self.assertEqual(db.get_doccount(), 1) |
|
|
857.1.5
by Michael Vogt
make i18n in DesktopTagSectionParser |
50 |
# test if Name[de] was picked up
|
51 |
i=0 |
|
52 |
for it in db.postlist("AAUbuntu Software Zentrum"): |
|
53 |
i+=1 |
|
54 |
self.assertEqual(i, 1) |
|
|
857.1.2
by Michael Vogt
add dekstop file test, move to a more generic parser class so that we can parse both desktop files and tagfiles |
55 |
|
|
857.1.1
by Michael Vogt
start with the code that can update using /var/lib/apt/lists |
56 |
def test_update_from_var_lib_apt_lists(self): |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
57 |
# ensure we index with german locales to test i18n
|
58 |
os.environ["LANGUAGE"] = "de" |
|
|
857.1.1
by Michael Vogt
start with the code that can update using /var/lib/apt/lists |
59 |
db = xapian.WritableDatabase("./data/test.db", |
60 |
xapian.DB_CREATE_OR_OVERWRITE) |
|
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
61 |
res = update_from_var_lib_apt_lists(db, self.cache, listsdir="./data/app-info/") |
|
857.1.1
by Michael Vogt
start with the code that can update using /var/lib/apt/lists |
62 |
self.assertTrue(res) |
|
857.1.3
by Michael Vogt
make basic tagfile reader work |
63 |
self.assertEqual(db.get_doccount(), 1) |
|
857.1.5
by Michael Vogt
make i18n in DesktopTagSectionParser |
64 |
# test if Name-de was picked up
|
65 |
i=0 |
|
66 |
for it in db.postlist("AAFestplatten Ueberpruefer"): |
|
67 |
i+=1 |
|
68 |
self.assertEqual(i, 1) |
|
69 |
# test if gettext worked
|
|
70 |
found_gettext_translation = False |
|
71 |
for it in db.postlist("AAFestplatten Ueberpruefer"): |
|
72 |
doc = db.get_document(it.docid) |
|
73 |
for term_iter in doc.termlist(): |
|
74 |
if term_iter.term == "fehler": |
|
75 |
found_gettext_translation = True |
|
76 |
break
|
|
77 |
self.assertTrue(found_gettext_translation) |
|
|
857.1.1
by Michael Vogt
start with the code that can update using /var/lib/apt/lists |
78 |
|
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
79 |
def test_application(self): |
80 |
self.assertRaises(AppDetails(self.db)) |
|
81 |
||
82 |
def test_application(self): |
|
83 |
db = xapian.WritableDatabase("./data/test.db", |
|
84 |
xapian.DB_CREATE_OR_OVERWRITE) |
|
85 |
res = update_from_app_install_data(db, self.cache, datadir="./data/") |
|
86 |
db = StoreDatabase("./data/test.db", self.cache) |
|
87 |
db.open(use_axi=False) |
|
88 |
self.assertTrue(len(db), 1) |
|
|
902
by Michael Vogt
add get_details() to Application |
89 |
# test details
|
90 |
app = Application("Ubuntu Software Center Test", "software-center") |
|
91 |
details = app.get_details(db) |
|
92 |
self.assertNotEqual(details, None) |
|
93 |
self.assertEqual(details.component, "main") |
|
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
94 |
# get the first document
|
95 |
for doc in db: |
|
|
887
by Michael Vogt
use kiwinotes ApplicationDetails attributes to populate the properties |
96 |
appdetails = AppDetails(db, doc=doc) |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
97 |
break
|
|
889.2.2
by Kiwinote
minor naming changes |
98 |
self.assertEqual(appdetails.name, "Ubuntu Software Center Test") |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
99 |
self.assertEqual(appdetails.pkgname, "software-center") |
|
888
by Michael Vogt
more code, more tests |
100 |
# FIXME: add a dekstop file with a real channel to test
|
101 |
# and monkey-patch/modify the APP_INSTALL_CHANNELS_PATH
|
|
102 |
self.assertEqual(appdetails.channel, None) |
|
103 |
self.assertEqual(appdetails.component, "main") |
|
104 |
self.assertNotEqual(appdetails.pkg, None) |
|
105 |
# FIXME: test description for unavailable pkg
|
|
106 |
self.assertTrue( |
|
107 |
appdetails.description.startswith("The Ubuntu Software Center")) |
|
|
889.2.2
by Kiwinote
minor naming changes |
108 |
# FIXME: test appdetails.website
|
|
888
by Michael Vogt
more code, more tests |
109 |
self.assertEqual(appdetails.icon, "softwarecenter") |
|
889
by Michael Vogt
add appdetails.{version,screenshots,thumbnail,price,license} |
110 |
# crude, crude
|
111 |
self.assertTrue(len(appdetails.version) > 2) |
|
112 |
# FIXME: screenshots will only work on ubuntu
|
|
113 |
self.assertEqual(appdetails.screenshot, |
|
114 |
"http://screenshots.ubuntu.com/screenshot-404/software-center") |
|
115 |
self.assertEqual(appdetails.thumbnail, |
|
116 |
"http://screenshots.ubuntu.com/thumbnail-404/software-center") |
|
117 |
# FIXME: add document that has a price
|
|
118 |
self.assertEqual(appdetails.price, "Free") |
|
119 |
self.assertEqual(appdetails.license, "License: Open Source") |
|
|
890
by Michael Vogt
merged from lp:~kiwinote/software-center/appdetails-in-db but make AptHistory a singleton |
120 |
# FIXME: this will only work if software-center is installed
|
|
889.2.2
by Kiwinote
minor naming changes |
121 |
self.assertNotEqual(appdetails.installation_date, None) |
|
886
by Michael Vogt
start with softwarecenter.db.{Application,AppDetails} interfaces |
122 |
|
|
776
by Michael Vogt
merged lp:~j-johan-edwards/software-center/custom_lists to |
123 |
if __name__ == "__main__": |
124 |
import logging |
|
125 |
logging.basicConfig(level=logging.DEBUG) |
|
126 |
unittest.main() |