Merge lp:~canonical-platform-qa/gallery-app/clean_delete_autopilot_tests into lp:~artmello/gallery-app/gallery-app-fix_autopilot_tests

Proposed by Leo Arias on 2015-04-16
Status: Merged
Approved by: Arthur Mello on 2015-04-20
Approved revision: 1193
Merged at revision: 1192
Proposed branch: lp:~canonical-platform-qa/gallery-app/clean_delete_autopilot_tests
Merge into: lp:~artmello/gallery-app/gallery-app-fix_autopilot_tests
Diff against target: 195 lines (+69/-49)
2 files modified
tests/autopilot/gallery_app/emulators/photo_viewer.py (+44/-16)
tests/autopilot/gallery_app/tests/test_photo_viewer.py (+25/-33)
To merge this branch: bzr merge lp:~canonical-platform-qa/gallery-app/clean_delete_autopilot_tests
Reviewer Review Type Date Requested Status
Arthur Mello 2015-04-16 Approve on 2015-04-20
Review via email: mp+256592@code.launchpad.net

This proposal supersedes a proposal from 2015-04-16.

Commit Message

Added an autopilot test to check the deletion of a photo.

Description of the Change

Please note a couple of things from this branch:

1. The helpers are split into classes that represent the parts of the screen that we are interacting with: all the helpers related to the PopupPhotoViewer are written in the respective class.

2. The public methods of the classes are named after actions that a user does: delete_current_photo, click_yes.

3. The public methods are annotated so they leave a log trace when they are called. In case of error, you can read the log and see what the test was excecutiong when an error was found.

4. A test does a single action and has a single check at the end:
delete a photo and check that it no longer exists in the filesystem.

I left an XXX comment on the old delete test because it has to be split in smaller tests. And as those smaller tests are not representing a user goal, they should be written in QML. Arthur said he was going to start writing those tests, when he is done the old delete autopilot test can be removed.

To post a comment you must log in.
1193. By Leo Arias on 2015-04-16

Updated the logs, removed unused method.

