on xenial help sign in
Update the url dispatcher test to use the fake app fixture from the toolkit.
37259c5Leo Arias
tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+5−40
@@ -20,12 +20,11 @@
20"""Test the integration with the URL dispatcher service."""
20"""Test the integration with the URL dispatcher service."""
21
21
22import os
22import os
23−import tempfile
24
23
25from autopilot import platform
24from autopilot import platform
26from autopilot.matchers import Eventually
25from autopilot.matchers import Eventually
27from testtools.matchers import Equals
26from testtools.matchers import Equals
28−from ubuntuuitoolkit import base as toolkit_base
27+from ubuntuuitoolkit import fixture_setup
29
28
30from unity8 import process_helpers
29from unity8 import process_helpers
31from unity8.shell import tests
30from unity8.shell import tests
@@ -47,13 +46,6 @@ MainView {
47 text: 'Test application.'
46 text: 'Test application.'
48 }
47 }
49}
48}
50−""")
51−
52− desktop_file_contents = ("""[Desktop Entry]
53−Type=Application
54−Name=test
55−Exec={qmlscene} {qml_file_path}
56−Icon=Not important
57""")
49""")
58
50
59 def setUp(self):
51 def setUp(self):
@@ -66,37 +58,10 @@ Icon=Not important
66 process_helpers.unlock_unity(unity_proxy)
58 process_helpers.unlock_unity(unity_proxy)
67
59
68 def create_test_application(self):
60 def create_test_application(self):
69− # FIXME most of this code is duplicated in the toolkit. We should
61+ fake_application = fixture_setup.FakeApplication(self.test_qml)
70− # create a fixture on the toolkit for other projects to use.
62+ self.useFixture(fake_application)
71− # http://pad.lv/1277334 --elopio - 2014-02-06
72− qml_file_path = self._write_test_qml_file()
73− self.addCleanup(os.remove, qml_file_path)
74− desktop_file_path = self._write_test_desktop_file(qml_file_path)
75− self.addCleanup(os.remove, desktop_file_path)
76− return qml_file_path, desktop_file_path
77−
78− def _write_test_qml_file(self):
79− qml_file = tempfile.NamedTemporaryFile(suffix='.qml', delete=False)
80− qml_file.write(self.test_qml.encode('utf-8'))
81− qml_file.close()
82− return qml_file.name
83−
84− def _write_test_desktop_file(self, qml_file_path):
85− desktop_file_dir = self._get_local_desktop_file_directory()
86− if not os.path.exists(desktop_file_dir):
87− os.makedirs(desktop_file_dir)
88− desktop_file = tempfile.NamedTemporaryFile(
89− suffix='.desktop', dir=desktop_file_dir, delete=False)
90− contents = self.desktop_file_contents.format(
91− qmlscene=toolkit_base.get_qmlscene_launch_command(),
92− qml_file_path=qml_file_path)
93− desktop_file.write(contents.encode('utf-8'))
94− desktop_file.close()
95− return desktop_file.name
96−
97− def _get_local_desktop_file_directory(self):
98− return os.path.join(
63+ return (
99− os.environ.get('HOME'), '.local', 'share', 'applications')
64+ fake_application.qml_file_path, fake_application.desktop_file_path)
100
65
101 def test_swipe_out_application_started_by_url_dispatcher(self):
66 def test_swipe_out_application_started_by_url_dispatcher(self):
102 _, desktop_file_path = self.create_test_application()
67 _, desktop_file_path = self.create_test_application()