Merge lp:~nskaggs/ubuntu-rssreader-app/fix-ap-layout into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/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
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
=== modified file 'tests/autopilot/shorts_app/__init__.py'
--- tests/autopilot/shorts_app/__init__.py 2014-09-17 20:18:37 +0000
+++ tests/autopilot/shorts_app/__init__.py 2014-12-17 00:05:17 +0000
@@ -7,7 +7,6 @@
77
8"""RSS reader app tests and emulators - top level package."""8"""RSS reader app tests and emulators - top level package."""
99
10import os
11import logging10import logging
12from time import sleep11from time import sleep
1312
@@ -15,7 +14,6 @@
15from testtools.matchers import NotEquals14from testtools.matchers import NotEquals
1615
17from ubuntuuitoolkit import (16from ubuntuuitoolkit import (
18 base,
19 emulators as toolkit_emulators17 emulators as toolkit_emulators
20)18)
2119
@@ -23,63 +21,18 @@
23logger = logging.getLogger(__name__)21logger = logging.getLogger(__name__)
2422
2523
26class ShortsApp():24class ShortsApp(object):
2725
28 """App class"""26 """Autopilot helper object for shorts."""
29 local_location = "../../shorts-app.qml"27
30 installed_location = "/usr/share/shorts-app/shorts-app.qml"28 def __init__(self, app_proxy, test_type):
3129 self.app = app_proxy
32 def __init__(self, test_obj):30 self.test_type = test_type
33 """Constructor31 self.main_view = self.app.select_single(MainView)
34
35 :param test_obj: An AutopilotTestCase object
36 """
37 self.test_obj = test_obj
38 launch, self.test_type = self.setup_environment()
39 self.app = launch()
40
41 def setup_environment(self):
42 """Selects the way to launch the application"""
43 if os.path.exists(self.local_location):
44 logger.debug("Running via local installation")
45 launch = self.launch_test_local
46 test_type = 'local'
47 elif os.path.exists(self.installed_location):
48 logger.debug("Running via installed debian package")
49 launch = self.launch_test_installed
50 test_type = 'deb'
51 else:
52 logger.debug("Running via click package")
53 launch = self.launch_test_click
54 test_type = 'click'
55 return launch, test_type
56
57 def launch_test_local(self):
58 """Launch the application using a relative path"""
59 return self.test_obj.launch_test_application(
60 base.get_qmlscene_launch_command(),
61 self.local_location,
62 app_type='qt',
63 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
64
65 def launch_test_installed(self):
66 """Launch the application using the system path"""
67 return self.test_obj.launch_test_application(
68 base.get_qmlscene_launch_command(),
69 self.installed_location,
70 app_type='qt',
71 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
72
73 def launch_test_click(self):
74 """Launch the application using click package"""
75 return self.test_obj.launch_click_package(
76 "com.ubuntu.shorts",
77 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
7832
79 @property33 @property
80 def main_view(self):34 def pointing_device(self):
81 """Return MainView object"""35 return self.app.pointing_device
82 return self.app.select_single(MainView)
8336
8437
85class ShortsAppException(Exception):38class ShortsAppException(Exception):
@@ -227,7 +180,8 @@
227 return self.select_single("ManageTopicsPage")180 return self.select_single("ManageTopicsPage")
228181
229 def get_rss_feed_page(self):182 def get_rss_feed_page(self):
230 return self.wait_select_single("RssFeedPage", objectName="rssfeedpage")183 return self.wait_select_single("ArticleViewPage",
184 objectName="rssfeedpage")
231185
232 def get_shorts_tab(self):186 def get_shorts_tab(self):
233 return self.wait_select_single("ShortsTab", objectName="Tab0")187 return self.wait_select_single("ShortsTab", objectName="Tab0")
234188
=== modified file 'tests/autopilot/shorts_app/tests/__init__.py'
--- tests/autopilot/shorts_app/tests/__init__.py 2014-06-27 15:21:04 +0000
+++ tests/autopilot/shorts_app/tests/__init__.py 2014-12-17 00:05:17 +0000
@@ -20,72 +20,123 @@
20"""shorts-app autopilot tests."""20"""shorts-app autopilot tests."""
2121
22import os.path22import os.path
23import os
24import shutil23import shutil
25import logging24import logging
2625
27from autopilot.input import Mouse, Touch, Pointer
28from autopilot.platform import model26from autopilot.platform import model
27from autopilot import logging as autopilot_logging
29from autopilot.testcase import AutopilotTestCase28from autopilot.testcase import AutopilotTestCase
3029
31from shorts_app import ShortsApp30import shorts_app
31
32import ubuntuuitoolkit
33from ubuntuuitoolkit import base
34import fixtures
3235
33logger = logging.getLogger(__name__)36logger = logging.getLogger(__name__)
3437
3538
36class ShortsAppTestCase(AutopilotTestCase):39class BaseTestCaseWithPatchedHome(AutopilotTestCase):
3740
38 """A common test case class that provides several useful methods for41 """A common test case class that provides several useful methods for
39 rssreader-app tests.42 rssreader-app tests.
4043
41 """44 """
42 if model() == 'Desktop':45
43 scenarios = [('with mouse', dict(input_device_class=Mouse))]46 local_location = os.path.dirname(os.path.dirname(os.getcwd()))
44 else:47 local_location_qml = os.path.join(local_location, 'shorts-app.qml')
45 scenarios = [('with touch', dict(input_device_class=Touch))]48 installed_location_qml = "/usr/share/shorts-app/shorts-app.qml"
4649
47 sqlite_dir = os.path.expanduser(50 def get_launcher_and_type(self):
48 "~/.local/share/com.ubuntu.shorts/Databases")51 if os.path.exists(self.local_location_qml):
49 backup_dir = sqlite_dir + ".backup"52 launcher = self.launch_test_local
53 test_type = 'local'
54 elif os.path.exists(self.installed_location_qml):
55 launcher = self.launch_test_installed
56 test_type = 'deb'
57 else:
58 launcher = self.launch_test_click
59 test_type = 'click'
60 return launcher, test_type
5061
51 def setUp(self):62 def setUp(self):
52 self.pointing_device = Pointer(self.input_device_class.create())63 super(BaseTestCaseWithPatchedHome, self).setUp()
53 super(ShortsAppTestCase, self).setUp()64 self.launcher, self.test_type = self.get_launcher_and_type()
54 self.temp_move_sqlite_db()65 self.home_dir = self.patch_home()
55 self.addCleanup(self.restore_sqlite_db)
5666
57 # turn off the OSK so it doesn't block screen elements67 # turn off the OSK so it doesn't block screen elements
58 if model() != 'Desktop':68 if model() != 'Desktop':
59 os.system("stop maliit-server")69 os.system("stop maliit-server")
60 self.addCleanup(os.system, "start maliit-server")70 self.addCleanup(os.system, "start maliit-server")
6171
62 self.shorts_app = ShortsApp(self)72 @autopilot_logging.log_action(logger.info)
6373 def launch_test_local(self):
64 def temp_move_sqlite_db(self):74 return self.launch_test_application(
65 try:75 base.get_qmlscene_launch_command(),
66 shutil.rmtree(self.backup_dir)76 self.local_location_qml,
67 except:77 app_type='qt',
68 pass78 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
69 else:79
70 logger.warning("Prexisting backup database found and removed")80 @autopilot_logging.log_action(logger.info)
7181 def launch_test_installed(self):
72 try:82 return self.launch_test_application(
73 shutil.move(self.sqlite_dir, self.backup_dir)83 base.get_qmlscene_launch_command(),
74 except:84 self.installed_location_qml,
75 logger.warning("No current database found")85 app_type='qt',
76 else:86 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
77 logger.debug("Backed up database")87
7888 @autopilot_logging.log_action(logger.info)
79 def restore_sqlite_db(self):89 def launch_test_click(self):
80 if os.path.exists(self.backup_dir):90 return self.launch_click_package(
81 if os.path.exists(self.sqlite_dir):91 "com.ubuntu.shorts",
82 try:92 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
83 shutil.rmtree(self.sqlite_dir)93
84 except:94 def _copy_xauthority_file(self, directory):
85 logger.error("Failed to remove test database and restore" /95 """ Copy .Xauthority file to directory, if it exists in /home
86 "database")96 """
87 return97 # If running under xvfb, as jenkins does,
88 try:98 # xsession will fail to start without xauthority file
89 shutil.move(self.backup_dir, self.sqlite_dir)99 # Thus if the Xauthority file is in the home directory
90 except:100 # make sure we copy it to our temp home directory
91 logger.error("Failed to restore database")101
102 xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
103 '.Xauthority'))
104 if os.path.isfile(xauth):
105 logger.debug("Copying .Xauthority to %s" % directory)
106 shutil.copyfile(
107 os.path.expanduser(os.path.join(os.environ.get('HOME'),
108 '.Xauthority')),
109 os.path.join(directory, '.Xauthority'))
110
111 def patch_home(self):
112 """ mock /home for testing purposes to preserve user data
113 """
114
115 # if running on non-phablet device,
116 # run in temp folder to avoid mucking up home
117 # bug 1316746
118 # bug 1376423
119 if self.test_type is 'click':
120 # just use home for now on devices
121 temp_dir = os.environ.get('HOME')
122 else:
123 temp_dir_fixture = fixtures.TempDir()
124 self.useFixture(temp_dir_fixture)
125 temp_dir = temp_dir_fixture.path
126
127 # before we set fixture, copy xauthority if needed
128 self._copy_xauthority_file(temp_dir)
129 self.useFixture(fixtures.EnvironmentVariable('HOME',
130 newvalue=temp_dir))
131
132 logger.debug("Patched home to fake home directory %s" % temp_dir)
133 return temp_dir
134
135
136class ShortsAppTestCase(BaseTestCaseWithPatchedHome):
137
138 """Base test case that launches shorts-app"""
139
140 def setUp(self):
141 super(ShortsAppTestCase, self).setUp()
142 self.app = shorts_app.ShortsApp(self.launcher(), self.test_type)
92143
=== modified file 'tests/autopilot/shorts_app/tests/test_rssreader.py'
--- tests/autopilot/shorts_app/tests/test_rssreader.py 2014-09-17 20:18:37 +0000
+++ tests/autopilot/shorts_app/tests/test_rssreader.py 2014-12-17 00:05:17 +0000
@@ -16,8 +16,6 @@
1616
17"""shorts app autopilot tests."""17"""shorts app autopilot tests."""
1818
19from __future__ import absolute_import
20
21from autopilot.matchers import Eventually19from autopilot.matchers import Eventually
22from testtools.matchers import Equals, NotEquals20from testtools.matchers import Equals, NotEquals
2321
@@ -36,7 +34,6 @@
3634
37 def setUp(self):35 def setUp(self):
38 super(BaseShortsAppTestCase, self).setUp()36 super(BaseShortsAppTestCase, self).setUp()
39 self.shorts_app.main_view.visible.wait_for(True)
4037
41 # wait for any updates to finish before beginning tests38 # wait for any updates to finish before beginning tests
42 self._wait_for_refresh()39 self._wait_for_refresh()
@@ -44,18 +41,18 @@
44 def _wait_for_refresh(self):41 def _wait_for_refresh(self):
45 try:42 try:
46 self.assertThat(43 self.assertThat(
47 self.shorts_app.main_view.get_network_activity,44 self.app.main_view.get_network_activity,
48 Eventually(NotEquals(None), timeout=5))45 Eventually(NotEquals(None), timeout=5))
49 self.assertThat(46 self.assertThat(
50 self.shorts_app.main_view.get_network_activity,47 self.app.main_view.get_network_activity,
51 Eventually(Equals(None), timeout=60))48 Eventually(Equals(None), timeout=60))
52 except:49 except:
53 self.assertThat(50 self.assertThat(
54 self.shorts_app.main_view.get_network_activity,51 self.app.main_view.get_network_activity,
55 Eventually(Equals(None), timeout=60))52 Eventually(Equals(None), timeout=60))
5653
57 def add_feed_to_new_topic(self, feed_url, feed_title, topic):54 def add_feed_to_new_topic(self, feed_url, feed_title, topic):
58 add_feeds_page = self.shorts_app.main_view.go_to_add_feeds()55 add_feeds_page = self.app.main_view.go_to_add_feeds()
59 # XXX here we are using an external server because we are currently56 # XXX here we are using an external server because we are currently
60 # using the Google Feed API, which doesn't let us access local57 # using the Google Feed API, which doesn't let us access local
61 # resources. --elopio - 2014-02-2658 # resources. --elopio - 2014-02-26
@@ -77,30 +74,30 @@
77 test_topic = 'Test topic'74 test_topic = 'Test topic'
78 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)75 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
7976
80 selected_tab_title = self.shorts_app.main_view.get_selected_tab_title()77 selected_tab_title = self.app.main_view.get_selected_tab_title()
81 self.assertEqual('Test topic', selected_tab_title)78 self.assertEqual('Test topic', selected_tab_title)
8279
83 def test_switch_to_list_view_mode(self):80 def test_switch_to_list_view_mode(self):
84 """ test switching to list view mode"""81 """ test switching to list view mode"""
85 shorts_tab = self.shorts_app.main_view.get_shorts_tab()82 shorts_tab = self.app.main_view.get_shorts_tab()
86 self._ensure_grid_view_mode(shorts_tab)83 self._ensure_grid_view_mode(shorts_tab)
87 self.shorts_app.main_view.change_view_mode("isNotListMode")84 self.app.main_view.change_view_mode("isNotListMode")
88 self.assertThat(shorts_tab.isListMode, Eventually(Equals(True)))85 self.assertThat(shorts_tab.isListMode, Eventually(Equals(True)))
8986
90 def test_switch_to_grid_view_mode(self):87 def test_switch_to_grid_view_mode(self):
91 """ test switching to grid view mode"""88 """ test switching to grid view mode"""
92 shorts_tab = self.shorts_app.main_view.get_shorts_tab()89 shorts_tab = self.app.main_view.get_shorts_tab()
93 self._ensure_list_view_mode(shorts_tab)90 self._ensure_list_view_mode(shorts_tab)
94 self.shorts_app.main_view.change_view_mode("isListMode")91 self.app.main_view.change_view_mode("isListMode")
95 self.assertThat(shorts_tab.isListMode, Eventually(Equals(False)))92 self.assertThat(shorts_tab.isListMode, Eventually(Equals(False)))
9693
97 def _ensure_grid_view_mode(self, current_tab):94 def _ensure_grid_view_mode(self, current_tab):
98 if current_tab.isListMode:95 if current_tab.isListMode:
99 self.shorts_app.main_view.change_view_mode("isListMode")96 self.app.main_view.change_view_mode("isListMode")
10097
101 def _ensure_list_view_mode(self, current_tab):98 def _ensure_list_view_mode(self, current_tab):
102 if not current_tab.isListMode:99 if not current_tab.isListMode:
103 self.shorts_app.main_view.change_view_mode("isNotListMode")100 self.app.main_view.change_view_mode("isNotListMode")
104101
105 def test_open_listmode_feed_item(self):102 def test_open_listmode_feed_item(self):
106 """"test to ensure list mode feed items can be opened"""103 """"test to ensure list mode feed items can be opened"""
@@ -110,14 +107,14 @@
110 test_topic = 'Test topic'107 test_topic = 'Test topic'
111108
112 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)109 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
113 new_topic_tab = self.shorts_app.main_view.get_topic_tab(test_topic)110 new_topic_tab = self.app.main_view.get_topic_tab(test_topic)
114 self._ensure_list_view_mode(new_topic_tab)111 self._ensure_list_view_mode(new_topic_tab)
115112
116 self.shorts_app.main_view.open_feed_item(test_topic, test_feed_title)113 self.app.main_view.open_feed_item(test_topic, test_feed_title)
117 self.assertEqual(114 self.assertEqual(
118 self.shorts_app.main_view.get_feed_in_feedlist_title(115 self.app.main_view.get_feed_in_feedlist_title(
119 test_topic, test_feed_title),116 test_topic, test_feed_title),
120 self.shorts_app.main_view.get_articleviewitem_title())117 self.app.main_view.get_articleviewitem_title())
121118
122 @unittest.skip("Can't see or get dynamic tabs")119 @unittest.skip("Can't see or get dynamic tabs")
123 def test_edit_topic(self):120 def test_edit_topic(self):
@@ -129,43 +126,43 @@
129 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)126 self.add_feed_to_new_topic(test_feed_url, test_feed_title, test_topic)
130127
131 # verify we are on the topicName Tab128 # verify we are on the topicName Tab
132 editTab = self.shorts_app.main_view.get_topic_tab(test_topic)129 editTab = self.app.main_view.get_topic_tab(test_topic)
133 self.assertThat(editTab.visible, Eventually(Equals(True)))130 self.assertThat(editTab.visible, Eventually(Equals(True)))
134131
135 # open toolbar132 # open toolbar
136 toolbar = self.shorts_app.main_view.open_toolbar()133 toolbar = self.app.main_view.open_toolbar()
137134
138 # click on edit topics button135 # click on edit topics button
139 toolbar.click_button("edittopicsbutton")136 toolbar.click_button("edittopicsbutton")
140137
141 # verify we are on topic management page138 # verify we are on topic management page
142 topicmanagementpage = \139 topicmanagementpage = \
143 self.shorts_app.main_view.get_feed_management_page()140 self.app.main_view.get_feed_management_page()
144 self.assertThat(141 self.assertThat(
145 topicmanagementpage.objectName,142 topicmanagementpage.objectName,
146 Eventually(Equals("topicmanagement")))143 Eventually(Equals("topicmanagement")))
147144
148 # verity Tab is expanded145 # verity Tab is expanded
149 editTopic = self.shorts_app.main_view.get_feedlist_topic(test_topic)146 editTopic = self.app.main_view.get_feedlist_topic(test_topic)
150 if editTopic.state != "expanded":147 if editTopic.state != "expanded":
151 self.pointing_device.click_object(editTopic)148 self.pointing_device.click_object(editTopic)
152149
153 # select feed150 # select feed
154 editFeed = self.shorts_app.main_view.get_feedlist_feed(test_topic)151 editFeed = self.app.main_view.get_feedlist_feed(test_topic)
155 self.assertThat(editFeed, NotEquals(None))152 self.assertThat(editFeed, NotEquals(None))
156 self.pointing_device.click_object(editFeed)153 self.pointing_device.click_object(editFeed)
157154
158 # verify we are on edit feed page155 # verify we are on edit feed page
159 editfeedpage = self.shorts_app.main_view.get_edit_feed_page()156 editfeedpage = self.app.main_view.get_edit_feed_page()
160 self.assertThat(editfeedpage.visible, Eventually(Equals(True)))157 self.assertThat(editfeedpage.visible, Eventually(Equals(True)))
161158
162 # change topic from dropdown159 # change topic from dropdown
163 topicValueselector = \160 topicValueselector = \
164 self.shorts_app.main_view.get_editfeed_topic_valueselector()161 self.app.main_view.get_editfeed_topic_valueselector()
165 self.pointing_device.click_object(topicValueselector)162 self.pointing_device.click_object(topicValueselector)
166163
167 # click on news topic164 # click on news topic
168 topicValueselectorValue = self.shorts_app.main_view. \165 topicValueselectorValue = self.app.main_view. \
169 get_editfeed_valueselector_value("Ubuntu")166 get_editfeed_valueselector_value("Ubuntu")
170 self.pointing_device.click_object(topicValueselectorValue)167 self.pointing_device.click_object(topicValueselectorValue)
171168
@@ -186,7 +183,7 @@
186183
187 def test_remove_feed(self):184 def test_remove_feed(self):
188 """Test the removal of a feed from the Edit Feeds page."""185 """Test the removal of a feed from the Edit Feeds page."""
189 edit_feeds_page = self.shorts_app.main_view.go_to_edit_feeds()186 edit_feeds_page = self.app.main_view.go_to_edit_feeds()
190 edit_feeds_page.expand_topic(self.test_topic)187 edit_feeds_page.expand_topic(self.test_topic)
191 feeds = edit_feeds_page.get_feeds_in_topic(self.test_topic)188 feeds = edit_feeds_page.get_feeds_in_topic(self.test_topic)
192 self.assertIn(self.test_feed_title, feeds)189 self.assertIn(self.test_feed_title, feeds)
@@ -196,7 +193,7 @@
196193
197 def test_remove_topic(self):194 def test_remove_topic(self):
198 """Test the removal of a topic from the Edit Topics page."""195 """Test the removal of a topic from the Edit Topics page."""
199 edit_feeds_page = self.shorts_app.main_view.go_to_edit_feeds()196 edit_feeds_page = self.app.main_view.go_to_edit_feeds()
200 edit_feeds_page.delete_topic(self.test_topic)197 edit_feeds_page.delete_topic(self.test_topic)
201 topics = edit_feeds_page.get_topics()198 topics = edit_feeds_page.get_topics()
202 self.assertNotIn(self.test_topic, topics)199 self.assertNotIn(self.test_topic, topics)

Subscribers

People subscribed via source and target branches