~canonical-platform-qa/ubuntu-system-tests/app_startup_poc

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/tests/test_sdcard.py

  • Committer: Sergio Cazzolato
  • Date: 2015-12-03 19:54:05 UTC
  • mfrom: (277.1.8 trunk)
  • mto: (277.1.15 trunk)
  • mto: This revision was merged to the branch mainline in revision 281.
  • Revision ID: sergio.cazzolato@canonical.com-20151203195405-kl29cvh0k177j1jc
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#
19
19
 
20
20
import os
 
21
import tempfile
 
22
from urllib import request
21
23
 
22
24
from testtools import skipUnless
23
25
 
24
26
from ubuntu_system_tests.helpers.data import load_test_metadata
25
27
from ubuntu_system_tests.helpers import file_system as fs
 
28
from ubuntu_system_tests.helpers import images
26
29
from ubuntu_system_tests.helpers import indicators
27
30
from ubuntu_system_tests.helpers import media
28
31
from ubuntu_system_tests.helpers import mediaplayer
 
32
from ubuntu_system_tests.helpers import music
29
33
from ubuntu_system_tests.helpers import scopes
30
34
from ubuntu_system_tests.helpers import sdcard
31
35
from ubuntu_system_tests.helpers import url_dispatcher
32
36
from ubuntu_system_tests.helpers.unity8 import get_dash
33
37
from ubuntu_system_tests.helpers import wait_until
 
38
from ubuntu_system_tests.helpers import web
34
39
 
35
40
from ubuntu_system_tests.tests import base
36
41
 
45
50
 
46
51
SRC_AUDIO_FILE_1 = os.path.join(fs.DIR_TEST_DATA_AUDIO,
47
52
                                data.audio.count20.file)
 
53
SRC_AUDIO_FILE_2 = os.path.join(fs.DIR_TEST_DATA_AUDIO,
 
54
                                data.audio.mp3_file.file)
48
55
SRC_VIDEO_FILE_1 = os.path.join(fs.DIR_TEST_DATA_VIDEO,
49
56
                                data.video.video_avi)
