~timo-jyrinki/gallery-app/allow_translating_date_strings

« back to all changes in this revision

Viewing changes to tests/autopilot/gallery_app/tests/test_photo_viewer.py

Fix AP tests
Approved by: Federico Gimenez

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
"""Tests the Photo editor of the gallery app."""
10
10
 
11
 
from testtools.matchers import Equals, NotEquals, GreaterThan, Is
 
11
from testtools.matchers import Equals, NotEquals, GreaterThan
12
12
from autopilot.matchers import Eventually
13
13
from testtools import skipIf
14
14
from autopilot.platform import model
15
15
 
16
 
from gallery_app.emulators.photo_viewer import PhotoViewer
 
16
from gallery_app.emulators import photo_viewer
17
17
from gallery_app.emulators.media_viewer import MediaViewer
18
18
from gallery_app.emulators.events_view import EventsView
19
19
from gallery_app.tests import GalleryTestCase
31
31
class TestMediaViewerBase(GalleryTestCase):
32
32
    @property
33
33
    def photo_viewer(self):
34
 
        return PhotoViewer(self.app)
 
34
        return photo_viewer.PhotoViewer(self.app)
35
35
 
36
36
    @property
37
37
    def events_view(self):
93
93
        photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
94
94
        self.assertThat(photo_viewer_loader.source, Equals(""))
95
95
 
96
 
    def get_delete_dialog(self):
97
 
        delete_dialog = self.photo_viewer.get_delete_dialog()
98
 
        self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
99
 
        self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
100
 
        return delete_dialog
101
 
 
102
 
    def ensure_closed_delete_dialog(self):
103
 
        self.assertThat(self.photo_viewer.delete_dialog_shown,
104
 
                        Eventually(Is(False)))
105
 
 
106
96
    def test_nav_bar_back_button(self):
107
97
        """Clicking the back button must close the photo."""
108
98
        self.main_view.get_header().click_custom_back_button()
120
110
        self.click_item(cancel_button)
121
111
        self.assertThat(share_picker.visible, Eventually(Equals(False)))
122
112
 
123
 
    def delete_one_picture(self):
124
 
        self.main_view.get_header().click_action_button("deleteButton")
125
 
        self.get_delete_dialog()
126
 
        delete_item = self.photo_viewer.get_delete_popover_delete_item()
127
 
        self.click_item(delete_item)
128
 
        self.ensure_closed_delete_dialog()
 
113
    def test_delete_photo_must_remove_it_from_filesystem(self):
 
114
        photo_component = self.main_view.select_single('GalleryPhotoComponent')
 
115
        source = photo_component.source
 
116
        file_path = source[len('image://thumbnailer/file://'):]
 
117
        self.assertTrue(os.path.exists(file_path))
 
118
 
 
119
        photo_viewer_popup = self.main_view.select_single(
 
120
            photo_viewer.PopupPhotoViewer)
 
121
        photo_viewer_popup.delete_current_photo()
 
122
 
 
123
        self.assertFalse(os.path.exists(file_path))
129
124
 
130
125
    def test_photo_delete_works(self):
131
126
        """Clicking the trash button must show the delete dialog."""
132
 
        self.main_view.get_header().click_action_button("deleteButton")
133
 
        self.get_delete_dialog()
134
 
 
135
 
        photo_viewer = self.photo_viewer.get_main_photo_viewer()
136
 
 
137
 
        cancel_item = self.photo_viewer.get_delete_popover_cancel_item()
138
 
        self.click_item(cancel_item)
139
 
        self.ensure_closed_delete_dialog()
 
127
        # XXX This test must be split into multiple QML tests.
 
128
        # --elopio - 2015-14-16
 
129
        photo_viewer_popup = self.main_view.select_single(
 
130
            photo_viewer.PopupPhotoViewer)
 
131
        photo_viewer_popup.delete_current_photo(confirm=False)
140
132
 
141
133
        self.assertThat(lambda: os.path.exists(self.sample_file),
142
134
                        Eventually(Equals(True)))
143
135
 
144
 
        self.delete_one_picture()
 
136
        photo_viewer_popup.delete_current_photo()
145
137
        self.assertThat(lambda: os.path.exists(self.sample_file),
146
138
                        Eventually(Equals(False)))
147
139
 
148
140
        # Delete all other pictures and make sure the photo viewer closes
149
 
        self.delete_one_picture()
150
 
        self.delete_one_picture()
151
 
        self.delete_one_picture()
152
 
        self.delete_one_picture()
 
141
        photo_viewer_popup.delete_current_photo()
 
142
        photo_viewer_popup.delete_current_photo()
 
143
        photo_viewer_popup.delete_current_photo()
 
144
        photo_viewer_popup.delete_current_photo()
153
145
 
154
 
        self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
 
146
        self.assertThat(photo_viewer_popup.visible, Eventually(Equals(False)))
155
147
 
156
148
    def test_nav_bar_album_picker_button(self):
157
149
        """Clicking the album picker must show the picker dialog."""
208
200
        video_file = "video.mp4"
209
201
        shutil.copyfile(self.sample_dir+"/option01/"+video_file,
210
202
                        self.sample_destination_dir+"/"+video_file)
211
 
 
 
203
 
212
204
        self.assertThat(
213
205
            lambda: self.events_view.number_of_events(),
214
206
            Eventually(Equals(num_events + 1))
221
213
        sleep(1)
222
214
        photo_viewer = self.photo_viewer.get_main_photo_viewer()
223
215
        self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
224
 
        photo_component = self.photo_viewer.get_photo_component() 
 
216
        photo_component = self.photo_viewer.get_photo_component()
225
217
        self.assertThat(photo_component.imageReady, Eventually(Equals(True)))
226
218
 
227
219
        os.remove(self.sample_destination_dir+"/"+video_file)