@@ -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/>.
20+"""Tests for the Dash autopilot emulators.
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.
20import mock
32import mock
35+from testtools.matchers import Contains, HasLength
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
27−class DashEmulatorTestCase(tests.UnityTestCase):
42+class DashBaseTestCase(tests.UnityTestCase):
29 scenarios = tests._get_device_emulation_scenarios()
44 scenarios = tests._get_device_emulation_scenarios()
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()
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(
61+ newvalue=qml_import_path_with_scope_fakes))
64+class DashEmulatorTestCase(DashBaseTestCase):
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)
123−class DashAppsEmulatorTestCase(tests.UnityTestCase):
152+class DashAppsEmulatorTestCase(DashBaseTestCase):
125− scenarios = tests._get_device_emulation_scenarios()
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',]
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')
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))
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)
180+ self.assertThat(applications, HasLength(expected_apps_count))
181+ for expected in expected_applications:
182+ self.assertThat(applications, Contains(expected))
184+ def _get_number_of_application_slots(self, category):
185+ category_element = self.applications_scope._get_category_element(
187+ grid = category_element.select_single('GenericFilterGrid')
188+ return grid.columns * grid.rows