50
57
SRC_PICTURE_FILE_1 = os.path.join(fs.DIR_TEST_DATA_IMAGES,
62
69
        current_scope_url = get_dash().get_current_scope().get_url()
63
70
        self.addCleanup(url_dispatcher.go_to_url, current_scope_url)
64
71
        self.msg_number = 0
 
72
        self.unity_proxy.main_window.clear_notifications()
65
73
 
66
74
    def _get_message_indicator(self):
67
75
        return indicators.MessageIndicator(self.unity_proxy.main_window,
93
101
        indicator = self._get_message_indicator()
94
102
        self.assertIn(INSERT_MSG, indicator.get_last_message(self.msg_number))
95
103
 
 
104
    def _copy_pictures(self, src_file, number):
 
105
        """ Copy several pictures to the sdcard """
 
106
        extension = os.path.splitext(src_file)[1]
 
107
        for i in range(number):
 
108
            sdcard.copy_picture(src_file,
 
109
                                dst_name='pic_{}{}'.format(i, extension))
 
110
 
 
111
    def _copy_new_pictures(self, number):
 
112
        """ Create several pictures to the sd card that will appear in the
 
113
        today category
 
114
        """
 
115
        extension = os.path.splitext(SRC_PICTURE_FILE_1)[1]
 
116
        new_file = tempfile.mkstemp(suffix=extension)[1]
 
117
 
 
118
        images.create_new_image(SRC_PICTURE_FILE_1, new_file)
 
119
        self.addCleanup(os.remove, new_file)
 
120
        self._copy_pictures(new_file, number)
 
121
 
 
122
    def _copy_unknown_pictures(self, number):
 
123
        """ Copy several pictures to the sd card that will appear in the
 
124
        unknown category. The src picture is downloaded from the web.
 
125
        """
 
126
        src_url = 'http://people.canonical.com/~platform-qa/ubuntu.jpg'
 
127
        dst = tempfile.mkstemp(suffix='.jpg')[1]
 
128
 
 
129
        unknown_file = web.download_file(src_url, save_location=dst)
 
130
        self.addCleanup(os.remove, unknown_file)
 
131
        self._copy_pictures(unknown_file, number)
 
132
 
 
133
    @skipUnless(scopes.is_scope_included(scopes.SCOPE_ID_MUSIC), SKIP_REASON)
96
134
    def test_insert_sd_card_and_explore(self):
97
135
        """ Verify music stored in the sd card is displayed and can be played
98
136
        in the music scope when the sd card is inserted.
135
173
 
136
174
        self.assertTrue(wait_until(player.is_playing))
137
175
 
 
176
    @skipUnless(scopes.is_scope_included(scopes.SCOPE_ID_VIDEO), SKIP_REASON)
138
177
    def test_insert_sd_card_containing_new_videos(self):
139
178
        """ Verify a video stored is displayed when the sd card is inserted
140
179
        and can be reproduced in the media player from the video scope
170
209
        """ Verify a picture stored in the sd card can be viewed in the events
171
210
        view and can be fully displayed as well
172
211
        """
173
 
 
174
212
        # Prerequisite: Copy picture to the sd card
175
213
        dst_pic = sdcard.copy_picture(SRC_PICTURE_FILE_1)
176
214
 
179
217
 
180
218
        gallery.click_photo(dst_pic)
181
219
        self.assertTrue(gallery.is_image_in_view(dst_pic))
 
220
 
 
221
    @skipUnless(scopes.is_scope_included(scopes.SCOPE_ID_MUSIC), SKIP_REASON)
 
222
    def test_play_music_from_sd_card_in_music_app(self):
 
223
        """ Verify it is possible to reproduce music stored in the sd card
 
224
        from the music scope
 
225
        """
 
226
        album = data.audio.count20.album
 
227
        artist = data.audio.count20.artist
 
228
 
 
229
        # Prerequisite: Copy songs with same artist and album to the sd card
 
230
        sdcard.copy_music(SRC_AUDIO_FILE_1)
 
231
        sdcard.copy_music(SRC_AUDIO_FILE_2)
 
232
 
 
233
        scope = scopes.go_to_music_scope()
 
234
 
 
235
        # Go to the album preview
 
236
        artist_preview = scope.select_artist(artist)
 
237
        album_preview = artist_preview.select_album(album)
 
238
 
 
239
        # Play the album in the music app and verify the desired album is
 
240
        # being reproduced
 
241
        album_preview.play_in_music_app()
 
242
        self.assertTrue(wait_until(music.is_music_app_running, timeout=20))
 
243
        self.addCleanup(music.stop_music_app)
 
244
        self.assertEqual(request.pathname2url('/{}/{}'.format(artist, album)),
 
245
                         music.get_current_album())
 
246
 
 
247
    @skipUnless(scopes.is_scope_included(scopes.SCOPE_ID_PHOTOS), SKIP_REASON)
 
248
    def test_view_photos_from_sdcard(self):
 
249
        """ Validate pictures stored in the sd card are displayed in the photos
 
250
        scope and the buttons "See all" and "See less" work properly
 
251
        """
 
252
 
 
253
        # This step is added at the beginning to disable the skip button if
 
254
        # needed, this is done before copying the pictures to the sd card to
 
255
        # see those correctly in the 'my photos' section
 
256
        scopes.go_to_photos_scope()
 
257
 
 
258
        # Prerequisite: Copy several pictures to the sd card
 
259
        self._copy_new_pictures(20)
 
260
        self._copy_unknown_pictures(2)
 
261
 
 
262
        # Reload scope and go to my photos section
 
263
        scope = scopes.go_to_photos_scope()
 
264
        my_photos = scope.go_to_my_photos()
 
265
 
 
266
        today = my_photos.get_today_category()
 
267
        # Check all the pictures are displayed clicking on "See all"
 
268
        self.assertTrue(today.is_see_all_displayed())
 
269
        my_photos.see_all(today)
 
270
        self.assertLessEqual(20, len(today.get_pictures_list()))
 
271
        self.assertTrue(today.expanded)
 
272
 
 
273
        # Check the pictures section is not expanded clicking on "See less"
 
274
        self.assertTrue(today.is_see_less_displayed())
 
275
        my_photos.see_less(today)
 
276
        self.assertTrue(wait_until(today.is_not_see_less_displayed))