Merge lp:~vrruiz/gallery-app/autopilot-app-class into lp:gallery-app

Proposed by Víctor R. Ruiz
Status: Needs review
Proposed branch: lp:~vrruiz/gallery-app/autopilot-app-class
Merge into: lp:gallery-app
Diff against target: 2084 lines (+720/-698)
9 files modified
tests/autopilot/gallery_app/__init__.py (+415/-0)
tests/autopilot/gallery_app/tests/__init__.py (+6/-280)
tests/autopilot/gallery_app/tests/test_album_editor.py (+34/-54)
tests/autopilot/gallery_app/tests/test_album_view.py (+55/-56)
tests/autopilot/gallery_app/tests/test_albums_view.py (+11/-19)
tests/autopilot/gallery_app/tests/test_events_view.py (+41/-53)
tests/autopilot/gallery_app/tests/test_photo_viewer.py (+102/-156)
tests/autopilot/gallery_app/tests/test_photos_view.py (+35/-48)
tests/autopilot/gallery_app/tests/test_picker_mode.py (+21/-32)
To merge this branch: bzr merge lp:~vrruiz/gallery-app/autopilot-app-class
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Leo Arias (community) Needs Fixing
Review via email: mp+222667@code.launchpad.net

Commit message

Create a class to drive the UI, and refactor test cases to use it.

Description of the change

Create a class to drive the UI, and refactor test cases to use it.

To post a comment you must log in.
Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

One thing to think about: the UI-driver methods were moved from the case classes to GalleryApp. The problem is that some of them use asserts, that make sense as part of tests, but not so much a pure UI test. Right now, it's not a big deal, because the test_case is a required argument to instantiate GalleryApp, but in the medium term, we won't have it.

Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

Another comment. The code is a not as elegant as it could be: lots of direct calls to the UI in the test cases. They probably can be refactored, but that wasn't the target of the present changes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

> One thing to think about: the UI-driver methods were moved from the case
> classes to GalleryApp. The problem is that some of them use asserts, that make
> sense as part of tests, but not so much a pure UI test. Right now, it's not a
> big deal, because the test_case is a required argument to instantiate
> GalleryApp, but in the medium term, we won't have it.

I think that's just what we want, move the assertions out of the helpers and into the tests.
Many assertions can be replaced by wait_for.

Revision history for this message
Leo Arias (elopio) wrote :

Victor, I'm sorry it took so long to make this review. You will likely have to merge with trunk now.
I'll try harder to make the reviews the same day. But next time I won't make soon a review you request please keep pinging me. I'll owe you a beer for every day you wait :)

For the gallery and apps developers: this change seeks to make it easier for us to test multiple applications at the same time. On its own, it just seems like a huge branch not really useful, and now you will have to call something like self.app.main_view instead of just self.main_view. But it makes a lot of sense when you see a test like this:

address_book = AddressBook.launch()
add_contact_page = address_book.main_view.go_to_add_contact()
add_contact_page.click_contact_image()
gallery_app = GalleryApp()
gallery_app.main_view.pick_image(...)
add_contact_page.main_view.fill_form(...)
add_contact_page.save()

For that we need to move the app helpers out of the test cases because there's no nice way to make a test case that inherits from both the base test cases in address book and gallery.

review: Needs Fixing
Revision history for this message
Leo Arias (elopio) wrote :

Sorry, about the comment:
This empty line is not needed.

I mean, the line between

from pkg_resources import resource_filename

and

from ubuntuuitoolkit import emulators as toolkit_emulators.

999. By Víctor R. Ruiz

Merge with trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

999. By Víctor R. Ruiz

Merge with trunk

998. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_picker_mode)

997. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_photos_view)

996. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_photo_viewer)

995. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_events_view)

994. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_album_view)

993. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_albums_view)

992. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_albums_view)

991. By Víctor R. Ruiz

Autopilot: Refactor for app class pattern (test_album_editor)

990. By Víctor R. Ruiz

