Merge lp:~elopio/ubuntu-rssreader-app/refactor_tests into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk

Proposed by Leo Arias
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 186
Merged at revision: 187
Proposed branch: lp:~elopio/ubuntu-rssreader-app/refactor_tests
Merge into: lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk
Diff against target: 414 lines (+169/-131)
3 files modified
feeds/AppendFeedPage.qml (+17/-1)
tests/autopilot/shorts_app/emulators.py (+95/-6)
tests/autopilot/shorts_app/tests/test_rssreader.py (+57/-124)
To merge this branch: bzr merge lp:~elopio/ubuntu-rssreader-app/refactor_tests
Reviewer Review Type Date Requested Status
Chris Gagnon (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Carla Sella (community) Approve
Leo Arias Pending
Review via email: mp+208517@code.launchpad.net

Commit message

Cleaned a test to add a feed to a new topic.

Description of the change

I started refactoring the first test, but it includes an add and delete test. This branch only includes the add part. So, for now I'm not removing any old code or tests. I find it nicer to go slowly.
Please let me know what you think, and if we should continue writing the tests this way.

To post a comment you must log in.
184. By Leo Arias

Fixed the copyright statements.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Chris Gagnon (chris.gagnon) wrote :

I'd really like to see a local http started to serve rss files from 127.0.0.1 instead of an external website.

there is an example here you can re-use to serve an rss xml file.
https://bazaar.launchpad.net/~phablet-team/webbrowser-app/trunk/view/head:/tests/autopilot/webbrowser_app/tests/http_server.py

review: Needs Fixing
Revision history for this message
Carla Sella (carla-sella) wrote :

I think that writing tests this way is fine.

Revision history for this message
Carla Sella (carla-sella) :
review: Approve
185. By Leo Arias

Removed the old add helper. Updated the remove tests with the new one.

186. By Leo Arias

Updated the other tests.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chris Gagnon (chris.gagnon) wrote :

We should really mock the network calls, without looking too closely it looks like google provides a library to do this. https://developers.google.com/api-client-library/python/guide/mocks

I won't hold up this MP for not mocking the network, but it should be on the roadmap for autopilot tests in this project.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'feeds/AppendFeedPage.qml'
--- feeds/AppendFeedPage.qml 2014-01-15 16:27:41 +0000
+++ feeds/AppendFeedPage.qml 2014-03-04 04:12:43 +0000
@@ -1,3 +1,19 @@
1/*
2 * Copyright (C) 2013, 2014
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
1import QtQuick 2.017import QtQuick 2.0
2import QtQuick.XmlListModel 2.018import QtQuick.XmlListModel 2.0
3import Ubuntu.Components 0.119import Ubuntu.Components 0.1
@@ -249,7 +265,7 @@
249265
250 delegate: ListItem.Standard {266 delegate: ListItem.Standard {
251 text: model.title267 text: model.title
252 objectName: "feedpagelistitem"268 objectName: "feedpagelistitem-" + model.title
253269
254 control: CheckBox {270 control: CheckBox {
255 anchors.verticalCenter: parent.verticalCenter271 anchors.verticalCenter: parent.verticalCenter
256272
=== modified file 'tests/autopilot/shorts_app/emulators.py'
--- tests/autopilot/shorts_app/emulators.py 2014-01-15 16:27:41 +0000
+++ tests/autopilot/shorts_app/emulators.py 2014-03-04 04:12:43 +0000
@@ -1,6 +1,6 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Copyright (C) 2013 Canonical Ltd.3# Copyright (C) 2013, 2014 Canonical Ltd.
4#4#
5# This program is free software; you can redistribute it and/or modify5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by6# it under the terms of the GNU Lesser General Public License as published by
@@ -14,14 +14,41 @@
14# You should have received a copy of the GNU Lesser General Public License14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17import logging
18from time import sleep
19
20from autopilot import logging as autopilot_logging
21from testtools.matchers import NotEquals
17from ubuntuuitoolkit import emulators as toolkit_emulators22from ubuntuuitoolkit import emulators as toolkit_emulators
18from time import sleep23
24
25logger = logging.getLogger(__name__)
1926
2027
21class MainView(toolkit_emulators.MainView):28class MainView(toolkit_emulators.MainView):
2229
23 retry_delay = 0.230 retry_delay = 0.2
2431
32 @autopilot_logging.log_action(logger.info)
33 def go_to_add_feeds(self):
34 popover = self._click_add_reads()
35 popover.click_button_by_text('+ Add feeds')
36 return self.select_single(
37 AppendFeedPage, objectName='appendfeedpage')
38
39 def _click_add_reads(self):
40 toolbar = self.open_toolbar()
41 toolbar.click_button('addreadsbutton')
42 return self.get_action_selection_popover('addreadspopover')
43
44 def get_selected_tab_title(self):
45 tabs = self.get_tabs()
46 selected_tab_index = tabs.selectedTabIndex
47 # TODO there are other tabs that are not of TopicTab type.
48 # --elopio - 2014-02-26
49 tab = tabs.select_single('TopicTab', index=selected_tab_index)
50 return tab.title
51
25 #ideally this should be converted to the sdk52 #ideally this should be converted to the sdk
26 #and use object name not text names53 #and use object name not text names
27 #see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/120514454 #see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1205144
@@ -83,10 +110,6 @@
83 #grab just the first checkbox110 #grab just the first checkbox
84 return self.select_many_retry("CheckBox", objectName="feedCheckbox")[0]111 return self.select_many_retry("CheckBox", objectName="feedCheckbox")[0]
85112
86 def get_append_page_list_items(self):
87 return self.select_many_retry("Standard",
88 objectName="feedpagelistitem")
89
90 def get_next_button(self):113 def get_next_button(self):
91 return self.select_single("Button", objectName="nextButton")114 return self.select_single("Button", objectName="nextButton")
92115
@@ -200,3 +223,69 @@
200 def get_editfeed_valueselector_value(self, name):223 def get_editfeed_valueselector_value(self, name):
201 valueselector = self.get_editfeed_topic_valueselector()224 valueselector = self.get_editfeed_topic_valueselector()
202 return valueselector.select_single("LabelVisual", text=name)225 return valueselector.select_single("LabelVisual", text=name)
226
227
228class Page(toolkit_emulators.MainView):
229 """Autopilot helper for the Page objects."""
230
231 def __init__(self, *args):
232 super(Page, self).__init__(*args)
233 # XXX we need a better way to keep reference to the main view.
234 # --elopio - 2014-02-26
235 self.main_view = self.get_root_instance().select_single(MainView)
236
237 @autopilot_logging.log_action(logger.info)
238 def click_next(self):
239 toolbar = self.main_view.get_toolbar()
240 next_button = toolbar.select_single('Button', objectName='nextButton')
241 self.pointing_device.click_object(next_button)
242
243
244class AppendFeedPage(Page):
245 """Autopilot helper for the Append Feed page."""
246
247 @autopilot_logging.log_action(logger.info)
248 def search_feed(self, keyword_or_url):
249 search_text_field = self.select_single(
250 toolkit_emulators.TextField, objectName='tfFeedUrl')
251 # Write and press enter.
252 search_text_field.write(keyword_or_url + '\n')
253 self._wait_for_results_to_appear()
254
255 def _wait_for_results_to_appear(self):
256 results_list = self._get_results_list()
257 results_list.count.wait_for(NotEquals(0))
258
259 def _get_results_list(self):
260 return self.select_single(
261 toolkit_emulators.QQuickListView, objectName='feedpagelistview')
262
263 @autopilot_logging.log_action(logger.info)
264 def select_results(self, *results):
265 """Select feed items from the list of results.
266
267 :param results: The titles of the items to select from the list.
268
269 """
270 for result in results:
271 self._check_result(result)
272
273 def click_next(self):
274 super(AppendFeedPage, self).click_next()
275 return self.main_view.select_single(
276 ChooseTopicPage, objectName='choosetopicpage')
277
278 def _check_result(self, result):
279 results_list = self._get_results_list()
280 results_list.click_element('feedpagelistitem-{}'.format(result))
281
282
283class ChooseTopicPage(Page):
284 """Autopilot helper for the Choose Topic Page page."""
285
286 @autopilot_logging.log_action(logger.info)
287 def add_topic(self, topic):
288 new_topic_text_field = self.select_single(
289 toolkit_emulators.TextField, objectName='newTopic')
290 # Write and press enter.
291 new_topic_text_field.write(topic + '\n')
203292
=== modified file 'tests/autopilot/shorts_app/tests/test_rssreader.py'
--- tests/autopilot/shorts_app/tests/test_rssreader.py 2014-02-13 03:52:29 +0000
+++ tests/autopilot/shorts_app/tests/test_rssreader.py 2014-03-04 04:12:43 +0000
@@ -1,9 +1,18 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical2#
3#3# Copyright (C) 2013, 2014 Canonical Ltd.
4# This program is free software: you can redistribute it and/or modify it4#
5# under the terms of the GNU General Public License version 3, as published5# This program is free software; you can redistribute it and/or modify
6# by the Free Software Foundation.6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation; version 3.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
716
8"""shorts app autopilot tests."""17"""shorts app autopilot tests."""
918
@@ -42,79 +51,28 @@
42 self.main_view.get_network_activity,51 self.main_view.get_network_activity,
43 Eventually(Equals(None), timeout=60))52 Eventually(Equals(None), timeout=60))
4453
45 def _add_feed_and_topic(self, feed, topicName):54 def add_feed_to_new_topic(self, feed_url, feed_title, topic):
46 """test add feed and topic"""55 add_feeds_page = self.main_view.go_to_add_feeds()
47 logger.debug("starting test add feed and topic")56 # XXX here we are using an external server because we are currently
4857 # using the Google Feed API, which doesn't let us access local
49 self.assertThat(self.main_view.get_topics_page,58 # resources. --elopio - 2014-02-26
50 Eventually(NotEquals(None)))59 add_feeds_page.search_feed(feed_url)
51 #open toolbar60 add_feeds_page.select_results(feed_title)
52 logger.debug("opening toolbar")61 choose_topics_page = add_feeds_page.click_next()
53 toolbar = self.main_view.open_toolbar()62 choose_topics_page.add_topic(topic)
5463 # TODO move this wait to the main view custom proxy object.
55 #click on add reads toolbar button64 # --elopio - 2014-02-26
56 logger.debug("clicking addreadsbutton")
57 toolbar.click_button("addreadsbutton")
58
59 #click on add feeds popover action
60 logger.debug("clicking + Add feeds")
61 addReadsPopover = self.main_view.get_action_popover()
62 self.main_view.run_action(addReadsPopover, "+ Add feeds")
63
64 #verify Append Feed page is open
65 logger.debug("asserting append page")
66 appendpage = lambda: self.main_view.get_append_page().visible
67 self.assertThat(appendpage, Eventually(Equals(True)))
68
69 #type feed in input field
70 logger.debug("inputting feed")
71 self._input_new_feed(feed)
72
73 #click on checkbox to confirm feed
74 logger.debug("asserting checkbox")
75 self.assertThat(self.main_view.get_append_page_feed,
76 Eventually(Not(Is(None))))
77 logger.debug("grabbing checkbox")
78 checkboxBtn = self.main_view.get_append_page_feed()
79 logger.debug("clicking checkbox")
80 self.pointing_device.click_object(checkboxBtn)
81 logger.debug("asserting checkbox checked")
82 self.assertThat(checkboxBtn.checked, Eventually(Equals(True)))
83
84 #save selected feedname
85 feedName = self.main_view.strip_html_tags(
86 str(self.main_view.get_append_page_list_items()[0].text))
87
88 #click on Next button
89 logger.debug("asserting next")
90 self.assertThat(self.main_view.get_next_button,
91 Eventually(Not(Is(None))))
92 logger.debug("grabbing next")
93 nextButton = self.main_view.get_next_button()
94 logger.debug("clicking next")
95 self.pointing_device.click_object(nextButton)
96
97 #verify choose topic page has opened
98 logger.debug("asserting choose topic page")
99 chossetopicpage = lambda: self.main_view.get_topics_page().visible
100 self.assertThat(chossetopicpage, Eventually(Equals(True)))
101
102 #get current topics
103 logger.debug("grabbing topics")
104 topics = self.main_view.get_choose_topics_items()
105 numTopics = len(topics)
106 logger.debug("found " + str(numTopics) + " topics")
107 for topic in topics:
108 logger.debug("Topic: " + str(topic.text))
109
110 #add a new topic
111 logger.debug("input topic")
112 self._input_new_topic(topicName)
113
114 #wait for new feed and topic to be added
115 self._wait_for_refresh()65 self._wait_for_refresh()
11666
117 return feedName67 def test_add_feed_to_new_topic(self):
68 """Test that adding a feed to a new topic must show it in a new tab."""
69 test_feed_url = 'http://www.canonical.com/rss.xml'
70 test_feed_title = 'Insights'
71 test_topic = 'Test topic'
72 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
73
74 selected_tab_title = self.main_view.get_selected_tab_title()
75 self.assertEqual('Test topic', selected_tab_title)
11876
119 def _remove_feed(self, feedName, topicName):77 def _remove_feed(self, feedName, topicName):
120 logger.debug("removing feed")78 logger.debug("removing feed")
@@ -268,55 +226,32 @@
268 poll += 1226 poll += 1
269 return topic227 return topic
270228
271 def test_add_remove_feed_and_topic(self):229 def test_remove_feed_and_topic(self):
272 """ test add and remove feed and topic"""230 """ test add and remove feed and topic"""
273231 test_feed_url = 'http://www.canonical.com/rss.xml'
274 #add topic and feed232 test_feed_title = 'Insights'
275 #TODO, try several different feeds233 test_topic = 'Test topic'
276 feed = "http://www.canonical.com/rss.xml"234 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
277 feedName = "Insights"
278 topicName = "CanonicalTopic"
279
280 #just for timing issues
281 self.assertThat(self.main_view.get_shorts_tab(),
282 NotEquals(None))
283 self.assertThat(self.main_view.get_shorts_tab().objectName,
284 Eventually(Equals("Tab0")))
285 self.assertThat(self.main_view.get_shorts_tab().visible,
286 Eventually(Equals(True)))
287
288 #add feed and topic
289 feedName = self._add_feed_and_topic(feed, topicName)
290235
291 #remove added feed236 #remove added feed
292 logger.debug("starting remove feed")237 logger.debug("starting remove feed")
293238
294 self._remove_feed(feedName, topicName)239 self._remove_feed(test_feed_title, test_topic)
295240
296 #remove added topic241 #remove added topic
297 self._remove_topic(topicName)242 self._remove_topic(test_topic)
298243
299 @unittest.skip("Tab switching fails")244 @unittest.skip("Tab switching fails")
300 def test_view_mode_and_feed_item(self):245 def test_view_mode_and_feed_item(self):
301 """test view modes and ensure feed items can be opened"""246 """test view modes and ensure feed items can be opened"""
302247 test_feed_url = 'http://www.canonical.com/rss.xml'
303 feed = "http://www.canonical.com/rss.xml"248 test_feed_title = 'Insights'
304 #feedName = "Insights"249 test_topic = 'Test topic'
305 topicName = "CanonicalTopic"250
306251 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
307 #just for timing issues
308 self.assertThat(self.main_view.get_shorts_tab(),
309 NotEquals(None))
310 self.assertThat(self.main_view.get_shorts_tab().objectName,
311 Eventually(Equals("Tab0")))
312 self.assertThat(self.main_view.get_shorts_tab().visible,
313 Eventually(Equals(True)))
314
315 #add topic and feed
316 self._add_feed_and_topic(feed, topicName)
317252
318 #verify we are on the editTopic Tab253 #verify we are on the editTopic Tab
319 editTab = self.main_view.get_topic_tab(topicName)254 editTab = self.main_view.get_topic_tab(test_topic)
320 self.assertThat(lambda: editTab.visible, Eventually(Equals(True)))255 self.assertThat(lambda: editTab.visible, Eventually(Equals(True)))
321256
322 #open toolbar257 #open toolbar
@@ -344,9 +279,9 @@
344 #self.assertThat(lambda: feedTab.visible, Eventually(Equals(True)))279 #self.assertThat(lambda: feedTab.visible, Eventually(Equals(True)))
345280
346 #select feed entry281 #select feed entry
347 self.assertThat(lambda: self.main_view.get_feedlist(topicName),282 self.assertThat(lambda: self.main_view.get_feedlist(test_topic),
348 Eventually(Not(Is(None))))283 Eventually(Not(Is(None))))
349 editFeed = self.main_view.get_feedlist(topicName)284 editFeed = self.main_view.get_feedlist(test_topic)
350285
351 for item in editFeed:286 for item in editFeed:
352 label = item.select_single("Label", objectName="labelFeedname")287 label = item.select_single("Label", objectName="labelFeedname")
@@ -362,16 +297,14 @@
362 @unittest.skip("Can't see or get dynamic tabs")297 @unittest.skip("Can't see or get dynamic tabs")
363 def test_edit_topic(self):298 def test_edit_topic(self):
364 """test edit topic"""299 """test edit topic"""
365300 test_feed_url = 'http://www.canonical.com/rss.xml'
366 feed = "http://www.canonical.com/rss.xml"301 test_feed_title = 'Insights'
367 feedName = "Insights"302 test_topic = 'Test topic'
368 topicName = "CanonicalTopic"303
369304 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
370 #add topic and feed
371 feedName = self._add_feed_and_topic(feed, topicName)
372305
373 #verify we are on the topicName Tab306 #verify we are on the topicName Tab
374 editTab = self.main_view.get_topic_tab(topicName)307 editTab = self.main_view.get_topic_tab(test_topic)
375 self.assertThat(editTab.visible, Eventually(Equals(True)))308 self.assertThat(editTab.visible, Eventually(Equals(True)))
376309
377 #open toolbar310 #open toolbar
@@ -387,12 +320,12 @@
387 Eventually(Equals("topicmanagement")))320 Eventually(Equals("topicmanagement")))
388321
389 #verity Tab is expanded322 #verity Tab is expanded
390 editTopic = self.main_view.get_feedlist_topic(topicName)323 editTopic = self.main_view.get_feedlist_topic(test_topic)
391 if editTopic.state != "expended":324 if editTopic.state != "expended":
392 self.pointing_device.click_object(editTopic)325 self.pointing_device.click_object(editTopic)
393326
394 #select feed327 #select feed
395 editFeed = self.main_view.get_feedlist_feed(feedName)328 editFeed = self.main_view.get_feedlist_feed(test_topic)
396 self.assertThat(editFeed, NotEquals(None))329 self.assertThat(editFeed, NotEquals(None))
397 self.pointing_device.click_object(editFeed)330 self.pointing_device.click_object(editFeed)
398331

Subscribers

People subscribed via source and target branches