@@ -17,23 +17,43 @@
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
33import mock
36+from testtools.matchers import Contains, HasLength
22from unity8 import process_helpers
39from unity8 import process_helpers
23from unity8.shell import emulators, tests
40from unity8.shell import emulators, tests
24from unity8.shell.emulators import dash as dash_emulators
41from unity8.shell.emulators import dash as dash_emulators
27−class DashEmulatorTestCase(tests.UnityTestCase):
44+class DashBaseTestCase(tests.UnityTestCase):
29 scenarios = tests._get_device_emulation_scenarios()
46 scenarios = tests._get_device_emulation_scenarios()
31 def setUp(self):
48 def setUp(self):
32− super(DashEmulatorTestCase, self).setUp()
49+ super(DashBaseTestCase, self).setUp()
33 unity_proxy = self.launch_unity()
50 unity_proxy = self.launch_unity()
34 process_helpers.unlock_unity(unity_proxy)
51 process_helpers.unlock_unity(unity_proxy)
35 self.dash = self.main_window.get_dash()
52 self.dash = self.main_window.get_dash()
55+class DashEmulatorTestCase(DashBaseTestCase):
37 def test_open_unexisting_scope(self):
57 def test_open_unexisting_scope(self):
38 scope_name = 'unexisting'
58 scope_name = 'unexisting'
39 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
59 with mock.patch.object(self.dash, 'pointing_device') as mock_pointer:
@@ -118,3 +138,70 @@ class DashEmulatorTestCase(tests.UnityTestCase):
118 scope = self.dash.open_scope(self._get_scope_name_from_id(scope_id))
138 scope = self.dash.open_scope(self._get_scope_name_from_id(scope_id))
119 self._assert_scope_is_opened(scope, scope_id)
139 self._assert_scope_is_opened(scope, scope_id)
120 self.assertIsInstance(scope, dash_emulators.DashApps)
140 self.assertIsInstance(scope, dash_emulators.DashApps)
143+class DashAppsEmulatorTestCase(DashBaseTestCase):
145+ available_applications = [
146+ 'Title.1', 'Title.21', 'Title.41', 'Title.61', 'Title.81',
147+ 'Title.101', 'Title.121', 'Title.141', 'Title.161', 'Title.181',
148+ 'Title.201', 'Title.221', 'Title.241', 'Title.261', 'Title.281']
151+ self._use_scope_fakes()
152+ super(DashAppsEmulatorTestCase, self).setUp()
153+ self.applications_scope = self.dash.open_scope('applications')
155+ def _use_scope_fakes(self):
157+ fixtures.EnvironmentVariable(
159+ newvalue=self._get_fake_scopes_library_path()))
161+ def _get_fake_scopes_library_path(self):
162+ if unity8.running_installed_tests():
163+ mock_path = 'qml/scopefakes/'
165+ mock_path = os.path.join(
166+ '../lib/', sysconfig.get_config_var('MULTIARCH'),
167+ 'unity8/qml/scopefakes/')
168+ lib_path = unity8.get_lib_path()
169+ ld_library_path = os.path.abspath(os.path.join(lib_path, mock_path))
171+ if not os.path.exists(ld_library_path):
173+ 'Expected library path does not exists: %s.' % (
175+ return ld_library_path
177+ def test_get_applications_with_unexisting_category(self):
178+ exception = self.assertRaises(
179+ emulators.UnityEmulatorException,
180+ self.applications_scope.get_applications,
181+ 'unexisting category')
184+ 'No category found with name unexisting category', str(exception))
186+ def test_get_applications_should_return_list_with_names(self):
187+ category = 'installed'
188+ expected_apps_count = self._get_number_of_application_slots(category)
189+ expected_applications = self.available_applications[
190+ :expected_apps_count]
192+ applications = self.applications_scope.get_applications(category)
194+ self.assertThat(applications, HasLength(expected_apps_count))
195+ for expected in expected_applications:
196+ self.assertThat(applications, Contains(expected))
198+ def _get_number_of_application_slots(self, category):
199+ category_element = self.applications_scope._get_category_element(
201+ grid = category_element.select_single('GenericFilterGrid')
202+ return grid.columns * grid.rows
204+ def test_open_preview(self):
205+ preview = self.applications_scope.open_preview('installed', 'Title.1')
206+ self.assertIsInstance(preview, dash_emulators.AppPreview)
207+ self.assertTrue(preview.isCurrent)