Autopilot: Refactoring for app class pattern

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/gallery_app/__init__.py'
2--- tests/autopilot/gallery_app/__init__.py 2013-03-19 13:04:59 +0000
3+++ tests/autopilot/gallery_app/__init__.py 2014-07-02 14:17:44 +0000
4@@ -6,3 +6,418 @@
5 # by the Free Software Foundation.
6
7 """Autopilot tests and emulators for gallery - top level package."""
8+
9+import os
10+import logging
11+import shutil
12+import signal
13+
14+from time import sleep
15+
16+from testtools.matchers import Equals, NotEquals, GreaterThan, Is
17+from autopilot.matchers import Eventually
18+from autopilot.platform import model
19+from autopilot.introspection import get_proxy_object_for_existing_process
20+from pkg_resources import resource_filename
21+
22+from ubuntuuitoolkit import emulators as toolkit_emulators
23+
24+from gallery_app.emulators import main_screen
25+from gallery_app.emulators.album_editor import AlbumEditor
26+from gallery_app.emulators.album_view import AlbumView
27+from gallery_app.emulators.albums_view import AlbumsView
28+from gallery_app.emulators.events_view import EventsView
29+from gallery_app.emulators.gallery_utils import GalleryUtils
30+from gallery_app.emulators.media_selector import MediaSelector
31+from gallery_app.emulators.media_viewer import MediaViewer
32+from gallery_app.emulators.photo_viewer import PhotoViewer
33+from gallery_app.emulators.photos_view import PhotosView
34+from gallery_app.emulators.picker_screen import PickerScreen
35+
36+logger = logging.getLogger(__name__)
37+
38+
39+class EnvironmentTypes:
40+ installed = "installed"
41+ local = "local"
42+ click = "click"
43+
44+
45+class GalleryApp():
46+ """A class to drive the UI of the gallery-app."""
47+
48+ sample_file_source = "/sample01.jpg"
49+ local_location = "../src/gallery-app"
50+ tap_press_time = 1
51+
52+ _db = '~/.local/share/com.ubuntu.gallery/gallery-app/' \
53+ 'database/gallery.sqlite'
54+ _thumbs = '~/.cache/com.ubuntu.gallery/gallery-app/thumbnails'
55+
56+ _default_sample_destination_dir = "/tmp/gallery-ap_sd"
57+ sample_destination_dir = ""
58+
59+ args = []
60+ app = None
61+
62+ def __init__(self, test_case, args=[]):
63+ """Constructor
64+
65+ :param test_case: An AutopilotTestCase object. This is required
66+ to be able to launch the application.
67+
68+ """
69+ # Start app
70+ self.args = args
71+ self.test_case = test_case
72+ env_type = self._get_environment_launch_type()
73+ self.configure_sample_files(env_type)
74+ self.launch_gallery_app(env_type)
75+
76+ def __del__(self):
77+ """Destructor"""
78+ shutil.rmtree(self.sample_destination_dir)
79+
80+ @property
81+ def gallery_utils(self):
82+ return GalleryUtils(self.app)
83+
84+ @property
85+ def main_view(self):
86+ return self.app.select_single(main_screen.MainScreen)
87+
88+ @property
89+ def album_editor(self):
90+ return self.app.select_single(AlbumEditor)
91+
92+ @property
93+ def album_view(self):
94+ return AlbumView(self.app)
95+
96+ @property
97+ def albums_view(self):
98+ return AlbumsView(self.app)
99+
100+ @property
101+ def events_view(self):
102+ return EventsView(self.app)
103+
104+ @property
105+ def media_selector(self):
106+ return MediaSelector(self.app)
107+
108+ @property
109+ def media_view(self):
110+ return self.app.select_single(MediaViewer)
111+
112+ @property
113+ def photo_viewer(self):
114+ return PhotoViewer(self.app)
115+
116+ @property
117+ def photos_view(self):
118+ return PhotosView(self.app)
119+
120+ @property
121+ def picker_view(self):
122+ return self.app.select_single(PickerScreen)
123+
124+ def _get_environment_launch_type(self):
125+ """Returns the type of the environment in which to setup and launch
126+ gallery-app.
127+
128+ """
129+ # Lets assume we are installed system wide if this file is somewhere
130+ # in /usr
131+ if os.path.realpath(__file__).startswith("/usr/"):
132+ return EnvironmentTypes.installed
133+ if model() == 'Desktop':
134+ return EnvironmentTypes.installed
135+ else:
136+ if os.path.exists(self.local_location):
137+ return EnvironmentTypes.local
138+ else:
139+ return EnvironmentTypes.click
140+
141+ def _get_sample_destination_dir(self, env_type):
142+ if env_type == EnvironmentTypes.click:
143+ pic_dir = os.path.expanduser("~/Pictures")
144+ pic_bak_dir = pic_dir + '.apbak'
145+ # Only save and restore if it previously existed
146+ if os.path.exists(pic_dir):
147+ shutil.move(pic_dir, pic_bak_dir)
148+ self.addCleanup(
149+ logger.debug, "Restoring backed up pics to %s" % pic_dir)
150+ self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
151+ return pic_dir
152+ else:
153+ return self._default_sample_destination_dir
154+
155+ def configure_db(self):
156+ db = os.path.expanduser(self._db)
157+ db_bak = db + '.apbak'
158+ # Only save and restore if it previously existed
159+ if os.path.exists(db):
160+ shutil.move(db, db_bak)
161+ self.addCleanup(shutil.move, db_bak, db)
162+ if not os.path.exists(os.path.dirname(db)):
163+ os.makedirs(os.path.dirname(db))
164+ mock_db = os.path.join(self.sample_destination_dir, '.database',
165+ 'gallery_confined.sqlite')
166+ shutil.move(mock_db, db)
167+
168+ def configure_thumbnails(self):
169+ thumbs = os.path.expanduser(self._thumbs)
170+ thumbs_bak = thumbs + '.apbak'
171+ # Only save and restore if it previously existed
172+ if os.path.exists(thumbs):
173+ shutil.move(thumbs, thumbs_bak)
174+ self.addCleanup(shutil.move, thumbs_bak, thumbs)
175+ if not os.path.exists(os.path.dirname(thumbs)):
176+ os.makedirs(os.path.dirname(thumbs))
177+ mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
178+ shutil.move(mock_thumbs, thumbs)
179+
180+ def configure_sample_files(self, env_type):
181+ self.sample_dir = resource_filename('gallery_app', 'data')
182+ self.sample_destination_dir = \
183+ self._get_sample_destination_dir(env_type)
184+ if (os.path.exists(self.sample_destination_dir)):
185+ shutil.rmtree(self.sample_destination_dir)
186+ ## FIXME self.assertFalse(os.path.exists(self.sample_destination_dir))
187+
188+ self.sample_file = os.path.join(
189+ self.sample_destination_dir,
190+ "sample04.jpg"
191+ )
192+
193+ default_data_dir = os.path.join(
194+ self.sample_dir,
195+ "default")
196+ shutil.copytree(default_data_dir, self.sample_destination_dir)
197+ ## FIXME self.assertTrue(os.path.isfile(self.sample_file))
198+
199+ self.sample_file_source = \
200+ default_data_dir + self.sample_file_source
201+
202+ if env_type == EnvironmentTypes.click:
203+ self.configure_db()
204+ self.configure_thumbnails()
205+
206+ def do_reset_config(self):
207+ config = os.path.expanduser(
208+ os.path.join("~", ".config", "gallery-app.conf"))
209+ if os.path.exists(config):
210+ os.remove(config)
211+
212+ @property
213+ def pointing_device(self):
214+ """Return pointing device"""
215+ return toolkit_emulators.get_pointing_device()
216+
217+ def launch_gallery_app(self, env_type):
218+ """Launch"""
219+ if env_type == EnvironmentTypes.installed:
220+ self.launch_test_installed()
221+ elif env_type == EnvironmentTypes.local:
222+ self.launch_test_local()
223+ elif env_type == EnvironmentTypes.click:
224+ self.launch_test_click()
225+ else:
226+ raise ValueError("Unknown environment type: %s", env_type)
227+
228+ def launch_test_local(self):
229+ logger.debug("Launching local gallery-app binary.")
230+ self.args.append(self.sample_destination_dir)
231+ self.app = self.test_case.launch_test_application(
232+ self.local_location,
233+ *self.args,
234+ emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
235+
236+ def launch_test_installed(self):
237+ if model() == 'Desktop':
238+ logger.debug(
239+ "Launching installed gallery-app binary for desktop."
240+ )
241+ self.args.append(self.sample_destination_dir)
242+ self.app = self.test_case.launch_test_application(
243+ "gallery-app",
244+ *self.args,
245+ emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
246+ else:
247+ logger.debug(
248+ "Launching installed gallery-app binary for device."
249+ )
250+ self.args.append("--desktop_file_hint="
251+ "/usr/share/applications/gallery-app.desktop")
252+ self.args.append(self.sample_destination_dir)
253+ self.app = self.test_case.launch_test_application(
254+ "gallery-app",
255+ *self.args,
256+ app_type='qt',
257+ emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
258+
259+ def launch_test_click(self):
260+ """
261+ Since this test runs under confinement, the only location photos
262+ are searchable in is ~/Pictures.
263+ """
264+ logger.debug("Launching gallery-app via click package.")
265+ self.app = self.test_case.launch_click_package(
266+ package_id="com.ubuntu.gallery",
267+ app_uris=' '.join(self.args),
268+ emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
269+
270+ def ui_update(self):
271+ """ Gives the program the time to update the UI"""
272+ sleep(0.1)
273+
274+ def click_item(self, item, delay=0.1):
275+ """Does a mouse click on the passed item, and moved the mouse there
276+ before"""
277+ # In jenkins test may fail because we don't wait before clicking the
278+ # target so we add a little delay before click.
279+ if model() == 'Desktop' and delay <= 0.25:
280+ delay = 0.25
281+
282+ self.pointing_device.move_to_object(item)
283+ sleep(delay)
284+ self.pointing_device.click()
285+
286+ def tap_item(self, item):
287+ """Does a long mouse press on the passed item, and moved the mouse
288+ there before"""
289+ self.pointing_device.move_to_object(item)
290+ self.pointing_device.press()
291+ sleep(1)
292+ self.pointing_device.release()
293+
294+ def switch_to_albums_tab(self):
295+ self.main_view.switch_to_tab("albumsTab")
296+
297+ albums_loader = self.gallery_utils.get_albums_viewer_loader()
298+ self.test_case.assertThat(albums_loader.progress, Eventually(Equals(1)))
299+
300+ # The next check assumes that at least one album is available
301+ # Check if the albums are availabe - they need some time to load.
302+ self.test_case.assertThat(lambda: len(self.gallery_utils.get_all_albums()),
303+ Eventually(GreaterThan(0)))
304+ self.ensure_tabs_dont_move()
305+
306+ def ensure_tabs_dont_move(self):
307+ # FIXME find a (functional) way to test if the tabs still move
308+ sleep(1)
309+
310+ def open_album_at(self, position):
311+ album = self.album_view.get_album_at(position)
312+ # workaround lp:1247698
313+ self.main_view.close_toolbar()
314+ self.click_item(album)
315+ self.ensure_view_is_fully_open()
316+
317+ def open_first_album(self):
318+ self.open_album_at(-1)
319+
320+ def get_delete_dialog(self):
321+ """Raises StateNotFoundError if get_delete_dialog fails."""
322+ delete_dialog = self.gallery_utils.get_delete_dialog()
323+ return delete_dialog
324+
325+ def edit_first_album(self):
326+ """Edit first album."""
327+ first_album = self.gallery_utils.get_first_album()
328+ # workaround lp:1247698
329+ self.main_view.close_toolbar()
330+ self.tap_item(first_album)
331+ edit_button = self.gallery_utils.get_edit_album_button()
332+ self.click_item(edit_button)
333+
334+ def ensure_view_is_fully_open(self):
335+ view = self.album_view.get_album_view()
336+ self.test_case.assertThat(view.visible, Eventually(Equals(True)))
337+
338+ def ensure_app_has_quit(self):
339+ """Terminate as gracefully as possible the application and ensure
340+ that it has fully quit before returning"""
341+
342+ if model() == "Desktop":
343+ # On desktop to cleanly quit an app we just do the
344+ # equivalent of clicking on the close button in the window.
345+ self.keyboard.press_and_release("Alt+F4")
346+ else:
347+ # On unity8 at the moment we have no clean way to close the app.
348+ # So we ask the shell first to show the home, unfocusing our app,
349+ # which will save its state. Then we simply send it a SIGTERM to
350+ # force it to quit.
351+ # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more
352+ # details.
353+ from unity8 import process_helpers
354+ pid = process_helpers._get_unity_pid()
355+ unity8 = get_proxy_object_for_existing_process(pid)
356+ shell = unity8.select_single("Shell")
357+ shell.slots.showHome()
358+ self.test_case.assertThat(shell.currentFocusedAppId,
359+ Eventually(NotEquals("gallery-app"))) # FIXME
360+ self.app.process.send_signal(signal.SIGTERM)
361+
362+ # Either way, we wait for the underlying process to be fully finished.
363+ self.app.process.wait()
364+ self.test_case.assertIsNotNone(self.app.process.returncode) # FIXME
365+
366+ def get_events_view(self):
367+ return self.app.wait_select_single("EventsOverview",
368+ objectName="organicEventView")
369+
370+ def enable_select_mode(self):
371+ self.main_view.open_toolbar().click_button("selectButton")
372+
373+ def delete_one_picture(self):
374+ self.main_view.open_toolbar().click_button("deleteButton")
375+ self.get_delete_dialog()
376+ delete_item = self.photo_viewer.get_delete_popover_delete_item()
377+ self.click_item(delete_item)
378+ self.ensure_closed_delete_dialog()
379+
380+ def open_first_photo(self):
381+ self.test_case.assertThat(
382+ lambda: self.events_view.number_of_photos_in_events(),
383+ Eventually(GreaterThan(0))
384+ )
385+
386+ # workaround lp:1247698
387+ # toolbar needs to be gone to click on an image.
388+ self.main_view.close_toolbar()
389+
390+ self.events_view.click_photo(self.sample_file)
391+
392+ photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
393+ self.test_case.assertThat(photo_viewer_loader.loaded, Eventually(Equals(True)))
394+ sleep(1)
395+ photo_viewer = self.photo_viewer.get_main_photo_viewer()
396+ self.test_case.assertThat(photo_viewer.visible, Eventually(Equals(True)))
397+
398+ def ensure_closed_delete_dialog(self):
399+ self.test_case.assertThat(self.photo_viewer.delete_dialog_shown,
400+ Eventually(Is(False)))
401+
402+ def click_edit_button(self):
403+ self.main_view.open_toolbar().click_button("editButton")
404+ edit_dialog = self.photo_viewer.get_photo_edit_dialog()
405+ self.test_case.assertThat(edit_dialog.visible, (Eventually(Equals(True))))
406+ self.test_case.assertThat(edit_dialog.opacity, (Eventually(Equals(1))))
407+
408+ def switch_to_photos_tab(self):
409+ self.main_view.switch_to_tab("photosTab")
410+ self.ensure_tabs_dont_move()
411+
412+ def click_first_photo(self):
413+ photo = self.photos_view.get_first_photo_in_photos_view()
414+ self.click_item(photo)
415+
416+ def select_first_event_media(self):
417+ first_media = self.picker_view.first_media_in_events_view()
418+ self.click_item(first_media)
419+
420+ def select_first_grid_media(self):
421+ first_media = self.picker_view.first_media_in_events_view()
422+ self.click_item(first_media)
423
424=== modified file 'tests/autopilot/gallery_app/tests/__init__.py'
425--- tests/autopilot/gallery_app/tests/__init__.py 2014-06-10 18:54:21 +0000
426+++ tests/autopilot/gallery_app/tests/__init__.py 2014-07-02 14:17:44 +0000
427@@ -7,304 +7,30 @@
428
429 """gallery autopilot tests."""
430
431-import os
432-import logging
433-import shutil
434-import signal
435+from time import sleep
436
437-from testtools.matchers import Equals, NotEquals, GreaterThan
438+from testtools.matchers import Equals
439 from autopilot.matchers import Eventually
440-from autopilot.platform import model
441 from autopilot.testcase import AutopilotTestCase
442-from autopilot.introspection import get_proxy_object_for_existing_process
443-from pkg_resources import resource_filename
444-
445-from ubuntuuitoolkit import emulators as toolkit_emulators
446-from gallery_app.emulators import main_screen
447-from gallery_app.emulators.gallery_utils import GalleryUtils
448-
449-from time import sleep
450-
451-logger = logging.getLogger(__name__)
452-
453-
454-class EnvironmentTypes:
455- installed = "installed"
456- local = "local"
457- click = "click"
458+
459+from gallery_app import GalleryApp
460
461
462 class GalleryTestCase(AutopilotTestCase):
463-
464 """A common test case class that provides several useful methods for
465 gallery tests."""
466
467- sample_file_source = "/sample01.jpg"
468- tap_press_time = 1
469- local_location = "../../src/gallery-app"
470-
471- _db = '~/.local/share/com.ubuntu.gallery/gallery-app/' \
472- 'database/gallery.sqlite'
473- _thumbs = '~/.cache/com.ubuntu.gallery/gallery-app/thumbnails'
474-
475- _default_sample_destination_dir = "/tmp/gallery-ap_sd"
476-
477 ARGS = []
478
479- @property
480- def gallery_utils(self):
481- return GalleryUtils(self.app)
482-
483- @property
484- def main_view(self):
485- return self.app.select_single(main_screen.MainScreen)
486-
487- def _get_environment_launch_type(self):
488- """Returns the type of the environment in which to setup and launch
489- gallery-app.
490-
491- """
492- # Lets assume we are installed system wide if this file is somewhere
493- # in /usr
494- if os.path.realpath(__file__).startswith("/usr/"):
495- return EnvironmentTypes.installed
496- if model() == 'Desktop':
497- return EnvironmentTypes.installed
498- else:
499- if os.path.exists(self.local_location):
500- return EnvironmentTypes.local
501- else:
502- return EnvironmentTypes.click
503-
504- def _get_sample_destination_dir(self, env_type):
505- if env_type == EnvironmentTypes.click:
506- pic_dir = os.path.expanduser("~/Pictures")
507- pic_bak_dir = pic_dir + '.apbak'
508- # Only save and restore if it previously existed
509- if os.path.exists(pic_dir):
510- shutil.move(pic_dir, pic_bak_dir)
511- self.addCleanup(
512- logger.debug, "Restoring backed up pics to %s" % pic_dir)
513- self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
514- return pic_dir
515- else:
516- return self._default_sample_destination_dir
517-
518- def configure_db(self):
519- db = os.path.expanduser(self._db)
520- db_bak = db + '.apbak'
521- # Only save and restore if it previously existed
522- if os.path.exists(db):
523- shutil.move(db, db_bak)
524- self.addCleanup(shutil.move, db_bak, db)
525- if not os.path.exists(os.path.dirname(db)):
526- os.makedirs(os.path.dirname(db))
527- mock_db = os.path.join(self.sample_destination_dir, '.database',
528- 'gallery_confined.sqlite')
529- shutil.move(mock_db, db)
530-
531- def configure_thumbnails(self):
532- thumbs = os.path.expanduser(self._thumbs)
533- thumbs_bak = thumbs + '.apbak'
534- # Only save and restore if it previously existed
535- if os.path.exists(thumbs):
536- shutil.move(thumbs, thumbs_bak)
537- self.addCleanup(shutil.move, thumbs_bak, thumbs)
538- if not os.path.exists(os.path.dirname(thumbs)):
539- os.makedirs(os.path.dirname(thumbs))
540- mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
541- shutil.move(mock_thumbs, thumbs)
542-
543- def configure_sample_files(self, env_type):
544- self.sample_dir = resource_filename('gallery_app', 'data')
545- self.sample_destination_dir = \
546- self._get_sample_destination_dir(env_type)
547- if (os.path.exists(self.sample_destination_dir)):
548- shutil.rmtree(self.sample_destination_dir)
549- self.assertFalse(os.path.exists(self.sample_destination_dir))
550-
551- self.sample_file = os.path.join(
552- self.sample_destination_dir,
553- "sample04.jpg"
554- )
555-
556- default_data_dir = os.path.join(
557- self.sample_dir,
558- "default")
559- shutil.copytree(default_data_dir, self.sample_destination_dir)
560- self.assertTrue(os.path.isfile(self.sample_file))
561-
562- self.sample_file_source = \
563- default_data_dir + self.sample_file_source
564-
565- if env_type == EnvironmentTypes.click:
566- self.configure_db()
567- self.configure_thumbnails()
568-
569- def do_reset_config(self):
570- config = os.path.expanduser(
571- os.path.join("~", ".config", "gallery-app.conf"))
572- if os.path.exists(config):
573- os.remove(config)
574-
575 def setUp(self):
576- self.pointing_device = toolkit_emulators.get_pointing_device()
577 super(GalleryTestCase, self).setUp()
578
579- env_type = self._get_environment_launch_type()
580- self.configure_sample_files(env_type)
581-
582- self.launch_gallery_app(env_type)
583-
584- self.addCleanup(shutil.rmtree, self.sample_destination_dir)
585- self.addCleanup(logger.debug,
586- "Deleting %s" % self.sample_destination_dir)
587+ self.gallery_app = GalleryApp(self, self.ARGS)
588
589 """ This is needed to wait for the application to start.
590 In the testfarm, the application may take some time to show up."""
591- self.assertThat(self.gallery_utils.get_qml_view().visible,
592+ self.assertThat(self.gallery_app.gallery_utils.get_qml_view().visible,
593 Eventually(Equals(True)))
594 """FIXME somehow on the server gallery sometimes is not fully started
595 for switching to the albums view. Therefore this hack of sleeping"""
596 sleep(2)
597-
598- def launch_gallery_app(self, env_type):
599- if env_type == EnvironmentTypes.installed:
600- self.launch_test_installed()
601- elif env_type == EnvironmentTypes.local:
602- self.launch_test_local()
603- elif env_type == EnvironmentTypes.click:
604- self.launch_test_click()
605- else:
606- raise ValueError("Unknown environment type: %s", env_type)
607-
608- def launch_test_local(self):
609- logger.debug("Launching local gallery-app binary.")
610- self.ARGS.append(self.sample_destination_dir)
611- self.app = self.launch_test_application(
612- self.local_location,
613- *self.ARGS,
614- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
615-
616- def launch_test_installed(self):
617- if model() == 'Desktop':
618- logger.debug(
619- "Launching installed gallery-app binary for desktop."
620- )
621- self.ARGS.append(self.sample_destination_dir)
622- self.app = self.launch_test_application(
623- "gallery-app",
624- *self.ARGS,
625- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
626- else:
627- logger.debug(
628- "Launching installed gallery-app binary for device."
629- )
630- self.ARGS.append("--desktop_file_hint="
631- "/usr/share/applications/gallery-app.desktop")
632- self.ARGS.append(self.sample_destination_dir)
633- self.app = self.launch_test_application(
634- "gallery-app",
635- *self.ARGS,
636- app_type='qt',
637- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
638-
639- def launch_test_click(self):
640- '''
641- Since this test runs under confinement, the only location photos
642- are searchable in is ~/Pictures.
643- '''
644- logger.debug("Launching gallery-app via click package.")
645- self.app = self.launch_click_package(
646- package_id="com.ubuntu.gallery",
647- app_uris=' '.join(self.ARGS),
648- emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
649-
650- def ui_update(self):
651- """ Gives the program the time to update the UI"""
652- sleep(0.1)
653-
654- def click_item(self, item, delay=0.1):
655- """Does a mouse click on the passed item, and moved the mouse there
656- before"""
657- # In jenkins test may fail because we don't wait before clicking the
658- # target so we add a little delay before click.
659- if model() == 'Desktop' and delay <= 0.25:
660- delay = 0.25
661-
662- self.pointing_device.move_to_object(item)
663- sleep(delay)
664- self.pointing_device.click()
665-
666- def tap_item(self, item):
667- """Does a long mouse press on the passed item, and moved the mouse
668- there before"""
669- self.pointing_device.move_to_object(item)
670- self.pointing_device.press()
671- sleep(1)
672- self.pointing_device.release()
673-
674- def switch_to_albums_tab(self):
675- self.main_view.switch_to_tab("albumsTab")
676-
677- albums_loader = self.gallery_utils.get_albums_viewer_loader()
678- self.assertThat(albums_loader.progress, Eventually(Equals(1)))
679-
680- # The next check assumes that at least one album is available
681- # Check if the albums are availabe - they need some time to load.
682- self.assertThat(lambda: len(self.gallery_utils.get_all_albums()),
683- Eventually(GreaterThan(0)))
684- self.ensure_tabs_dont_move()
685-
686- def ensure_tabs_dont_move(self):
687- # FIXME find a (functional) way to test if the tabs still move
688- sleep(1)
689-
690- def open_album_at(self, position):
691- album = self.album_view.get_album_at(position)
692- # workaround lp:1247698
693- self.main_view.close_toolbar()
694- self.click_item(album)
695- self.ensure_view_is_fully_open()
696-
697- def open_first_album(self):
698- self.open_album_at(-1)
699-
700- def ensure_view_is_fully_open(self):
701- view = self.album_view.get_album_view()
702- self.assertThat(view.visible, Eventually(Equals(True)))
703-
704- def ensure_app_has_quit(self):
705- """Terminate as gracefully as possible the application and ensure
706- that it has fully quit before returning"""
707-
708- if model() == "Desktop":
709- # On desktop to cleanly quit an app we just do the
710- # equivalent of clicking on the close button in the window.
711- self.keyboard.press_and_release("Alt+F4")
712- else:
713- # On unity8 at the moment we have no clean way to close the app.
714- # So we ask the shell first to show the home, unfocusing our app,
715- # which will save its state. Then we simply send it a SIGTERM to
716- # force it to quit.
717- # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more
718- # details.
719- from unity8 import process_helpers
720- pid = process_helpers._get_unity_pid()
721- unity8 = get_proxy_object_for_existing_process(pid)
722- shell = unity8.select_single("Shell")
723- shell.slots.showHome()
724- self.assertThat(shell.currentFocusedAppId,
725- Eventually(NotEquals("gallery-app")))
726- self.app.process.send_signal(signal.SIGTERM)
727-
728- # Either way, we wait for the underlying process to be fully finished.
729- self.app.process.wait()
730- self.assertIsNotNone(self.app.process.returncode)
731-
732- def get_delete_dialog(self):
733- """Raises StateNotFoundError if get_delete_dialog fails."""
734- delete_dialog = self.gallery_utils.get_delete_dialog()
735- self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
736- self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
737- return delete_dialog
738
739=== modified file 'tests/autopilot/gallery_app/tests/test_album_editor.py'
740--- tests/autopilot/gallery_app/tests/test_album_editor.py 2014-06-10 19:00:23 +0000
741+++ tests/autopilot/gallery_app/tests/test_album_editor.py 2014-07-02 14:17:44 +0000
742@@ -11,9 +11,7 @@
743 from testtools.matchers import Equals
744 from autopilot.matchers import Eventually
745
746-from gallery_app.emulators.album_view import AlbumView
747-from gallery_app.emulators.media_selector import MediaSelector
748-from gallery_app.emulators import album_editor
749+from gallery_app import GalleryApp
750 from gallery_app.tests import GalleryTestCase
751
752 from time import sleep
753@@ -21,34 +19,17 @@
754 class TestAlbumEditor(GalleryTestCase):
755 """Tests the album editor of the gallery app"""
756
757- @property
758- def album_view(self):
759- return AlbumView(self.app)
760-
761- @property
762- def media_selector(self):
763- return MediaSelector(self.app)
764-
765 def setUp(self):
766- self.ARGS = []
767 super(TestAlbumEditor, self).setUp()
768- self.switch_to_albums_tab()
769- self.main_view.close_toolbar()
770- self.edit_first_album()
771-
772- def edit_first_album(self):
773- first_album = self.gallery_utils.get_first_album()
774- # workaround lp:1247698
775- self.main_view.close_toolbar()
776- self.tap_item(first_album)
777- edit_button = self.gallery_utils.get_edit_album_button()
778- self.click_item(edit_button)
779- editor = self.app.select_single(album_editor.AlbumEditor)
780+ self.gallery_app.switch_to_albums_tab()
781+ self.gallery_app.main_view.close_toolbar()
782+ self.gallery_app.edit_first_album()
783+ editor = self.gallery_app.album_editor
784 editor.ensure_fully_open()
785
786 def test_album_title_fields(self):
787 """tests the title and sub title"""
788- editor = self.app.select_single(album_editor.AlbumEditor)
789+ editor = self.gallery_app.album_editor
790 title_field = editor.album_title_entry_field()
791 subtitle_field = editor.album_subtitle_entry_field()
792
793@@ -59,7 +40,7 @@
794 self.assertThat(subtitle_field.text, Eventually(Equals(text)))
795
796 # workaround lp:1247698
797- self.main_view.close_toolbar()
798+ self.gallery_app.main_view.close_toolbar()
799 editor.click_title_field()
800 self.assertThat(title_field.activeFocus, Eventually(Equals(True)))
801 self.keyboard.press_and_release("Ctrl+a")
802@@ -80,61 +61,60 @@
803 def test_add_photo(self):
804 """Tests adding a photo using the media selector"""
805 # first open, but cancel before adding a photo
806- editor = self.app.select_single(album_editor.AlbumEditor)
807+ editor = self.gallery_app.album_editor
808 # workaround lp:1247698
809- self.main_view.close_toolbar()
810+ self.gallery_app.main_view.close_toolbar()
811 editor.add_photos()
812- self.media_selector.ensure_fully_open()
813+ self.gallery_app.media_selector.ensure_fully_open()
814
815 sleep(5)
816- self.main_view.get_toolbar().click_custom_button("cancelButton")
817+ self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
818 editor.ensure_fully_closed()
819
820- self.main_view.close_toolbar()
821- self.open_first_album()
822- num_photos_start = self.album_view.number_of_photos()
823+ self.gallery_app.main_view.close_toolbar()
824+ self.gallery_app.open_first_album()
825+ num_photos_start = self.gallery_app.album_view.number_of_photos()
826 self.assertThat(num_photos_start, Equals(1))
827- self.main_view.open_toolbar().click_button("backButton")
828- self.album_view.ensure_album_view_fully_closed()
829+ self.gallery_app.main_view.open_toolbar().click_button("backButton")
830+ self.gallery_app.album_view.ensure_album_view_fully_closed()
831
832 # now open to add a photo
833- self.main_view.close_toolbar()
834- self.edit_first_album()
835- editor = self.app.select_single(album_editor.AlbumEditor)
836+ self.gallery_app.main_view.close_toolbar()
837+ self.gallery_app.edit_first_album()
838+ editor = self.gallery_app.album_editor
839 # workaround lp:1247698
840- self.main_view.close_toolbar()
841- editor.add_photos()
842+ self.gallery_app.main_view.close_toolbar()
843+ self.gallery_app.album_editor.add_photos()
844 self.media_selector.ensure_fully_open()
845
846 photo = self.media_selector.get_second_photo()
847- self.click_item(photo)
848- self.main_view.get_toolbar().click_custom_button("addButton")
849- editor = self.app.select_single(album_editor.AlbumEditor)
850- editor.ensure_fully_closed()
851+ self.gallery_app.click_item(photo)
852+ self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
853+ self.gallery_app.album_editor.ensure_fully_closed()
854
855- self.main_view.close_toolbar()
856- self.open_first_album()
857- num_photos = self.album_view.number_of_photos()
858+ self.gallery_app.main_view.close_toolbar()
859+ self.gallery_app.open_first_album()
860+ num_photos = self.gallery_app.album_view.number_of_photos()
861 self.assertThat(num_photos, Equals(num_photos_start + 1))
862
863 def test_cover_image(self):
864 """Test to change the album cover image"""
865- editor = self.app.select_single(album_editor.AlbumEditor)
866+ editor = self.gallery_app.album_editor
867 cover_image = editor.album_cover_image()
868 self.assertThat(
869 cover_image.source.endswith("album-cover-default-large.png"),
870 Equals(True))
871- self.main_view.close_toolbar()
872+ self.gallery_app.main_view.close_toolbar()
873
874 # click somewhere rather at the bottom of the cover
875 # workaround lp:1247698
876- self.main_view.close_toolbar()
877+ self.gallery_app.main_view.close_toolbar()
878 x, y, w, h = cover_image.globalRect
879- self.pointing_device.move(x + int(w / 2), y + h - int(h / 10))
880- self.pointing_device.click()
881+ self.gallery_app.pointing_device.move(x + int(w / 2), y + h - int(h / 10))
882+ self.gallery_app.pointing_device.click()
883
884- green_item = self.gallery_utils.get_cover_menu_item("Green")
885- self.click_item(green_item)
886+ green_item = self.gallery_app.gallery_utils.get_cover_menu_item("Green")
887+ self.gallery_app.click_item(green_item)
888
889 self.assertThat(lambda: cover_image.source.endswith(
890 "album-cover-green-large.png"), Eventually(Equals(True)))
891
892=== modified file 'tests/autopilot/gallery_app/tests/test_album_view.py'
893--- tests/autopilot/gallery_app/tests/test_album_view.py 2014-06-12 16:42:04 +0000
894+++ tests/autopilot/gallery_app/tests/test_album_view.py 2014-07-02 14:17:44 +0000
895@@ -15,7 +15,6 @@
896 from gallery_app.emulators.albums_view import AlbumsView
897 from gallery_app.emulators.media_selector import MediaSelector
898 from gallery_app.emulators.photo_viewer import PhotoViewer
899-from gallery_app.emulators import album_editor
900 from gallery_app.tests import GalleryTestCase
901
902 import os
903@@ -43,72 +42,72 @@
904 return PhotoViewer(self.app)
905
906 def setUp(self):
907- self.ARGS = []
908+ self.args = []
909 super(TestAlbumView, self).setUp()
910- self.switch_to_albums_tab()
911+ self.gallery_app.switch_to_albums_tab()
912
913 def test_album_view_open_photo(self):
914- self.main_view.close_toolbar()
915- self.open_first_album()
916- self.main_view.close_toolbar()
917- photo = self.album_view.get_first_photo()
918+ self.gallery_app.main_view.close_toolbar()
919+ self.gallery_app.open_first_album()
920+ self.gallery_app.main_view.close_toolbar()
921+ photo = self.gallery_app.album_view.get_first_photo()
922 # workaround lp:1247698
923- self.main_view.close_toolbar()
924- self.click_item(photo)
925+ self.gallery_app.main_view.close_toolbar()
926+ self.gallery_app.click_item(photo)
927 sleep(5)
928- photo_view = self.main_view.wait_select_single("PopupPhotoViewer")
929+ photo_view = self.gallery_app.main_view.wait_select_single("PopupPhotoViewer")
930 self.assertThat(photo_view.visible, Eventually(Equals(True)))
931
932 def test_album_view_flipping(self):
933- self.main_view.close_toolbar()
934+ self.gallery_app.main_view.close_toolbar()
935
936 # For some reason here the album at position 0 in the autopilot list is
937 # actually the second album, they seem to be returned in reverse order.
938- self.open_album_at(0)
939- self.main_view.close_toolbar()
940+ self.gallery_app.open_album_at(0)
941+ self.gallery_app.main_view.close_toolbar()
942
943- spread = self.album_view.get_spread_view()
944+ spread = self.gallery_app.album_view.get_spread_view()
945
946 # check that we can page to the cover and back (we check for lesser
947 # than 1 because it can either be 0 if we are on a one page spread
948 # or -1 if we are on a two page spread, for example on desktop)
949- self.album_view.swipe_page_left(1)
950+ self.gallery_app.album_view.swipe_page_left(1)
951 self.assertThat(spread.viewingPage, Eventually(LessThan(1)))
952- self.album_view.swipe_page_right(0)
953+ self.gallery_app.album_view.swipe_page_right(0)
954 self.assertThat(spread.viewingPage, Eventually(Equals(1)))
955
956 # drag to next page and check we have flipped away from page 1
957 # can't check precisely for page 2 because depending on form factor
958 # and orientation we might be displaying two pages at the same time
959- self.album_view.swipe_page_right(1)
960+ self.gallery_app.album_view.swipe_page_right(1)
961 self.assertThat(spread.viewingPage, Eventually(GreaterThan(1)))
962
963 def test_add_photo(self):
964- self.main_view.close_toolbar()
965- self.open_first_album()
966- num_photos_start = self.album_view.number_of_photos()
967+ self.gallery_app.main_view.close_toolbar()
968+ self.gallery_app.open_first_album()
969+ num_photos_start = self.gallery_app.album_view.number_of_photos()
970 self.assertThat(num_photos_start, Equals(1))
971
972 # open media selector but cancel
973- self.main_view.open_toolbar().click_button("addButton")
974- self.media_selector.ensure_fully_open()
975+ self.gallery_app.main_view.open_toolbar().click_button("addButton")
976+ self.gallery_app.media_selector.ensure_fully_open()
977
978- self.main_view.get_toolbar().click_custom_button("cancelButton")
979+ self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
980 sleep(1)
981
982- num_photos = self.album_view.number_of_photos()
983+ num_photos = self.gallery_app.album_view.number_of_photos()
984 self.assertThat(num_photos, Equals(num_photos_start))
985
986 # open media selector and add a photo
987- self.main_view.open_toolbar().click_button("addButton")
988- self.media_selector.ensure_fully_open()
989+ self.gallery_app.main_view.open_toolbar().click_button("addButton")
990+ self.gallery_app.media_selector.ensure_fully_open()
991
992- photo = self.media_selector.get_second_photo()
993- self.click_item(photo)
994- self.main_view.get_toolbar().click_custom_button("addButton")
995+ photo = self.gallery_app.media_selector.get_second_photo()
996+ self.gallery_app.click_item(photo)
997+ self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
998
999 self.assertThat(
1000- lambda: self.album_view.number_of_photos(),
1001+ lambda: self.gallery_app.album_view.number_of_photos(),
1002 Eventually(Equals(num_photos_start + 1)))
1003
1004 def test_remove_photo_from_album(self):
1005@@ -183,57 +182,57 @@
1006 Eventually(Equals(True)))
1007
1008 def test_add_photo_to_new_album(self):
1009- self.main_view.open_toolbar().click_button("addButton")
1010- self.ui_update()
1011+ self.gallery_app.main_view.open_toolbar().click_button("addButton")
1012+ self.gallery_app.ui_update()
1013
1014- editor = self.app.select_single(album_editor.AlbumEditor)
1015+ editor = self.gallery_app.album_editor
1016 editor.ensure_fully_open()
1017- self.main_view.close_toolbar()
1018+ self.gallery_app.main_view.close_toolbar()
1019 editor.close()
1020
1021- self.open_first_album()
1022- self.main_view.close_toolbar()
1023- num_photos_start = self.album_view.number_of_photos()
1024+ self.gallery_app.open_first_album()
1025+ self.gallery_app.main_view.close_toolbar()
1026+ num_photos_start = self.gallery_app.album_view.number_of_photos()
1027 self.assertThat(num_photos_start, Equals(0))
1028
1029- plus = self.album_view.get_plus_icon_empty_album()
1030+ plus = self.gallery_app.album_view.get_plus_icon_empty_album()
1031 # workaround lp:1247698
1032- self.main_view.close_toolbar()
1033- self.click_item(plus)
1034- self.media_selector.ensure_fully_open()
1035+ self.gallery_app.main_view.close_toolbar()
1036+ self.gallery_app.click_item(plus)
1037+ self.gallery_app.media_selector.ensure_fully_open()
1038
1039- photo = self.media_selector.get_second_photo()
1040- self.click_item(photo)
1041- self.main_view.get_toolbar().click_custom_button("addButton")
1042+ photo = self.gallery_app.media_selector.get_second_photo()
1043+ self.gallery_app.click_item(photo)
1044+ self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
1045
1046 self.assertThat(
1047- lambda: self.album_view.number_of_photos(),
1048+ lambda: self.gallery_app.album_view.number_of_photos(),
1049 Eventually(Equals(num_photos_start + 1)))
1050
1051 @skip("Temporarily disable as it fails in some cases, supposedly due to "
1052 "problems with the infrastructure")
1053 def test_save_state(self):
1054- self.main_view.close_toolbar()
1055- self.open_first_album()
1056-
1057- id = self.album_view.get_album_view().albumId
1058-
1059- self.ensure_app_has_quit()
1060+ self.gallery_app.main_view.close_toolbar()
1061+ self.gallery_app.open_first_album()
1062+
1063+ id = self.gallery_app.album_view.get_album_view().albumId
1064+
1065+ self.gallery_app.ensure_app_has_quit()
1066 self.start_app()
1067
1068- view = self.album_view.get_album_view()
1069+ view = self.gallery_app.album_view.get_album_view()
1070 self.assertThat(view.visible, Eventually(Equals(True)))
1071 self.assertThat(view.albumId, Eventually(Equals(id)))
1072
1073 @skip("Temporarily disable as it fails in some cases, supposedly due to "
1074 "problems with the infrastructure")
1075 def test_no_save_state_on_back(self):
1076- self.main_view.close_toolbar()
1077- self.open_first_album()
1078- self.main_view.open_toolbar().click_button("backButton")
1079+ self.gallery_app.main_view.close_toolbar()
1080+ self.gallery_app.open_first_album()
1081+ self.gallery_app.main_view.open_toolbar().click_button("backButton")
1082
1083 self.ensure_app_has_quit()
1084 self.start_app()
1085
1086- view = self.album_view.get_animated_album_view()
1087+ view = self.gallery_app.album_view.get_animated_album_view()
1088 self.assertThat(view.isOpen, Equals(False))
1089
1090=== modified file 'tests/autopilot/gallery_app/tests/test_albums_view.py'
1091--- tests/autopilot/gallery_app/tests/test_albums_view.py 2014-05-20 15:19:35 +0000
1092+++ tests/autopilot/gallery_app/tests/test_albums_view.py 2014-07-02 14:17:44 +0000
1093@@ -13,8 +13,6 @@
1094 from autopilot.platform import model
1095
1096 from gallery_app.tests import GalleryTestCase
1097-from gallery_app.emulators.albums_view import AlbumsView
1098-from gallery_app.emulators import album_editor
1099
1100 from os import environ as env
1101
1102@@ -22,13 +20,7 @@
1103 class TestAlbumsView(GalleryTestCase):
1104 envDesktopMode = None
1105
1106- @property
1107- def albums_view(self):
1108- return AlbumsView(self.app)
1109-
1110 def setUp(self):
1111- self.ARGS = []
1112-
1113 self.envDesktopMode = env.get("DESKTOP_MODE")
1114
1115 if model() == "Desktop":
1116@@ -37,7 +29,7 @@
1117 env["DESKTOP_MODE"] = "0"
1118
1119 super(TestAlbumsView, self).setUp()
1120- self.switch_to_albums_tab()
1121+ self.gallery_app.switch_to_albums_tab()
1122
1123 def tearDown(self):
1124 if self.envDesktopMode:
1125@@ -49,10 +41,10 @@
1126
1127 def test_add_album(self):
1128 """Add one album, and checks if the number of albums went up by one"""
1129- albums = self.albums_view.number_of_albums_in_albums_view()
1130- self.main_view.open_toolbar().click_button("addButton")
1131+ albums = self.gallery_app.albums_view.number_of_albums_in_albums_view()
1132+ self.gallery_app.main_view.open_toolbar().click_button("addButton")
1133 self.assertThat(
1134- lambda: self.albums_view.number_of_albums_in_albums_view(),
1135+ lambda: self.gallery_app.albums_view.number_of_albums_in_albums_view(),
1136 Eventually(Equals(albums+1))
1137 )
1138
1139@@ -60,20 +52,20 @@
1140 """Add one album, cancel it and checks if the number of albums does
1141 not change
1142 """
1143- albums = self.albums_view.number_of_albums_in_albums_view()
1144- self.main_view.open_toolbar().click_button("addButton")
1145- editor = self.app.select_single(album_editor.AlbumEditor)
1146+ albums = self.gallery_app.albums_view.number_of_albums_in_albums_view()
1147+ self.gallery_app.main_view.open_toolbar().click_button("addButton")
1148+ editor = self.gallery_app.album_editor
1149 editor.ensure_fully_open()
1150- self.main_view.get_toolbar().click_custom_button("cancelButton")
1151+ self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
1152 self.assertThat(
1153- lambda: self.albums_view.number_of_albums_in_albums_view(),
1154+ lambda: self.gallery_app.albums_view.number_of_albums_in_albums_view(),
1155 Eventually(Equals(albums))
1156 )
1157
1158 # Check if Camera Button is not visible at Desktop mode
1159 def test_camera_button_visible(self):
1160- self.main_view.open_toolbar()
1161- toolbar = self.main_view.get_toolbar()
1162+ self.gallery_app.main_view.open_toolbar()
1163+ toolbar = self.gallery_app.main_view.get_toolbar()
1164 cameraButton = toolbar.select_single(
1165 "ActionItem",
1166 objectName="cameraButton"
1167
1168=== modified file 'tests/autopilot/gallery_app/tests/test_events_view.py'
1169--- tests/autopilot/gallery_app/tests/test_events_view.py 2014-06-16 13:46:21 +0000
1170+++ tests/autopilot/gallery_app/tests/test_events_view.py 2014-07-02 14:17:44 +0000
1171@@ -13,7 +13,6 @@
1172 from autopilot.platform import model
1173
1174 from gallery_app.tests import GalleryTestCase
1175-from gallery_app.emulators.events_view import EventsView
1176
1177 from os import environ as env
1178 from os.path import exists
1179@@ -24,12 +23,8 @@
1180 """Tests the main gallery features"""
1181 envDesktopMode = None
1182
1183- @property
1184- def events_view(self):
1185- return EventsView(self.app)
1186-
1187 def setUp(self):
1188- self.ARGS = []
1189+ self.args = []
1190
1191 self.envDesktopMode = env.get("DESKTOP_MODE")
1192
1193@@ -41,9 +36,9 @@
1194 # This is needed to wait for the application to start.
1195 # In the testfarm, the application may take some time to show up.
1196 super(TestEventsView, self).setUp()
1197- self.main_view.switch_to_tab("eventsTab")
1198+ self.gallery_app.main_view.switch_to_tab("eventsTab")
1199 """Wait for the data to be loaded and displayed"""
1200- self.assertThat(lambda: self.events_view.number_of_events(),
1201+ self.assertThat(lambda: self.gallery_app.events_view.number_of_events(),
1202 Eventually(GreaterThan(0)))
1203
1204 def tearDown(self):
1205@@ -54,77 +49,70 @@
1206
1207 super(TestEventsView, self).tearDown()
1208
1209- def get_events_view(self):
1210- return self.app.wait_select_single("EventsOverview",
1211- objectName="organicEventView")
1212-
1213- def enable_select_mode(self):
1214- self.main_view.open_toolbar().click_button("selectButton")
1215-
1216 def test_select_button_cancel(self):
1217 """Clicking the cancel button after clicking the select button must
1218 hide the toolbar automatically."""
1219- events_view = self.get_events_view()
1220+ events_view = self.gallery_app.get_events_view()
1221 self.assertFalse(events_view.inSelectionMode)
1222
1223- self.enable_select_mode()
1224+ self.gallery_app.enable_select_mode()
1225 self.assertTrue(events_view.inSelectionMode)
1226
1227- self.main_view.get_toolbar().click_custom_button("cancelButton")
1228+ self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
1229
1230- toolbar = self.main_view.get_toolbar()
1231+ toolbar = self.gallery_app.main_view.get_toolbar()
1232 self.assertThat(toolbar.opened, Eventually(Equals(False)))
1233 self.assertFalse(events_view.inSelectionMode)
1234
1235 def test_delete_a_photo(self):
1236 """Selecting a photo must make the delete button clickable."""
1237- self.assertThat(lambda: exists(self.sample_file),
1238- Eventually(Equals(True)))
1239-
1240- self.enable_select_mode()
1241- self.events_view.click_photo(self.sample_file)
1242- self.main_view.open_toolbar().click_button("deleteButton")
1243- self.assertThat(self.gallery_utils.delete_dialog_shown,
1244- Eventually(Is(True)))
1245-
1246- self.gallery_utils.click_delete_dialog_cancel_button()
1247- self.assertThat(self.gallery_utils.delete_dialog_shown,
1248- Eventually(Is(False)))
1249-
1250- self.assertThat(lambda: exists(self.sample_file),
1251- Eventually(Equals(True)))
1252-
1253- self.main_view.open_toolbar().click_button("deleteButton")
1254- self.assertThat(self.gallery_utils.delete_dialog_shown,
1255- Eventually(Is(True)))
1256-
1257- self.gallery_utils.click_delete_dialog_delete_button()
1258- self.assertThat(self.gallery_utils.delete_dialog_shown,
1259- Eventually(Is(False)))
1260-
1261- self.assertThat(lambda: exists(self.sample_file),
1262+ self.assertThat(lambda: exists(self.gallery_app.sample_file),
1263+ Eventually(Equals(True)))
1264+
1265+ self.gallery_app.enable_select_mode()
1266+ self.gallery_app.events_view.click_photo(self.gallery_app.sample_file)
1267+ self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
1268+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1269+ Eventually(Is(True)))
1270+
1271+ self.gallery_app.gallery_utils.click_delete_dialog_cancel_button()
1272+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1273+ Eventually(Is(False)))
1274+
1275+ self.assertThat(lambda: exists(self.gallery_app.sample_file),
1276+ Eventually(Equals(True)))
1277+
1278+ self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
1279+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1280+ Eventually(Is(True)))
1281+
1282+ self.gallery_app.gallery_utils.click_delete_dialog_delete_button()
1283+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1284+ Eventually(Is(False)))
1285+
1286+ self.assertThat(lambda: exists(self.gallery_app.sample_file),
1287 Eventually(Equals(False)))
1288
1289 def test_adding_a_video(self):
1290 if model() == "Desktop":
1291- before = self.events_view.get_event(0)
1292+ before = self.gallery_app.events_view.get_event(0)
1293 video_file = "video.mp4"
1294- shutil.copyfile(self.sample_dir+"/option01/"+video_file,
1295- self.sample_destination_dir+"/"+video_file)
1296+ shutil.copyfile(self.gallery_app.sample_dir+"/option01/"+video_file,
1297+ self.gallery_app.sample_destination_dir+"/"+video_file)
1298 video_file = "video.mkv"
1299- shutil.copyfile(self.sample_dir+"/option01/"+video_file,
1300- self.sample_destination_dir+"/"+video_file)
1301- after = self.events_view.get_event(0)
1302+ shutil.copyfile(self.gallery_app.sample_dir+"/option01/"+video_file,
1303+ self.gallery_app.sample_destination_dir+"/"+video_file)
1304+ after = self.gallery_app.events_view.get_event(0)
1305 self.assertThat(lambda: str(after),
1306 Eventually(NotEquals(str(before))))
1307 self.assertThat(
1308- lambda: self.events_view.number_of_photos_in_events(),
1309+ lambda: self.gallery_app.events_view.number_of_photos_in_events(),
1310 Eventually(Equals(4)))
1311
1312 # Check if Camera Button is not visible at Desktop mode
1313 def test_camera_button_visible(self):
1314- self.main_view.open_toolbar()
1315- toolbar = self.main_view.get_toolbar()
1316+ self.gallery_app.main_view.open_toolbar()
1317+ toolbar = self.gallery_app.main_view.get_toolbar()
1318 cameraButton = toolbar.select_single(
1319 "ActionItem",
1320 objectName="cameraButton"
1321
1322=== modified file 'tests/autopilot/gallery_app/tests/test_photo_viewer.py'
1323--- tests/autopilot/gallery_app/tests/test_photo_viewer.py 2014-05-20 15:19:35 +0000
1324+++ tests/autopilot/gallery_app/tests/test_photo_viewer.py 2014-07-02 14:17:44 +0000
1325@@ -8,12 +8,9 @@
1326
1327 """Tests the Photo editor of the gallery app."""
1328
1329-from testtools.matchers import Equals, NotEquals, GreaterThan, Is
1330+from testtools.matchers import Equals, NotEquals
1331 from autopilot.matchers import Eventually
1332
1333-from gallery_app.emulators.photo_viewer import PhotoViewer
1334-from gallery_app.emulators.media_viewer import MediaViewer
1335-from gallery_app.emulators.events_view import EventsView
1336 from gallery_app.tests import GalleryTestCase
1337
1338 import os
1339@@ -26,38 +23,11 @@
1340
1341
1342 class TestPhotoViewerBase(GalleryTestCase):
1343- @property
1344- def photo_viewer(self):
1345- return PhotoViewer(self.app)
1346-
1347- @property
1348- def events_view(self):
1349- return EventsView(self.app)
1350-
1351 def setUp(self):
1352- self.ARGS = []
1353 super(TestPhotoViewerBase, self).setUp()
1354- self.main_view.switch_to_tab("eventsTab")
1355- self.open_first_photo()
1356- self.main_view.open_toolbar()
1357-
1358- def open_first_photo(self):
1359- self.assertThat(
1360- lambda: self.events_view.number_of_photos_in_events(),
1361- Eventually(GreaterThan(0))
1362- )
1363-
1364- # workaround lp:1247698
1365- # toolbar needs to be gone to click on an image.
1366- self.main_view.close_toolbar()
1367-
1368- self.events_view.click_photo(self.sample_file)
1369-
1370- photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
1371- self.assertThat(photo_viewer_loader.loaded, Eventually(Equals(True)))
1372- sleep(1)
1373- photo_viewer = self.photo_viewer.get_main_photo_viewer()
1374- self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
1375+ self.gallery_app.main_view.switch_to_tab("eventsTab")
1376+ self.gallery_app.open_first_photo()
1377+ self.gallery_app.main_view.open_toolbar()
1378
1379
1380 class TestPhotoViewer(TestPhotoViewerBase):
1381@@ -67,15 +37,15 @@
1382 def test_save_state(self):
1383 """Quitting the app once a photo has been opened will return
1384 to that same photo on restart"""
1385- path = self.photo_viewer.get_photo_component().select_single(
1386+ path = self.gallery_app.photo_viewer.get_photo_component().select_single(
1387 "QQuickImage").source
1388
1389 self.ensure_app_has_quit()
1390 self.start_app()
1391
1392- photo_viewer = self.photo_viewer.get_main_photo_viewer()
1393+ photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
1394 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
1395- new_path = self.photo_viewer.get_photo_component().select_single(
1396+ new_path = self.gallery_app.photo_viewer.get_photo_component().select_single(
1397 "QQuickImage").source
1398
1399 self.assertThat(path, Equals(new_path))
1400@@ -85,76 +55,59 @@
1401 def test_no_save_state_on_back(self):
1402 """Quitting the app once a photo has been opened and then closed
1403 will not reopen a photo on restart"""
1404- self.main_view.open_toolbar().click_button("backButton")
1405+ self.gallery_app.main_view.open_toolbar().click_button("backButton")
1406
1407 self.ensure_app_has_quit()
1408 self.start_app()
1409
1410- photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
1411+ photo_viewer_loader = self.gallery_app.photo_viewer.get_main_photo_viewer_loader()
1412 self.assertThat(photo_viewer_loader.source, Equals(""))
1413
1414- def get_delete_dialog(self):
1415- delete_dialog = self.photo_viewer.get_delete_dialog()
1416- self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
1417- self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
1418- return delete_dialog
1419-
1420- def ensure_closed_delete_dialog(self):
1421- self.assertThat(self.photo_viewer.delete_dialog_shown,
1422- Eventually(Is(False)))
1423-
1424 def test_nav_bar_back_button(self):
1425 """Clicking the back button must close the photo."""
1426- self.main_view.open_toolbar().click_button("backButton")
1427- photo_viewer = self.photo_viewer.get_main_photo_viewer()
1428+ self.gallery_app.main_view.open_toolbar().click_button("backButton")
1429+ photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
1430 self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
1431
1432- def delete_one_picture(self):
1433- self.main_view.open_toolbar().click_button("deleteButton")
1434- self.get_delete_dialog()
1435- delete_item = self.photo_viewer.get_delete_popover_delete_item()
1436- self.click_item(delete_item)
1437- self.ensure_closed_delete_dialog()
1438-
1439 def test_photo_delete_works(self):
1440 """Clicking the trash button must show the delete dialog."""
1441- self.main_view.open_toolbar().click_button("deleteButton")
1442- self.get_delete_dialog()
1443-
1444- photo_viewer = self.photo_viewer.get_main_photo_viewer()
1445-
1446- cancel_item = self.photo_viewer.get_delete_popover_cancel_item()
1447- self.click_item(cancel_item)
1448- self.ensure_closed_delete_dialog()
1449-
1450- self.assertThat(lambda: os.path.exists(self.sample_file),
1451+ self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
1452+ self.gallery_app.get_delete_dialog()
1453+
1454+ photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
1455+
1456+ cancel_item = self.gallery_app.photo_viewer.get_delete_popover_cancel_item()
1457+ self.gallery_app.click_item(cancel_item)
1458+ self.gallery_app.ensure_closed_delete_dialog()
1459+
1460+ self.assertThat(lambda: os.path.exists(self.gallery_app.sample_file),
1461 Eventually(Equals(True)))
1462
1463- self.delete_one_picture()
1464- self.assertThat(lambda: os.path.exists(self.sample_file),
1465+ self.gallery_app.delete_one_picture()
1466+ self.assertThat(lambda: os.path.exists(self.gallery_app.sample_file),
1467 Eventually(Equals(False)))
1468
1469 # Delete all other pictures and make sure the photo viewer closes
1470- self.delete_one_picture()
1471- self.delete_one_picture()
1472- self.delete_one_picture()
1473- self.delete_one_picture()
1474+ self.gallery_app.delete_one_picture()
1475+ self.gallery_app.delete_one_picture()
1476+ self.gallery_app.delete_one_picture()
1477+ self.gallery_app.delete_one_picture()
1478
1479 self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
1480
1481 def test_nav_bar_album_picker_button(self):
1482 """Clicking the album picker must show the picker dialog."""
1483- self.main_view.open_toolbar().click_button("addButton")
1484- album_picker = self.photo_viewer.get_popup_album_picker()
1485+ self.gallery_app.main_view.open_toolbar().click_button("addButton")
1486+ album_picker = self.gallery_app.photo_viewer.get_popup_album_picker()
1487 self.assertThat(album_picker.visible, Eventually(Equals(True)))
1488
1489 def test_double_click_zoom(self):
1490 """Double clicking an opened photo must zoom it."""
1491- opened_photo = self.photo_viewer.get_photo_component()
1492+ opened_photo = self.gallery_app.photo_viewer.get_photo_component()
1493
1494- self.pointing_device.move_to_object(opened_photo)
1495- self.pointing_device.click()
1496- self.pointing_device.click()
1497+ self.gallery_app.pointing_device.move_to_object(opened_photo)
1498+ self.gallery_app.pointing_device.click()
1499+ self.gallery_app.pointing_device.click()
1500
1501 self.assertThat(
1502 opened_photo.isZoomAnimationInProgress,
1503@@ -162,8 +115,8 @@
1504 )
1505 self.assertThat(opened_photo.fullyZoomed, Eventually(Equals(True)))
1506
1507- self.pointing_device.click()
1508- self.pointing_device.click()
1509+ self.gallery_app.pointing_device.click()
1510+ self.gallery_app.pointing_device.click()
1511
1512 self.assertThat(
1513 opened_photo.isZoomAnimationInProgress,
1514@@ -173,26 +126,26 @@
1515
1516 def test_swipe_change_image(self):
1517 """Swiping left and right on a photo should move to another photo"""
1518- list = self.photo_viewer.get_photos_list()
1519+ list = self.gallery_app.photo_viewer.get_photos_list()
1520 self.assertThat(list.currentIndex, Eventually(Equals(0)))
1521
1522 # Slide left should move to the next image
1523 x, y, w, h = list.globalRect
1524 mid_y = y + h // 2
1525 mid_x = x + w // 2
1526- self.pointing_device.drag(mid_x, mid_y, x + 10, mid_y)
1527+ self.gallery_app.pointing_device.drag(mid_x, mid_y, x + 10, mid_y)
1528
1529 self.assertThat(list.moving, Eventually(Equals(False)))
1530 self.assertThat(list.currentIndex, Eventually(Equals(1)))
1531
1532 # Slide right should get us back to the start
1533- self.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
1534+ self.gallery_app.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
1535
1536 self.assertThat(list.moving, Eventually(Equals(False)))
1537 self.assertThat(list.currentIndex, Eventually(Equals(0)))
1538
1539 # Slide right again shouldn't go anywhere
1540- self.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
1541+ self.gallery_app.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
1542
1543 self.assertThat(list.moving, Eventually(Equals(False)))
1544 self.assertThat(list.currentIndex, Eventually(Equals(0)))
1545@@ -202,98 +155,91 @@
1546
1547 def setUp(self):
1548 super(TestPhotoEditor, self).setUp()
1549- self.click_edit_button()
1550- self.media_view = self.app.select_single(MediaViewer)
1551-
1552- def click_edit_button(self):
1553- self.main_view.open_toolbar().click_button("editButton")
1554- edit_dialog = self.photo_viewer.get_photo_edit_dialog()
1555- self.assertThat(edit_dialog.visible, (Eventually(Equals(True))))
1556- self.assertThat(edit_dialog.opacity, (Eventually(Equals(1))))
1557+ self.gallery_app.click_edit_button()
1558
1559 def test_photo_editor_crop(self):
1560 """Cropping a photo must crop it."""
1561- old_file_size = os.path.getsize(self.sample_file)
1562+ old_file_size = os.path.getsize(self.gallery_app.sample_file)
1563
1564- crop_box = self.photo_viewer.get_crop_interactor()
1565+ crop_box = self.gallery_app.photo_viewer.get_crop_interactor()
1566 item_width = crop_box.width
1567 item_height = crop_box.height
1568
1569- self.photo_viewer.click_crop_item()
1570+ self.gallery_app.photo_viewer.click_crop_item()
1571
1572 self.assertThat(crop_box.state, Eventually(Equals("shown")))
1573 self.assertThat(crop_box.opacity, Eventually(Equals(1)))
1574
1575- crop_corner = self.photo_viewer.get_top_left_crop_corner()
1576+ crop_corner = self.gallery_app.photo_viewer.get_top_left_crop_corner()
1577 x, y, h, w = crop_corner.globalRect
1578 x = x + w // 2
1579 y = y + h // 2
1580- self.pointing_device.drag(x, y,
1581+ self.gallery_app.pointing_device.drag(x, y,
1582 x + item_width // 2, y + item_height // 2)
1583
1584 # wait for animation being finished
1585- crop_overlay = self.photo_viewer.get_crop_overlay()
1586+ crop_overlay = self.gallery_app.photo_viewer.get_crop_overlay()
1587 self.assertThat(crop_overlay.interpolationFactor,
1588 Eventually(Equals(1.0)))
1589
1590- crop_button = self.photo_viewer.get_crop_overlays_crop_icon()
1591- self.click_item(crop_button)
1592- self.media_view.ensure_spinner_not_running()
1593+ crop_button = self.gallery_app.photo_viewer.get_crop_overlays_crop_icon()
1594+ self.gallery_app.click_item(crop_button)
1595+ self.gallery_app.media_view.ensure_spinner_not_running()
1596
1597 # wait for new photo being set/reloaded, so saving thumbnailing etc.
1598 # is done
1599- edit_preview = self.photo_viewer.get_edit_preview()
1600- new_source = "image://thumbnailer/" + self.sample_file
1601+ edit_preview = self.gallery_app.photo_viewer.get_edit_preview()
1602+ new_source = "image://thumbnailer/" + self.gallery_app.sample_file
1603
1604 self.assertThat(edit_preview.source, Eventually(Equals(new_source)))
1605
1606- new_file_size = os.path.getsize(self.sample_file)
1607+ new_file_size = os.path.getsize(self.gallery_app.sample_file)
1608 self.assertThat(old_file_size > new_file_size, Equals(True))
1609
1610 def test_photo_editor_rotate(self):
1611 """Makes sure that the photo editor inside the photo viewer works using
1612 the rotate function"""
1613- opened_photo = self.photo_viewer.get_opened_photo()
1614+ opened_photo = self.gallery_app.photo_viewer.get_opened_photo()
1615 item_height = opened_photo.height
1616
1617 def is_landscape():
1618 return opened_photo.paintedWidth > opened_photo.paintedHeight
1619 self.assertThat(is_landscape(), Equals(True))
1620
1621- self.photo_viewer.click_rotate_item()
1622- self.media_view.ensure_spinner_not_running()
1623+ self.gallery_app.photo_viewer.click_rotate_item()
1624+ self.gallery_app.media_view.ensure_spinner_not_running()
1625
1626 self.assertThat(opened_photo.paintedHeight,
1627 Eventually(Equals(item_height)))
1628 self.assertThat(lambda: is_landscape(),
1629 Eventually(Equals(False)))
1630
1631- self.main_view.open_toolbar()
1632- self.click_edit_button()
1633- self.photo_viewer.click_undo_item()
1634- self.media_view.ensure_spinner_not_running()
1635+ self.gallery_app.main_view.open_toolbar()
1636+ self.gallery_app.click_edit_button()
1637+ self.gallery_app.photo_viewer.click_undo_item()
1638+ self.gallery_app.media_view.ensure_spinner_not_running()
1639
1640 self.assertThat(opened_photo.paintedHeight,
1641 Eventually(NotEquals(item_height)))
1642 self.assertThat(lambda: is_landscape(),
1643 Eventually(Equals(True)))
1644
1645- self.main_view.open_toolbar()
1646- self.click_edit_button()
1647- self.photo_viewer.click_redo_item()
1648- self.media_view.ensure_spinner_not_running()
1649+ self.gallery_app.main_view.open_toolbar()
1650+ self.gallery_app.click_edit_button()
1651+ self.gallery_app.photo_viewer.click_redo_item()
1652+ self.gallery_app.media_view.ensure_spinner_not_running()
1653
1654 self.assertThat(opened_photo.paintedHeight,
1655 Eventually(Equals(item_height)))
1656 is_landscape = opened_photo.paintedWidth > opened_photo.paintedHeight
1657 self.assertThat(is_landscape, Equals(False))
1658
1659- self.main_view.open_toolbar()
1660- self.click_edit_button()
1661- self.photo_viewer.click_rotate_item()
1662- self.main_view.open_toolbar()
1663- self.click_edit_button()
1664- self.photo_viewer.click_revert_item()
1665+ self.gallery_app.main_view.open_toolbar()
1666+ self.gallery_app.click_edit_button()
1667+ self.gallery_app.photo_viewer.click_rotate_item()
1668+ self.gallery_app.main_view.open_toolbar()
1669+ self.gallery_app.click_edit_button()
1670+ self.gallery_app.photo_viewer.click_revert_item()
1671
1672 self.assertThat(opened_photo.paintedHeight,
1673 Eventually(NotEquals(item_height)))
1674@@ -307,66 +253,66 @@
1675 sleep(1)
1676
1677 def test_photo_editor_redo_undo_revert_enhance_states(self):
1678- undo_item = self.photo_viewer.get_undo_menu_item()
1679- redo_item = self.photo_viewer.get_redo_menu_item()
1680- revert_item = self.photo_viewer.get_revert_menu_item()
1681+ undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
1682+ redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
1683+ revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
1684
1685 self.assertThat(undo_item.enabled, Eventually(Equals(False)))
1686 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
1687 self.assertThat(revert_item.enabled, Eventually(Equals(False)))
1688
1689- self.photo_viewer.click_rotate_item()
1690- self.media_view.ensure_spinner_not_running()
1691+ self.gallery_app.photo_viewer.click_rotate_item()
1692+ self.gallery_app.media_view.ensure_spinner_not_running()
1693
1694- self.click_edit_button()
1695- undo_item = self.photo_viewer.get_undo_menu_item()
1696- redo_item = self.photo_viewer.get_redo_menu_item()
1697- revert_item = self.photo_viewer.get_revert_menu_item()
1698+ self.gallery_app.click_edit_button()
1699+ undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
1700+ redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
1701+ revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
1702
1703 self.assertThat(undo_item.enabled, Eventually(Equals(True)))
1704 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
1705 self.assertThat(revert_item.enabled, Eventually(Equals(True)))
1706
1707- self.photo_viewer.click_undo_item()
1708- self.media_view.ensure_spinner_not_running()
1709+ self.gallery_app.photo_viewer.click_undo_item()
1710+ self.gallery_app.media_view.ensure_spinner_not_running()
1711
1712- self.click_edit_button()
1713- undo_item = self.photo_viewer.get_undo_menu_item()
1714- redo_item = self.photo_viewer.get_redo_menu_item()
1715- revert_item = self.photo_viewer.get_revert_menu_item()
1716+ self.gallery_app.click_edit_button()
1717+ undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
1718+ redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
1719+ revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
1720
1721 self.assertThat(undo_item.enabled, Eventually(Equals(False)))
1722 self.assertThat(redo_item.enabled, Eventually(Equals(True)))
1723 self.assertThat(revert_item.enabled, Eventually(Equals(False)))
1724
1725- self.photo_viewer.click_redo_item()
1726- self.media_view.ensure_spinner_not_running()
1727+ self.gallery_app.photo_viewer.click_redo_item()
1728+ self.gallery_app.media_view.ensure_spinner_not_running()
1729
1730- self.click_edit_button()
1731- undo_item = self.photo_viewer.get_undo_menu_item()
1732- redo_item = self.photo_viewer.get_redo_menu_item()
1733- revert_item = self.photo_viewer.get_revert_menu_item()
1734+ self.gallery_app.click_edit_button()
1735+ undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
1736+ redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
1737+ revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
1738
1739 self.assertThat(undo_item.enabled, Eventually(Equals(True)))
1740 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
1741 self.assertThat(revert_item.enabled, Eventually(Equals(True)))
1742
1743- self.photo_viewer.click_revert_item()
1744- self.media_view.ensure_spinner_not_running()
1745+ self.gallery_app.photo_viewer.click_revert_item()
1746+ self.gallery_app.media_view.ensure_spinner_not_running()
1747
1748- self.click_edit_button()
1749- undo_item = self.photo_viewer.get_undo_menu_item()
1750- redo_item = self.photo_viewer.get_redo_menu_item()
1751- revert_item = self.photo_viewer.get_revert_menu_item()
1752+ self.gallery_app.click_edit_button()
1753+ undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
1754+ redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
1755+ revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
1756
1757 self.assertThat(undo_item.enabled, Eventually(Equals(True)))
1758 self.assertThat(redo_item.enabled, Eventually(Equals(False)))
1759 self.assertThat(revert_item.enabled, Eventually(Equals(False)))
1760
1761- self.photo_viewer.click_enhance_item()
1762- self.media_view.ensure_spinner_not_running()
1763-
1764- self.click_edit_button()
1765-
1766- revert_item = self.photo_viewer.get_revert_menu_item()
1767+ self.gallery_app.photo_viewer.click_enhance_item()
1768+ self.gallery_app.media_view.ensure_spinner_not_running()
1769+
1770+ self.gallery_app.click_edit_button()
1771+
1772+ revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
1773 self.assertThat(lambda: revert_item.enabled, Eventually(Equals(True)))
1774
1775=== modified file 'tests/autopilot/gallery_app/tests/test_photos_view.py'
1776--- tests/autopilot/gallery_app/tests/test_photos_view.py 2014-05-20 20:59:52 +0000
1777+++ tests/autopilot/gallery_app/tests/test_photos_view.py 2014-07-02 14:17:44 +0000
1778@@ -14,7 +14,6 @@
1779 from autopilot.platform import model
1780
1781 from gallery_app.tests import GalleryTestCase
1782-from gallery_app.emulators.photos_view import PhotosView
1783
1784 from time import sleep
1785 from os import environ as env
1786@@ -24,12 +23,8 @@
1787 class TestPhotosView(GalleryTestCase):
1788 envDesktopMode = None
1789
1790- @property
1791- def photos_view(self):
1792- return PhotosView(self.app)
1793-
1794 def setUp(self):
1795- self.ARGS = []
1796+ self.args = []
1797 self.envDesktopMode = env.get("DESKTOP_MODE")
1798
1799 if model() == "Desktop":
1800@@ -38,7 +33,7 @@
1801 env["DESKTOP_MODE"] = "0"
1802
1803 super(TestPhotosView, self).setUp()
1804- self.switch_to_photos_tab()
1805+ self.gallery_app.switch_to_photos_tab()
1806
1807 def tearDown(self):
1808 if self.envDesktopMode:
1809@@ -48,82 +43,74 @@
1810
1811 super(TestPhotosView, self).tearDown()
1812
1813- def switch_to_photos_tab(self):
1814- self.main_view.switch_to_tab("photosTab")
1815- self.ensure_tabs_dont_move()
1816-
1817- def click_first_photo(self):
1818- photo = self.photos_view.get_first_photo_in_photos_view()
1819- self.click_item(photo)
1820-
1821 def test_open_photo(self):
1822- self.main_view.close_toolbar()
1823- self.click_first_photo()
1824+ self.gallery_app.main_view.close_toolbar()
1825+ self.gallery_app.click_first_photo()
1826 sleep(5)
1827- photo_viewer = self.photos_view.get_main_photo_viewer()
1828+ photo_viewer = self.gallery_app.photos_view.get_main_photo_viewer()
1829 self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
1830
1831 def test_select_button_cancel(self):
1832 """Clicking the cancel button after clicking the select button must
1833 hide the toolbar automatically."""
1834- photos_overview = self.app.select_single("PhotosOverview")
1835+ photos_overview = self.gallery_app.app.select_single("PhotosOverview")
1836 self.assertFalse(photos_overview.inSelectionMode)
1837
1838- self.main_view.open_toolbar().click_button("selectButton")
1839+ self.gallery_app.main_view.open_toolbar().click_button("selectButton")
1840 self.assertTrue(photos_overview.inSelectionMode)
1841
1842- self.main_view.open_toolbar().click_custom_button("cancelButton")
1843+ self.gallery_app.main_view.open_toolbar().click_custom_button("cancelButton")
1844
1845- toolbar = self.main_view.get_toolbar()
1846+ toolbar = self.gallery_app.main_view.get_toolbar()
1847 self.assertThat(toolbar.opened, Eventually(Equals(False)))
1848 self.assertFalse(photos_overview.inSelectionMode)
1849
1850- first_photo = self.photos_view.get_first_photo_in_photos_view()
1851- self.tap_item(first_photo)
1852+ first_photo = self.gallery_app.photos_view.get_first_photo_in_photos_view()
1853+ self.gallery_app.tap_item(first_photo)
1854 self.assertTrue(photos_overview.inSelectionMode)
1855
1856 def test_delete_photo_dialog_appears(self):
1857 """Selecting a photo must make the delete button clickable."""
1858- self.main_view.open_toolbar().click_button("selectButton")
1859- self.click_first_photo()
1860- self.main_view.open_toolbar().click_button("deleteButton")
1861+ self.gallery_app.main_view.open_toolbar().click_button("selectButton")
1862+ self.gallery_app.click_first_photo()
1863+ self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
1864
1865- self.assertThat(self.gallery_utils.delete_dialog_shown,
1866+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1867 Eventually(Is(True)))
1868
1869- cancel_item = self.photos_view.get_delete_dialog_cancel_button()
1870- self.click_item(cancel_item)
1871- self.assertThat(self.gallery_utils.delete_dialog_shown,
1872+ cancel_item = self.gallery_app.photos_view.get_delete_dialog_cancel_button()
1873+ self.gallery_app.click_item(cancel_item)
1874+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1875 Eventually(Is(False)))
1876
1877 def test_delete_a_photo(self):
1878 """Must be able to select a photo and use the dialog to delete it."""
1879- number_of_photos = self.photos_view.number_of_photos()
1880- self.main_view.open_toolbar().click_button("selectButton")
1881- self.click_first_photo()
1882- self.main_view.open_toolbar().click_button("deleteButton")
1883+ number_of_photos = self.gallery_app.photos_view.number_of_photos()
1884+ self.gallery_app.main_view.open_toolbar().click_button("selectButton")
1885+ self.gallery_app.click_first_photo()
1886+ self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
1887
1888- self.assertThat(self.gallery_utils.delete_dialog_shown,
1889+ self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
1890 Eventually(Is(True)))
1891
1892- self.main_view.open_toolbar().click_button("deleteButton")
1893+ self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
1894
1895- delete_item = self.photos_view.get_delete_dialog_delete_button()
1896- self.click_item(delete_item)
1897+ delete_item = self.gallery_app.photos_view.get_delete_dialog_delete_button()
1898+ self.gallery_app.click_item(delete_item)
1899 self.assertThat(
1900- self.gallery_utils.delete_dialog_shown,
1901+ self.gallery_app.gallery_utils.delete_dialog_shown,
1902 Eventually(Is(False))
1903 )
1904
1905- self.assertThat(lambda: self.photos_view.number_of_photos(),
1906+ self.assertThat(lambda: self.gallery_app.photos_view.number_of_photos(),
1907 Eventually(Equals(number_of_photos - 1)))
1908
1909 @unittest.skip("Temporarily disable as it fails in some cases, "
1910 "supposedly due to problems with the infrastructure")
1911 def test_save_state(self):
1912- self.switch_to_photos_tab()
1913+ self.gallery_app.switch_to_photos_tab()
1914
1915- tabs = self.main_view.select_single("Tabs")
1916+ tabs = self.gallery_app.main_view.select_single("Tabs")
1917 tab = tabs.get_current_tab()
1918 self.assertThat(tab.objectName, Equals("photosTab"))
1919 index = tab.index
1920@@ -131,7 +118,7 @@
1921 self.ensure_app_has_quit()
1922 self.start_app()
1923
1924- tabs = self.main_view.select_single("Tabs")
1925+ tabs = self.gallery_app.main_view.select_single("Tabs")
1926 tab = tabs.get_current_tab()
1927 self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))
1928 self.assertThat(tab.objectName, Equals("photosTab"))
1929@@ -141,8 +128,8 @@
1930 'Key based tests only make sense on Desktop'
1931 )
1932 def test_toggle_fullscreen(self):
1933- self.switch_to_photos_tab()
1934- view = self.main_view
1935+ self.gallery_app.switch_to_photos_tab()
1936+ view = self.gallery_app.main_view
1937 self.assertThat(view.fullScreen, Eventually(Equals(False)))
1938 self.keyboard.press_and_release('F11')
1939 self.assertThat(view.fullScreen, Eventually(Equals(True)))
1940@@ -157,8 +144,8 @@
1941
1942 # Check if Camera Button is not visible at Desktop mode
1943 def test_camera_button_visible(self):
1944- self.main_view.open_toolbar()
1945- toolbar = self.main_view.get_toolbar()
1946+ self.gallery_app.main_view.open_toolbar()
1947+ toolbar = self.gallery_app.main_view.get_toolbar()
1948 cameraButton = toolbar.select_single(
1949 "ActionItem",
1950 objectName="cameraButton"
1951
1952=== modified file 'tests/autopilot/gallery_app/tests/test_picker_mode.py'
1953--- tests/autopilot/gallery_app/tests/test_picker_mode.py 2014-05-21 16:02:19 +0000
1954+++ tests/autopilot/gallery_app/tests/test_picker_mode.py 2014-07-02 14:17:44 +0000
1955@@ -11,54 +11,43 @@
1956 from testtools.matchers import Equals
1957 from autopilot.matchers import Eventually
1958
1959-from gallery_app.emulators.picker_screen import PickerScreen
1960+from gallery_app import GalleryApp
1961 from gallery_app.tests import GalleryTestCase
1962+
1963 import unittest
1964
1965 from unittest import skip
1966
1967 class TestPickerMode(GalleryTestCase):
1968
1969- @property
1970- def picker_view(self):
1971- return self.app.select_single(PickerScreen)
1972-
1973 def setUp(self):
1974- self.ARGS.append("--pick-mode")
1975+ self.args.append("--pick-mode")
1976 super(TestPickerMode, self).setUp()
1977
1978- def select_first_event_media(self):
1979- first_media = self.picker_view.first_media_in_events_view()
1980- self.click_item(first_media)
1981-
1982- def select_first_grid_media(self):
1983- first_media = self.picker_view.first_media_in_events_view()
1984- self.click_item(first_media)
1985-
1986 @unittest.skip("Temporarily disable as it fails in some cases, "
1987 "supposedly due to problems with the infrastructure")
1988 def test_pick_first_photo(self):
1989 """Check if the button enabled state follows the selection"""
1990- pick_button = self.picker_view.pick_button()
1991+ pick_button = self.gallery_app.picker_view.pick_button()
1992 self.assertThat(pick_button.enabled, Eventually(Equals(False)))
1993- first_events_media = self.picker_view.first_media_in_events_view()
1994+ first_events_media = self.gallery_app.picker_view.first_media_in_events_view()
1995 self.assertThat(
1996 first_events_media.isSelected,
1997 Eventually(Equals(False))
1998 )
1999
2000- self.select_first_event_media()
2001+ self.gallery_app.select_first_event_media()
2002
2003- pick_button = self.picker_view.pick_button()
2004+ pick_button = self.gallery_app.picker_view.pick_button()
2005 self.assertThat(pick_button.enabled, Eventually(Equals(True)))
2006 self.assertThat(
2007 first_events_media.isSelected,
2008 Eventually(Equals(True))
2009 )
2010
2011- self.select_first_event_media()
2012+ self.gallery_app.select_first_event_media()
2013
2014- pick_button = self.picker_view.pick_button()
2015+ pick_button = self.gallery_app.picker_view.pick_button()
2016 self.assertThat(pick_button.enabled, Eventually(Equals(False)))
2017 self.assertThat(
2018 first_events_media.isSelected,
2019@@ -68,14 +57,14 @@
2020 @skip("Temporarily disable as it fails in some cases")
2021 def test_pick_named_photo(self):
2022 """Select a named photo and press Pick button."""
2023- self.picker_view.switch_to_tab('photosTab')
2024- pick_button = self.picker_view.pick_button()
2025+ self.gallery_app.picker_view.switch_to_tab('photosTab')
2026+ pick_button = self.gallery_app.picker_view.pick_button()
2027 self.assertFalse(pick_button.enabled)
2028
2029 # create the image location path based on sample location
2030 image_path = 'image://thumbnailer/{}/sample02.jpg'.format(
2031 self.sample_destination_dir)
2032- self.picker_view.select_named_photo(image_path)
2033+ self.gallery_app.picker_view.select_named_photo(image_path)
2034
2035 self.assertTrue(pick_button.enabled)
2036 self.click_item(pick_button)
2037@@ -84,38 +73,38 @@
2038 "supposedly due to problems with the infrastructure")
2039 def test_selection_synchronisation(self):
2040 """Checks if the selection is the same for both views"""
2041- first_events_media = self.picker_view.first_media_in_events_view()
2042+ first_events_media = self.gallery_app.picker_view.first_media_in_events_view()
2043 self.assertThat(
2044 first_events_media.isSelected,
2045 Eventually(Equals(False))
2046 )
2047
2048- self.select_first_event_media()
2049+ self.gallery_app.select_first_event_media()
2050 self.assertThat(
2051 first_events_media.isSelected,
2052 Eventually(Equals(True))
2053 )
2054
2055- self.picker_view.switch_to_next_tab()
2056+ self.gallery_app.picker_view.switch_to_next_tab()
2057
2058- first_grid_media = self.picker_view.first_media_in_grid_view()
2059+ first_grid_media = self.gallery_app.picker_view.first_media_in_grid_view()
2060 self.assertThat(first_grid_media.isSelected, Eventually(Equals(True)))
2061
2062 @unittest.skip("Temporarily disable as it fails in some cases, "
2063 "supposedly due to problems with the infrastructure")
2064 def test_save_picker_state(self):
2065- self.picker_view.switch_to_tab("photosTab")
2066- self.ensure_tabs_dont_move()
2067+ self.gallery_app.picker_view.switch_to_tab("photosTab")
2068+ self.gallery_app.ensure_tabs_dont_move()
2069
2070- tabs = self.picker_view.select_single("Tabs")
2071+ tabs = self.gallery_app.picker_view.select_single("Tabs")
2072 tab = tabs.get_current_tab()
2073 self.assertThat(tab.objectName, Equals("photosTab"))
2074 index = tab.index
2075
2076- self.ensure_app_has_quit()
2077+ self.gallery_app.ensure_app_has_quit()
2078 self.start_app()
2079
2080- tabs = self.picker_view.select_single("Tabs")
2081+ tabs = self.gallery_app.picker_view.select_single("Tabs")
2082 tab = tabs.get_current_tab()
2083 self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))
2084 self.assertThat(tab.objectName, Equals("photosTab"))

Subscribers

People subscribed via source and target branches