22
from urllib import request
22
24
from testtools import skipUnless
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
35
40
from ubuntu_system_tests.tests import base
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()
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))
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))
111
def _copy_new_pictures(self, number):
112
""" Create several pictures to the sd card that will appear in the
115
extension = os.path.splitext(SRC_PICTURE_FILE_1)[1]
116
new_file = tempfile.mkstemp(suffix=extension)[1]
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)
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.
126
src_url = 'http://people.canonical.com/~platform-qa/ubuntu.jpg'
127
dst = tempfile.mkstemp(suffix='.jpg')[1]
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)
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.
180
218
gallery.click_photo(dst_pic)
181
219
self.assertTrue(gallery.is_image_in_view(dst_pic))
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
226
album = data.audio.count20.album
227
artist = data.audio.count20.artist
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)
233
scope = scopes.go_to_music_scope()
235
# Go to the album preview
236
artist_preview = scope.select_artist(artist)
237
album_preview = artist_preview.select_album(album)
239
# Play the album in the music app and verify the desired album is
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())
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
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()
258
# Prerequisite: Copy several pictures to the sd card
259
self._copy_new_pictures(20)
260
self._copy_unknown_pictures(2)
262
# Reload scope and go to my photos section
263
scope = scopes.go_to_photos_scope()
264
my_photos = scope.go_to_my_photos()
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)
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))