Merge lp:~nskaggs/ubuntu-rssreader-app/fix-ap-layout into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk
- fix-ap-layout
- Merge into trunk
Proposed by
Nicholas Skaggs
Status: | Merged |
---|---|
Approved by: | Nicholas Skaggs |
Approved revision: | 349 |
Merged at revision: | 348 |
Proposed branch: | lp:~nskaggs/ubuntu-rssreader-app/fix-ap-layout |
Merge into: | lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk |
Diff against target: |
448 lines (+134/-132) 3 files modified
tests/autopilot/shorts_app/__init__.py (+12/-58) tests/autopilot/shorts_app/tests/__init__.py (+97/-46) tests/autopilot/shorts_app/tests/test_rssreader.py (+25/-28) |
To merge this branch: | bzr merge lp:~nskaggs/ubuntu-rssreader-app/fix-ap-layout |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Ubuntu Shorts Developers | Pending | ||
Review via email: mp+244930@code.launchpad.net |
Commit message
Update AP layout to best practices
Description of the change
Update AP layout to best practices (I did not switch off using the deprecated modules for the SDK helpers)
To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'tests/autopilot/shorts_app/__init__.py' |
2 | --- tests/autopilot/shorts_app/__init__.py 2014-09-17 20:18:37 +0000 |
3 | +++ tests/autopilot/shorts_app/__init__.py 2014-12-17 00:05:17 +0000 |
4 | @@ -7,7 +7,6 @@ |
5 | |
6 | """RSS reader app tests and emulators - top level package.""" |
7 | |
8 | -import os |
9 | import logging |
10 | from time import sleep |
11 | |
12 | @@ -15,7 +14,6 @@ |
13 | from testtools.matchers import NotEquals |
14 | |
15 | from ubuntuuitoolkit import ( |
16 | - base, |
17 | emulators as toolkit_emulators |
18 | ) |
19 | |
20 | @@ -23,63 +21,18 @@ |
21 | logger = logging.getLogger(__name__) |
22 | |
23 | |
24 | -class ShortsApp(): |
25 | - |
26 | - """App class""" |
27 | - local_location = "../../shorts-app.qml" |
28 | - installed_location = "/usr/share/shorts-app/shorts-app.qml" |
29 | - |
30 | - def __init__(self, test_obj): |
31 | - """Constructor |
32 | - |
33 | - :param test_obj: An AutopilotTestCase object |
34 | - """ |
35 | - self.test_obj = test_obj |
36 | - launch, self.test_type = self.setup_environment() |
37 | - self.app = launch() |
38 | - |
39 | - def setup_environment(self): |
40 | - """Selects the way to launch the application""" |
41 | - if os.path.exists(self.local_location): |
42 | - logger.debug("Running via local installation") |
43 | - launch = self.launch_test_local |
44 | - test_type = 'local' |
45 | - elif os.path.exists(self.installed_location): |
46 | - logger.debug("Running via installed debian package") |
47 | - launch = self.launch_test_installed |
48 | - test_type = 'deb' |
49 | - else: |
50 | - logger.debug("Running via click package") |
51 | - launch = self.launch_test_click |
52 | - test_type = 'click' |
53 | - return launch, test_type |
54 | - |
55 | - def launch_test_local(self): |
56 | - """Launch the application using a relative path""" |
57 | - return self.test_obj.launch_test_application( |
58 | - base.get_qmlscene_launch_command(), |
59 | - self.local_location, |
60 | - app_type='qt', |
61 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
62 | - |
63 | - def launch_test_installed(self): |
64 | - """Launch the application using the system path""" |
65 | - return self.test_obj.launch_test_application( |
66 | - base.get_qmlscene_launch_command(), |
67 | - self.installed_location, |
68 | - app_type='qt', |
69 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
70 | - |
71 | - def launch_test_click(self): |
72 | - """Launch the application using click package""" |
73 | - return self.test_obj.launch_click_package( |
74 | - "com.ubuntu.shorts", |
75 | - emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
76 | +class ShortsApp(object): |
77 | + |
78 | + """Autopilot helper object for shorts.""" |
79 | + |
80 | + def __init__(self, app_proxy, test_type): |
81 | + self.app = app_proxy |
82 | + self.test_type = test_type |
83 | + self.main_view = self.app.select_single(MainView) |
84 | |
85 | @property |
86 | - def main_view(self): |
87 | - """Return MainView object""" |
88 | - return self.app.select_single(MainView) |
89 | + def pointing_device(self): |
90 | + return self.app.pointing_device |
91 | |
92 | |
93 | class ShortsAppException(Exception): |
94 | @@ -227,7 +180,8 @@ |
95 | return self.select_single("ManageTopicsPage") |
96 | |
97 | def get_rss_feed_page(self): |
98 | - return self.wait_select_single("RssFeedPage", objectName="rssfeedpage") |
99 | + return self.wait_select_single("ArticleViewPage", |
100 | + objectName="rssfeedpage") |
101 | |
102 | def get_shorts_tab(self): |
103 | return self.wait_select_single("ShortsTab", objectName="Tab0") |
104 | |
105 | === modified file 'tests/autopilot/shorts_app/tests/__init__.py' |
106 | --- tests/autopilot/shorts_app/tests/__init__.py 2014-06-27 15:21:04 +0000 |
107 | +++ tests/autopilot/shorts_app/tests/__init__.py 2014-12-17 00:05:17 +0000 |
108 | @@ -20,72 +20,123 @@ |
109 | """shorts-app autopilot tests.""" |
110 | |
111 | import os.path |
112 | -import os |
113 | import shutil |
114 | import logging |
115 | |
116 | -from autopilot.input import Mouse, Touch, Pointer |
117 | from autopilot.platform import model |
118 | +from autopilot import logging as autopilot_logging |
119 | from autopilot.testcase import AutopilotTestCase |
120 | |
121 | -from shorts_app import ShortsApp |
122 | +import shorts_app |
123 | + |
124 | +import ubuntuuitoolkit |
125 | +from ubuntuuitoolkit import base |
126 | +import fixtures |
127 | |
128 | logger = logging.getLogger(__name__) |
129 | |
130 | |
131 | -class ShortsAppTestCase(AutopilotTestCase): |
132 | +class BaseTestCaseWithPatchedHome(AutopilotTestCase): |
133 | |
134 | """A common test case class that provides several useful methods for |
135 | rssreader-app tests. |
136 | |
137 | """ |
138 | - if model() == 'Desktop': |
139 | - scenarios = [('with mouse', dict(input_device_class=Mouse))] |
140 | - else: |
141 | - scenarios = [('with touch', dict(input_device_class=Touch))] |
142 | - |
143 | - sqlite_dir = os.path.expanduser( |
144 | - "~/.local/share/com.ubuntu.shorts/Databases") |
145 | - backup_dir = sqlite_dir + ".backup" |
146 | + |
147 | + local_location = os.path.dirname(os.path.dirname(os.getcwd())) |
148 | + local_location_qml = os.path.join(local_location, 'shorts-app.qml') |
149 | + installed_location_qml = "/usr/share/shorts-app/shorts-app.qml" |
150 | + |
151 | + def get_launcher_and_type(self): |
152 | + if os.path.exists(self.local_location_qml): |
153 | + launcher = self.launch_test_local |
154 | + test_type = 'local' |
155 | + elif os.path.exists(self.installed_location_qml): |
156 | + launcher = self.launch_test_installed |
157 | + test_type = 'deb' |
158 | + else: |
159 | + launcher = self.launch_test_click |
160 | + test_type = 'click' |
161 | + return launcher, test_type |
162 | |
163 | def setUp(self): |
164 | - self.pointing_device = Pointer(self.input_device_class.create()) |
165 | - super(ShortsAppTestCase, self).setUp() |
166 | - self.temp_move_sqlite_db() |
167 | - self.addCleanup(self.restore_sqlite_db) |
168 | + super(BaseTestCaseWithPatchedHome, self).setUp() |
169 | + self.launcher, self.test_type = self.get_launcher_and_type() |
170 | + self.home_dir = self.patch_home() |
171 | |
172 | # turn off the OSK so it doesn't block screen elements |
173 | if model() != 'Desktop': |
174 | os.system("stop maliit-server") |
175 | self.addCleanup(os.system, "start maliit-server") |
176 | |
177 | - self.shorts_app = ShortsApp(self) |
178 | - |
179 | - def temp_move_sqlite_db(self): |
180 | - try: |
181 | - shutil.rmtree(self.backup_dir) |
182 | - except: |
183 | - pass |
184 | - else: |
185 | - logger.warning("Prexisting backup database found and removed") |
186 | - |
187 | - try: |
188 | - shutil.move(self.sqlite_dir, self.backup_dir) |
189 | - except: |
190 | - logger.warning("No current database found") |
191 | - else: |
192 | - logger.debug("Backed up database") |
193 | - |
194 | - def restore_sqlite_db(self): |
195 | - if os.path.exists(self.backup_dir): |
196 | - if os.path.exists(self.sqlite_dir): |
197 | - try: |
198 | - shutil.rmtree(self.sqlite_dir) |
199 | - except: |
200 | - logger.error("Failed to remove test database and restore" / |
201 | - "database") |
202 | - return |
203 | - try: |
204 | - shutil.move(self.backup_dir, self.sqlite_dir) |
205 | - except: |
206 | - logger.error("Failed to restore database") |
207 | + @autopilot_logging.log_action(logger.info) |
208 | + def launch_test_local(self): |
209 | + return self.launch_test_application( |
210 | + base.get_qmlscene_launch_command(), |
211 | + self.local_location_qml, |
212 | + app_type='qt', |
213 | + emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase) |
214 | + |
215 | + @autopilot_logging.log_action(logger.info) |
216 | + def launch_test_installed(self): |
217 | + return self.launch_test_application( |
218 | + base.get_qmlscene_launch_command(), |
219 | + self.installed_location_qml, |
220 | + app_type='qt', |
221 | + emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase) |
222 | + |
223 | + @autopilot_logging.log_action(logger.info) |
224 | + def launch_test_click(self): |
225 | + return self.launch_click_package( |
226 | + "com.ubuntu.shorts", |
227 | + emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase) |
228 | + |
229 | + def _copy_xauthority_file(self, directory): |
230 | + """ Copy .Xauthority file to directory, if it exists in /home |
231 | + """ |
232 | + # If running under xvfb, as jenkins does, |
233 | + # xsession will fail to start without xauthority file |
234 | + # Thus if the Xauthority file is in the home directory |
235 | + # make sure we copy it to our temp home directory |
236 | + |
237 | + xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'), |
238 | + '.Xauthority')) |
239 | + if os.path.isfile(xauth): |
240 | + logger.debug("Copying .Xauthority to %s" % directory) |
241 | + shutil.copyfile( |
242 | + os.path.expanduser(os.path.join(os.environ.get('HOME'), |
243 | + '.Xauthority')), |
244 | + os.path.join(directory, '.Xauthority')) |
245 | + |
246 | + def patch_home(self): |
247 | + """ mock /home for testing purposes to preserve user data |
248 | + """ |
249 | + |
250 | + # if running on non-phablet device, |
251 | + # run in temp folder to avoid mucking up home |
252 | + # bug 1316746 |
253 | + # bug 1376423 |
254 | + if self.test_type is 'click': |
255 | + # just use home for now on devices |
256 | + temp_dir = os.environ.get('HOME') |
257 | + else: |
258 | + temp_dir_fixture = fixtures.TempDir() |
259 | + self.useFixture(temp_dir_fixture) |
260 | + temp_dir = temp_dir_fixture.path |
261 | + |
262 | + # before we set fixture, copy xauthority if needed |
263 | + self._copy_xauthority_file(temp_dir) |
264 | + self.useFixture(fixtures.EnvironmentVariable('HOME', |
265 | + newvalue=temp_dir)) |
266 | + |
267 | + logger.debug("Patched home to fake home directory %s" % temp_dir) |
268 | + return temp_dir |
269 | + |
270 | + |
271 | +class ShortsAppTestCase(BaseTestCaseWithPatchedHome): |
272 | + |
273 | + """Base test case that launches shorts-app""" |
274 | + |
275 | + def setUp(self): |
276 | + super(ShortsAppTestCase, self).setUp() |
277 | + self.app = shorts_app.ShortsApp(self.launcher(), self.test_type) |
278 | |
279 | === modified file 'tests/autopilot/shorts_app/tests/test_rssreader.py' |
280 | --- tests/autopilot/shorts_app/tests/test_rssreader.py 2014-09-17 20:18:37 +0000 |
281 | +++ tests/autopilot/shorts_app/tests/test_rssreader.py 2014-12-17 00:05:17 +0000 |
282 | @@ -16,8 +16,6 @@ |
283 | |
284 | """shorts app autopilot tests.""" |
285 | |
286 | -from __future__ import absolute_import |
287 | - |
288 | from autopilot.matchers import Eventually |
289 | from testtools.matchers import Equals, NotEquals |
290 | |
291 | @@ -36,7 +34,6 @@ |
292 | |
293 | def setUp(self): |
294 | super(BaseShortsAppTestCase, self).setUp() |
295 | - self.shorts_app.main_view.visible.wait_for(True) |
296 | |
297 | # wait for any updates to finish before beginning tests |
298 | self._wait_for_refresh() |
299 | @@ -44,18 +41,18 @@ |
300 | def _wait_for_refresh(self): |
301 | try: |
302 | self.assertThat( |
303 | - self.shorts_app.main_view.get_network_activity, |
304 | + self.app.main_view.get_network_activity, |
305 | Eventually(NotEquals(None), timeout=5)) |
306 | self.assertThat( |
307 | - self.shorts_app.main_view.get_network_activity, |
308 | + self.app.main_view.get_network_activity, |
309 | Eventually(Equals(None), timeout=60)) |
310 | except: |
311 | self.assertThat( |
312 | - self.shorts_app.main_view.get_network_activity, |
313 | + self.app.main_view.get_network_activity, |
314 | Eventually(Equals(None), timeout=60)) |
315 | |
316 | def add_feed_to_new_topic(self, feed_url, feed_title, topic): |
317 | - add_feeds_page = self.shorts_app.main_view.go_to_add_feeds() |
318 | + add_feeds_page = self.app.main_view.go_to_add_feeds() |
319 | # XXX here we are using an external server because we are currently |
320 | # using the Google Feed API, which doesn't let us access local |
321 | # resources. --elopio - 2014-02-26 |
322 | @@ -77,30 +74,30 @@ |
323 | test_topic = 'Test topic' |
324 | self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic) |
325 | |
326 | - selected_tab_title = self.shorts_app.main_view.get_selected_tab_title() |
327 | + selected_tab_title = self.app.main_view.get_selected_tab_title() |
328 | self.assertEqual('Test topic', selected_tab_title) |
329 | |
330 | def test_switch_to_list_view_mode(self): |
331 | """ test switching to list view mode""" |
332 | - shorts_tab = self.shorts_app.main_view.get_shorts_tab() |
333 | + shorts_tab = self.app.main_view.get_shorts_tab() |
334 | self._ensure_grid_view_mode(shorts_tab) |
335 | - self.shorts_app.main_view.change_view_mode("isNotListMode") |
336 | + self.app.main_view.change_view_mode("isNotListMode") |
337 | self.assertThat(shorts_tab.isListMode, Eventually(Equals(True))) |
338 | |
339 | def test_switch_to_grid_view_mode(self): |
340 | """ test switching to grid view mode""" |
341 | - shorts_tab = self.shorts_app.main_view.get_shorts_tab() |
342 | + shorts_tab = self.app.main_view.get_shorts_tab() |
343 | self._ensure_list_view_mode(shorts_tab) |
344 | - self.shorts_app.main_view.change_view_mode("isListMode") |
345 | + self.app.main_view.change_view_mode("isListMode") |
346 | self.assertThat(shorts_tab.isListMode, Eventually(Equals(False))) |
347 | |
348 | def _ensure_grid_view_mode(self, current_tab): |
349 | if current_tab.isListMode: |
350 | - self.shorts_app.main_view.change_view_mode("isListMode") |
351 | + self.app.main_view.change_view_mode("isListMode") |
352 | |
353 | def _ensure_list_view_mode(self, current_tab): |
354 | if not current_tab.isListMode: |
355 | - self.shorts_app.main_view.change_view_mode("isNotListMode") |
356 | + self.app.main_view.change_view_mode("isNotListMode") |
357 | |
358 | def test_open_listmode_feed_item(self): |
359 | """"test to ensure list mode feed items can be opened""" |
360 | @@ -110,14 +107,14 @@ |
361 | test_topic = 'Test topic' |
362 | |
363 | self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic) |
364 | - new_topic_tab = self.shorts_app.main_view.get_topic_tab(test_topic) |
365 | + new_topic_tab = self.app.main_view.get_topic_tab(test_topic) |
366 | self._ensure_list_view_mode(new_topic_tab) |
367 | |
368 | - self.shorts_app.main_view.open_feed_item(test_topic, test_feed_title) |
369 | + self.app.main_view.open_feed_item(test_topic, test_feed_title) |
370 | self.assertEqual( |
371 | - self.shorts_app.main_view.get_feed_in_feedlist_title( |
372 | + self.app.main_view.get_feed_in_feedlist_title( |
373 | test_topic, test_feed_title), |
374 | - self.shorts_app.main_view.get_articleviewitem_title()) |
375 | + self.app.main_view.get_articleviewitem_title()) |
376 | |
377 | @unittest.skip("Can't see or get dynamic tabs") |
378 | def test_edit_topic(self): |
379 | @@ -129,43 +126,43 @@ |
380 | self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic) |
381 | |
382 | # verify we are on the topicName Tab |
383 | - editTab = self.shorts_app.main_view.get_topic_tab(test_topic) |
384 | + editTab = self.app.main_view.get_topic_tab(test_topic) |
385 | self.assertThat(editTab.visible, Eventually(Equals(True))) |
386 | |
387 | # open toolbar |
388 | - toolbar = self.shorts_app.main_view.open_toolbar() |
389 | + toolbar = self.app.main_view.open_toolbar() |
390 | |
391 | # click on edit topics button |
392 | toolbar.click_button("edittopicsbutton") |
393 | |
394 | # verify we are on topic management page |
395 | topicmanagementpage = \ |
396 | - self.shorts_app.main_view.get_feed_management_page() |
397 | + self.app.main_view.get_feed_management_page() |
398 | self.assertThat( |
399 | topicmanagementpage.objectName, |
400 | Eventually(Equals("topicmanagement"))) |
401 | |
402 | # verity Tab is expanded |
403 | - editTopic = self.shorts_app.main_view.get_feedlist_topic(test_topic) |
404 | + editTopic = self.app.main_view.get_feedlist_topic(test_topic) |
405 | if editTopic.state != "expanded": |
406 | self.pointing_device.click_object(editTopic) |
407 | |
408 | # select feed |
409 | - editFeed = self.shorts_app.main_view.get_feedlist_feed(test_topic) |
410 | + editFeed = self.app.main_view.get_feedlist_feed(test_topic) |
411 | self.assertThat(editFeed, NotEquals(None)) |
412 | self.pointing_device.click_object(editFeed) |
413 | |
414 | # verify we are on edit feed page |
415 | - editfeedpage = self.shorts_app.main_view.get_edit_feed_page() |
416 | + editfeedpage = self.app.main_view.get_edit_feed_page() |
417 | self.assertThat(editfeedpage.visible, Eventually(Equals(True))) |
418 | |
419 | # change topic from dropdown |
420 | topicValueselector = \ |
421 | - self.shorts_app.main_view.get_editfeed_topic_valueselector() |
422 | + self.app.main_view.get_editfeed_topic_valueselector() |
423 | self.pointing_device.click_object(topicValueselector) |
424 | |
425 | # click on news topic |
426 | - topicValueselectorValue = self.shorts_app.main_view. \ |
427 | + topicValueselectorValue = self.app.main_view. \ |
428 | get_editfeed_valueselector_value("Ubuntu") |
429 | self.pointing_device.click_object(topicValueselectorValue) |
430 | |
431 | @@ -186,7 +183,7 @@ |
432 | |
433 | def test_remove_feed(self): |
434 | """Test the removal of a feed from the Edit Feeds page.""" |
435 | - edit_feeds_page = self.shorts_app.main_view.go_to_edit_feeds() |
436 | + edit_feeds_page = self.app.main_view.go_to_edit_feeds() |
437 | edit_feeds_page.expand_topic(self.test_topic) |
438 | feeds = edit_feeds_page.get_feeds_in_topic(self.test_topic) |
439 | self.assertIn(self.test_feed_title, feeds) |
440 | @@ -196,7 +193,7 @@ |
441 | |
442 | def test_remove_topic(self): |
443 | """Test the removal of a topic from the Edit Topics page.""" |
444 | - edit_feeds_page = self.shorts_app.main_view.go_to_edit_feeds() |
445 | + edit_feeds_page = self.app.main_view.go_to_edit_feeds() |
446 | edit_feeds_page.delete_topic(self.test_topic) |
447 | topics = edit_feeds_page.get_topics() |
448 | self.assertNotIn(self.test_topic, topics) |