on xenial help sign in
Properly implemented the get_applications test case using the fake scopes.
05af309Leo Arias
tests/autopilot/unity8/shell/emulators/dash.py+2
@@ -152,6 +152,8 @@ class DashApps(emulators.UnityEmulatorBase):
152 """
152 """
153 category_element = self._get_category_element(category)
153 category_element = self._get_category_element(category)
154 application_tiles = category_element.select_many('Tile')
154 application_tiles = category_element.select_many('Tile')
155+ # TODO return them on the same order they are displayed.
156+ # --elopio - 2014-1-15
155 return [tile.text for tile in application_tiles]
157 return [tile.text for tile in application_tiles]
156
158
157 def _get_category_element(self, category):
159 def _get_category_element(self, category):
tests/autopilot/unity8/shell/tests/test_emulators.py+53−16
@@ -17,23 +17,52 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
18#
19
19
20+"""Tests for the Dash autopilot emulators.
21+
22+The autopilot emulators are helpers for tests that check a user journey that
23+involves the dash. The code for some of those tests will not be inside this
24+branch, but in projects that depend on unity or that test the whole system
25+integration. So, we need to test the helpers in order to make sure that we
26+don't break them for those external projects.
27+
28+"""
29+
30+import os
31+
20import mock
32import mock
21
33
34+import fixtures
35+from testtools.matchers import Contains, HasLength
36+
22from unity8 import process_helpers
37from unity8 import process_helpers
23from unity8.shell import emulators, tests
38from unity8.shell import emulators, tests
24from unity8.shell.emulators import dash as dash_emulators
39from unity8.shell.emulators import dash as dash_emulators
25
40
26
41
27−class DashEmulatorTestCase(tests.UnityTestCase):
42+class DashBaseTestCase(tests.UnityTestCase):
28
43
29 scenarios = tests._get_device_emulation_scenarios()
44 scenarios = tests._get_device_emulation_scenarios()
30
45
31 def setUp(self):
46 def setUp(self):
32− super(DashEmulatorTestCase, self).setUp()
47+ super(DashBaseTestCase, self).setUp()
48+ self._use_scope_fakes()
33 unity_proxy = self.launch_unity()
49 unity_proxy = self.launch_unity()
34 process_helpers.unlock_unity(unity_proxy)
50 process_helpers.unlock_unity(unity_proxy)
35 self.dash = self.main_window.get_dash()
51 self.dash = self.main_window.get_dash()
36
52
53+ def _use_scope_fakes(self):
54+ qml2_import_path = os.environ.get('QML2_IMPORT_PATH')
55+ mocks_path = os.path.join(
56+ os.getcwd(), '../..', 'builddir/tests/mocks')
57+ qml_import_path_with_scope_fakes = '{0}:{1}'.format(
58+ qml2_import_path, mocks_path)
59+ self.useFixture(fixtures.EnvironmentVariable(
60+ 'QML2_IMPORT_PATH',
61+ newvalue=qml_import_path_with_scope_fakes))
62+
63+
64+class DashEmulatorTestCase(DashBaseTestCase):
65+
37 def test_open_unexisting_scope(self):
66 def test_open_unexisting_scope(self):
38 scope_name = 'unexisting'
67 scope_name = 'unexisting'
39 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
68 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
@@ -120,15 +149,15 @@ class DashEmulatorTestCase(tests.UnityTestCase):
120 self.assertIsInstance(scope, dash_emulators.DashApps)
149 self.assertIsInstance(scope, dash_emulators.DashApps)
121
150
122
151
123−class DashAppsEmulatorTestCase(tests.UnityTestCase):
152+class DashAppsEmulatorTestCase(DashBaseTestCase):
124−
125− scenarios = tests._get_device_emulation_scenarios()
126
153
154+ available_applications = [
155+ 'Title.1', 'Title.21', 'Title.41', 'Title.61', 'Title.81',
156+ 'Title.101', 'Title.121', 'Title.141', 'Title.161', 'Title.181',
157+ 'Title.201', 'Title.221', 'Title.241', 'Title.261', 'Title.281',]
158+
127 def setUp(self):
159 def setUp(self):
128 super(DashAppsEmulatorTestCase, self).setUp()
160 super(DashAppsEmulatorTestCase, self).setUp()
129− unity_proxy = self.launch_unity()
130− process_helpers.unlock_unity(unity_proxy)
131− self.dash = self.main_window.get_dash()
132 self.applications_scope = self.dash.open_scope('applications')
161 self.applications_scope = self.dash.open_scope('applications')
133
162
134 def test_get_applications_with_unexisting_category(self):
163 def test_get_applications_with_unexisting_category(self):
@@ -141,11 +170,19 @@ class DashAppsEmulatorTestCase(tests.UnityTestCase):
141 'No category found with name unexisting category', str(exception))
170 'No category found with name unexisting category', str(exception))
142
171
143 def test_get_applications_should_return_list_with_names(self):
172 def test_get_applications_should_return_list_with_names(self):
144− # FIXME The installed category comes from the scope click. This is the
173+ category = 'installed'
145− # wrong way to test this emulator, because it shouldn't depend on the
174+ expected_apps_count = self._get_number_of_application_slots(category)
146− # current implementation of the click scope. There can be many other
175+ expected_applications = self.available_applications[
147− # scopes using DashApps as a base. In addition to this, we can't
176+ :expected_apps_count]
148− # actually check the values returned, as they depend on the server that
177+
149− # the click scope uses. What we need is to open a scope with hardcoded
150− # categories and values.
151− applications = self.applications_scope.get_applications('installed')
178+ applications = self.applications_scope.get_applications(category)
179+
180+ self.assertThat(applications, HasLength(expected_apps_count))
181+ for expected in expected_applications:
182+ self.assertThat(applications, Contains(expected))
183+
184+ def _get_number_of_application_slots(self, category):
185+ category_element = self.applications_scope._get_category_element(
186+ category)
187+ grid = category_element.select_single('GenericFilterGrid')
188+ return grid.columns * grid.rows