Arthur Mello (artmello) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/gallery_app/emulators/photo_viewer.py'
2--- tests/autopilot/gallery_app/emulators/photo_viewer.py 2015-04-15 17:45:14 +0000
3+++ tests/autopilot/gallery_app/emulators/photo_viewer.py 2015-04-16 22:02:22 +0000
4@@ -5,28 +5,62 @@
5 # under the terms of the GNU General Public License version 3, as published
6 # by the Free Software Foundation.
7
8+import logging
9+
10+import autopilot.logging
11+import ubuntuuitoolkit
12+
13+from gallery_app.emulators import main_screen
14 from gallery_app.emulators.gallery_utils import(
15 GalleryAppException,
16 GalleryUtils
17 )
18
19
20+logger = logging.getLogger(__name__)
21+
22+
23+class PopupPhotoViewer(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
24+
25+ @autopilot.logging.log_action(logger.info)
26+ def delete_current_photo(self, confirm=True):
27+ header = self.get_root_instance().select_single(
28+ main_screen.MainScreen).get_header()
29+ header.click_action_button("deleteButton")
30+ if confirm:
31+ self.confirm_delete_photo()
32+ else:
33+ self.cancel_delete_photo()
34+
35+ @autopilot.logging.log_action(logger.debug)
36+ def confirm_delete_photo(self):
37+ self._click_delete_dialog_button("Yes")
38+
39+ def _click_delete_dialog_button(self, name):
40+ delete_dialog = self._get_delete_dialog()
41+ button = delete_dialog.wait_select_single(
42+ "Button", objectName="deletePhotoDialog" + name, visible=True)
43+ self.pointing_device.click_object(button)
44+ delete_dialog.wait_until_destroyed()
45+
46+ def _get_delete_dialog(self):
47+ delete_dialog = self.get_root_instance().wait_select_single(
48+ objectName="deletePhotoDialog")
49+ delete_dialog.visible.wait_for(True)
50+ delete_dialog.opacity.wait_for(1)
51+ return delete_dialog
52+
53+ @autopilot.logging.log_action(logger.debug)
54+ def cancel_delete_photo(self):
55+ self._click_delete_dialog_button('No')
56+
57+
58 class PhotoViewer(GalleryUtils):
59
60 def __init__(self, app):
61 super(PhotoViewer, self).__init__(self)
62 self.app = app
63
64- def get_delete_dialog(self):
65- """Returns the photo viewer delete dialog."""
66- return self.app.wait_select_single("Dialog",
67- objectName="deletePhotoDialog")
68-
69- def delete_dialog_shown(self):
70- dialog = self.app.select_many("Dialog",
71- objectName="deletePhotoDialog")
72- return len(dialog) >= 1
73-
74 def get_popup_album_picker(self):
75 """Returns the photo viewer album pickers."""
76 return self.app.wait_select_single("PopupAlbumPicker",
77@@ -118,12 +152,6 @@
78 """Returns the 'auto enhance' menu item in the edit dialog."""
79 return self.app.select_single("Standard", objectName='enhanceListItem')
80
81- def get_delete_popover_delete_item(self):
82- """Returns the delete button of the delete popover."""
83- return self.app.wait_select_single("Button",
84- objectName="deletePhotoDialogYes",
85- visible=True)
86-
87 def get_delete_popover_cancel_item(self):
88 """Returns the cancel button of the delete popover."""
89 return self.app.wait_select_single("Button",
90
91=== modified file 'tests/autopilot/gallery_app/tests/test_photo_viewer.py'
92--- tests/autopilot/gallery_app/tests/test_photo_viewer.py 2015-04-15 17:45:14 +0000
93+++ tests/autopilot/gallery_app/tests/test_photo_viewer.py 2015-04-16 22:02:22 +0000
94@@ -8,12 +8,12 @@
95
96 """Tests the Photo editor of the gallery app."""
97
98-from testtools.matchers import Equals, NotEquals, GreaterThan, Is
99+from testtools.matchers import Equals, NotEquals, GreaterThan
100 from autopilot.matchers import Eventually
101 from testtools import skipIf
102 from autopilot.platform import model
103
104-from gallery_app.emulators.photo_viewer import PhotoViewer
105+from gallery_app.emulators import photo_viewer
106 from gallery_app.emulators.media_viewer import MediaViewer
107 from gallery_app.emulators.events_view import EventsView
108 from gallery_app.tests import GalleryTestCase
109@@ -31,7 +31,7 @@
110 class TestMediaViewerBase(GalleryTestCase):
111 @property
112 def photo_viewer(self):
113- return PhotoViewer(self.app)
114+ return photo_viewer.PhotoViewer(self.app)
115
116 @property
117 def events_view(self):
118@@ -93,16 +93,6 @@
119 photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
120 self.assertThat(photo_viewer_loader.source, Equals(""))
121
122- def get_delete_dialog(self):
123- delete_dialog = self.photo_viewer.get_delete_dialog()
124- self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
125- self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
126- return delete_dialog
127-
128- def ensure_closed_delete_dialog(self):
129- self.assertThat(self.photo_viewer.delete_dialog_shown,
130- Eventually(Is(False)))
131-
132 def test_nav_bar_back_button(self):
133 """Clicking the back button must close the photo."""
134 self.main_view.get_header().click_custom_back_button()
135@@ -120,38 +110,40 @@
136 self.click_item(cancel_button)
137 self.assertThat(share_picker.visible, Eventually(Equals(False)))
138
139- def delete_one_picture(self):
140- self.main_view.get_header().click_action_button("deleteButton")
141- self.get_delete_dialog()
142- delete_item = self.photo_viewer.get_delete_popover_delete_item()
143- self.click_item(delete_item)
144- self.ensure_closed_delete_dialog()
145+ def test_delete_photo_must_remove_it_from_filesystem(self):
146+ photo_component = self.main_view.select_single('GalleryPhotoComponent')
147+ source = photo_component.source
148+ file_path = source[len('image://thumbnailer/file://'):]
149+ self.assertTrue(os.path.exists(file_path))
150+
151+ photo_viewer_popup = self.main_view.select_single(
152+ photo_viewer.PopupPhotoViewer)
153+ photo_viewer_popup.delete_current_photo()
154+
155+ self.assertFalse(os.path.exists(file_path))
156
157 def test_photo_delete_works(self):
158 """Clicking the trash button must show the delete dialog."""
159- self.main_view.get_header().click_action_button("deleteButton")
160- self.get_delete_dialog()
161-
162- photo_viewer = self.photo_viewer.get_main_photo_viewer()
163-
164- cancel_item = self.photo_viewer.get_delete_popover_cancel_item()
165- self.click_item(cancel_item)
166- self.ensure_closed_delete_dialog()
167+ # XXX This test must be split into multiple QML tests.
168+ # --elopio - 2015-14-16
169+ photo_viewer_popup = self.main_view.select_single(
170+ photo_viewer.PopupPhotoViewer)
171+ photo_viewer_popup.delete_current_photo(confirm=False)
172
173 self.assertThat(lambda: os.path.exists(self.sample_file),
174 Eventually(Equals(True)))
175
176- self.delete_one_picture()
177+ photo_viewer_popup.delete_current_photo()
178 self.assertThat(lambda: os.path.exists(self.sample_file),
179 Eventually(Equals(False)))
180
181 # Delete all other pictures and make sure the photo viewer closes
182- self.delete_one_picture()
183- self.delete_one_picture()
184- self.delete_one_picture()
185- self.delete_one_picture()
186+ photo_viewer_popup.delete_current_photo()
187+ photo_viewer_popup.delete_current_photo()
188+ photo_viewer_popup.delete_current_photo()
189+ photo_viewer_popup.delete_current_photo()
190
191- self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
192+ self.assertThat(photo_viewer_popup.visible, Eventually(Equals(False)))
193
194 def test_nav_bar_album_picker_button(self):
195 """Clicking the album picker must show the picker dialog."""

Subscribers

People subscribed via source and target branches