1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
from gi.repository import GObject
import random
import os
import time
import unittest
# ensure we set the review backend to the fake one
os.environ["SOFTWARE_CENTER_IPSUM_REVIEWS"] = "1"
from softwarecenter.db.pkginfo import get_pkg_info
from softwarecenter.ui.qml.categoriesmodel import CategoriesModel
from softwarecenter.ui.qml.pkglist import PkgListModel
from softwarecenter.ui.qml.reviewslist import ReviewsListModel
class TestQMLHelpers(unittest.TestCase):
""" tests the helper classes for the qml code """
def setUp(self):
# ensure the cache is ready
cache = get_pkg_info()
cache.open()
def test_categories_model(self):
""" test the qml categories model """
CAT_NAME_COLUMN = 0
# get the model
model = CategoriesModel()
# ensure we have something in it
self.assertNotEqual(model.rowCount(), 0)
# ensure we have "Games"
names = set()
for i in range(model.rowCount()):
index = model.index(i, CAT_NAME_COLUMN)
role = CAT_NAME_COLUMN
names.add(model.data(index, role))
self.assertTrue("Games" in names)
def test_pkglist_model(self):
APP_NAME_COLUMN = 0
# get model
model = PkgListModel()
# ensure we start with a empty model by default
self.assertEqual(model.rowCount(), 0)
# test search
model.setSearchQuery("software")
# ensure we have something in it
self.assertNotEqual(model.rowCount(), 0)
# ensure we have "Software Center"
names = set()
for i in range(model.rowCount()):
index = model.index(i, APP_NAME_COLUMN)
role = APP_NAME_COLUMN
names.add(model.data(index, role))
# en_DK/en_US fun
self.assertTrue("Ubuntu Software Center" in names or
"Ubuntu Software Centre" in names)
# test setCategory by ensuring that setCategory() cuts the nr of
# search results
old_search_hits = model.rowCount()
model.setCategory("Games")
self.assertTrue(model.rowCount() < old_search_hits)
# test clear
model.clear()
self.assertEqual(model.rowCount(), 0)
def test_reviews_model_details(self):
SUMMARY_COLUMN = 0
# get the model
model = ReviewsListModel()
# ensure we start with a empty model by default
self.assertEqual(model.rowCount(), 0)
# fetch some reviews and ensure its not random
random.seed(1)
model.getReviews("software-center")
time.sleep(0.1)
self._p()
# check the results
self.assertEqual(model.rowCount(), 17)
summaries = []
for i in range(model.rowCount()):
index = model.index(i, SUMMARY_COLUMN)
role = SUMMARY_COLUMN
summaries.append(model.data(index, role))
# ensure the summaries are thre
self.assertEqual(summaries[0], "Medium")
self.assertEqual(summaries[4], "Cool")
# test clear
model.clear()
self.assertEqual(model.rowCount(), 0)
def test_reviews_model_stats(self):
def _got_review_stats_changed_signal():
self._i_am_refreshed = True
# get the model
model = ReviewsListModel()
self._i_am_refreshed = False
model.reviewStatsChanged.connect(_got_review_stats_changed_signal)
model.refreshReviewStats()
# ensure the signal got send
self.assertTrue(self._i_am_refreshed)
del self._i_am_refreshed
def _p(self):
context = GObject.main_context_default()
while context.pending():
context.iteration()
if __name__ == "__main__":
unittest.main()
|