← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~vamrocks602/music-app/test-empty-library into lp:music-app

 

Vamshi Balanaga has proposed merging lp:~vamrocks602/music-app/test-empty-library into lp:music-app.

Requested reviews:
  Nicholas Skaggs (nskaggs)

For more details, see:
https://code.launchpad.net/~vamrocks602/music-app/test-empty-library/+merge/280794

Created a test to check if the LibraryEmptyState page is displayed when no music is detected in the target directory.
-- 
Your team Music App Developers is subscribed to branch lp:music-app.
=== modified file 'app/ui/LibraryEmptyState.qml'
--- app/ui/LibraryEmptyState.qml	2015-10-28 01:05:33 +0000
+++ app/ui/LibraryEmptyState.qml	2015-12-17 03:22:43 +0000
@@ -22,6 +22,8 @@
 
 Page {
     id: libraryEmptyPage
+    objectName: "emptyLibrary"
+    visible: false
     anchors {
         fill: parent
     }
@@ -32,6 +34,11 @@
         locked: true
     }
 
+    // Hack for autopilot otherwise LibraryEmptyState appears as Page
+    // due to bug 1341671 it is required that there is a property so that
+    // qml doesn't optimise using the parent type
+    property bool bug1341671workaround: true
+
     // Overlay to show when no tracks detected on the device
     Rectangle {
         id: libraryEmpty
@@ -105,6 +112,7 @@
 
             Label {
                 color: styleMusic.libraryEmpty.labelColor
+                objectName: "titleText"
                 elide: Text.ElideRight
                 fontSize: "x-large"
                 horizontalAlignment: Text.AlignLeft
@@ -116,6 +124,7 @@
 
             Label {
                 color: styleMusic.libraryEmpty.labelColor
+                objectName:"descriptiveText"
                 elide: Text.ElideRight
                 fontSize: "large"
                 horizontalAlignment: Text.AlignLeft

=== modified file 'tests/autopilot/music_app/__init__.py'
--- tests/autopilot/music_app/__init__.py	2015-11-03 03:55:07 +0000
+++ tests/autopilot/music_app/__init__.py	2015-12-17 03:22:43 +0000
@@ -135,6 +135,15 @@
         # wait for now playing page to be visible
         self.get_now_playing_page().visible.wait_for(True)
 
+    def get_LibraryEmptyState(self):
+        libraryEmpty = self.app.wait_select_single(LibraryEmptyState, objectName="emptyLibrary")
+        return libraryEmpty
+        
+class LibraryEmptyState(UbuntuUIToolkitCustomProxyObjectBase):
+    """Autopilot helper for LibraryEmptyState"""
+    def __init__(self, *args):
+        super(LibraryEmptyState, self).__init__(*args)
+        
 
 class Page(UbuntuUIToolkitCustomProxyObjectBase):
     """Autopilot helper for Pages."""

=== added directory 'tests/autopilot/music_app/content/blank-mediascanner-2.0'
=== added file 'tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.db'
Binary files tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.db	1970-01-01 00:00:00 +0000 and tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.db	2015-12-17 03:22:43 +0000 differ
=== added file 'tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql'
--- tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql	1970-01-01 00:00:00 +0000
+++ tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql	2015-12-17 03:22:43 +0000
@@ -0,0 +1,1 @@
+INSERT INTO schemaVersion VALUES(9)
\ No newline at end of file

=== added file 'tests/autopilot/music_app/content/mediascanner-2.0/.help'
=== added file 'tests/autopilot/music_app/content/mediascanner-2.0/blank_mediastore.sql.THIS'
--- tests/autopilot/music_app/content/mediascanner-2.0/blank_mediastore.sql.THIS	1970-01-01 00:00:00 +0000
+++ tests/autopilot/music_app/content/mediascanner-2.0/blank_mediastore.sql.THIS	2015-12-17 03:22:43 +0000
@@ -0,0 +1,83 @@
+PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE IF NOT EXISTS'schemaVersion' (version INTEGER);
+DELETE FROM 'schemaVersion';
+INSERT INTO 'schemaVersion' VALUES(9);
+DROP TABLE IF EXISTS media_attic;
+CREATE TABLE media_attic (
+    id INTEGER PRIMARY KEY,
+    filename TEXT UNIQUE NOT NULL,
+    content_type TEXT,
+    etag TEXT,
+    title TEXT,
+    date TEXT,
+    artist TEXT,          -- Only relevant to audio
+    album TEXT,           -- Only relevant to audio
+    album_artist TEXT,    -- Only relevant to audio
+    genre TEXT,           -- Only relevant to audio
+    disc_number INTEGER,  -- Only relevant to audio
+    track_number INTEGER, -- Only relevant to audio
+    duration INTEGER,
+    width INTEGER,        -- Only relevant to video/images
+    height INTEGER,       -- Only relevant to video/images
+    latitude DOUBLE,
+    longitude DOUBLE,
+    has_thumbnail INTEGER,
+    mtime INTEGER,
+    type INTEGER   -- 0=Audio, 1=Video
+);
+PRAGMA writable_schema=ON;
+INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)VALUES('table','media_fts','media_fts',0,'CREATE VIRTUAL TABLE media_fts
+USING fts4(content=''media'', title, artist, album, tokenize=mozporter)');
+--DROP TABLE 'media_fts_segments';
+CREATE TABLE IF NOT EXISTS'media_fts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
+--DROP TABLE 'media_fts_segdir';
+CREATE TABLE IF NOT EXISTS'media_fts_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
+--DROP TABLE 'media_fts_stat';
+CREATE TABLE IF NOT EXISTS 'media_fts_stat'(id INTEGER PRIMARY KEY, value BLOB);
+--PREVIOUSLY ENCOUNTERED AN ERROR AT THIS LINE: COMMENTING PROBABLY NOT BEST FIX
+--INSERT INTO "media_fts_stat" VALUES(0,X'10230501F502');
+CREATE TABLE IF NOT EXISTS broken_files (
+    filename TEXT PRIMARY KEY NOT NULL,
+    etag TEXT NOT NULL
+);
+DROP TABLE IF EXISTS media;
+CREATE TABLE media (
+    filename TEXT PRIMARY KEY NOT NULL CHECK (filename LIKE '/%'),
+    content_type TEXT,
+    etag TEXT,
+    title TEXT,
+    date TEXT,
+    artist TEXT,          -- Only relevant to audio
+    album TEXT,           -- Only relevant to audio
+    album_artist TEXT,    -- Only relevant to audio
+    genre TEXT,           -- Only relevant to audio
+    disc_number INTEGER,  -- Only relevant to audio
+    track_number INTEGER, -- Only relevant to audio
+    duration INTEGER,
+    width INTEGER,        -- Only relevant to video/images
+    height INTEGER,       -- Only relevant to video/images
+    latitude DOUBLE,
+    longitude DOUBLE,
+    has_thumbnail INTEGER CHECK (has_thumbnail IN (0, 1)),
+    mtime INTEGER,
+    type INTEGER CHECK (type IN (1, 2, 3)) -- MediaType enum
+);
+CREATE INDEX media_type_idx ON media(type);
+CREATE INDEX media_song_info_idx ON media(type, album_artist, album, disc_number, track_number, title) WHERE type = 0;
+CREATE INDEX media_genre_idx ON media(type, genre) WHERE type = 0;
+CREATE INDEX media_artist_idx ON media(type, artist) WHERE type = 0;
+CREATE TRIGGER media_bu BEFORE UPDATE ON media BEGIN
+  DELETE FROM media_fts WHERE docid=old.rowid;
+END;
+CREATE TRIGGER media_bd BEFORE DELETE ON media BEGIN
+  DELETE FROM media_fts WHERE docid=old.rowid;
+END;
+CREATE TRIGGER media_au AFTER UPDATE ON media BEGIN
+  INSERT INTO media_fts(docid, title, artist, album) VALUES (new.rowid, new.title, new.artist, new.album);
+END;
+CREATE TRIGGER media_ai AFTER INSERT ON media BEGIN
+  INSERT INTO media_fts(docid, title, artist, album) VALUES (new.rowid, new.title, new.artist, new.album);
+END;
+PRAGMA writable_schema=OFF;
+COMMIT;

=== added file 'tests/autopilot/music_app/content/mediascanner-2.0/blank_mediastore.sql~'
--- tests/autopilot/music_app/content/mediascanner-2.0/blank_mediastore.sql~	1970-01-01 00:00:00 +0000
+++ tests/autopilot/music_app/content/mediascanner-2.0/blank_mediastore.sql~	2015-12-17 03:22:43 +0000
@@ -0,0 +1,83 @@
+PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE IF NOT EXISTS'schemaVersion' (version INTEGER);
+DELETE FROM 'schemaVersion';
+INSERT INTO 'schemaVersion' VALUES(9);
+DROP TABLE IF EXISTS media_attic;
+CREATE TABLE media_attic (
+    id INTEGER PRIMARY KEY,
+    filename TEXT UNIQUE NOT NULL,
+    content_type TEXT,
+    etag TEXT,
+    title TEXT,
+    date TEXT,
+    artist TEXT,          -- Only relevant to audio
+    album TEXT,           -- Only relevant to audio
+    album_artist TEXT,    -- Only relevant to audio
+    genre TEXT,           -- Only relevant to audio
+    disc_number INTEGER,  -- Only relevant to audio
+    track_number INTEGER, -- Only relevant to audio
+    duration INTEGER,
+    width INTEGER,        -- Only relevant to video/images
+    height INTEGER,       -- Only relevant to video/images
+    latitude DOUBLE,
+    longitude DOUBLE,
+    has_thumbnail INTEGER,
+    mtime INTEGER,
+    type INTEGER   -- 0=Audio, 1=Video
+);
+PRAGMA writable_schema=ON;
+INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)VALUES('table','media_fts','media_fts',0,'CREATE VIRTUAL TABLE media_fts
+USING fts4(content=''media'', title, artist, album, tokenize=mozporter)');
+--DROP TABLE 'media_fts_segments';
+CREATE TABLE IF NOT EXISTS'media_fts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
+--DROP TABLE 'media_fts_segdir';
+CREATE TABLE IF NOT EXISTS'media_fts_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
+--DROP TABLE 'media_fts_stat';
+CREATE TABLE IF NOT EXISTS 'media_fts_stat'(id INTEGER PRIMARY KEY, value BLOB);
+--PREVIOUSLY ENCOUNTERED AN ERROR AT THIS LINE: COMMENTING PROBABLY NOT BEST FIX
+--INSERT INTO "media_fts_stat" VALUES(0,X'10230501F502');
+CREATE TABLE IF NOT EXISTS broken_files (
+    filename TEXT PRIMARY KEY NOT NULL,
+    etag TEXT NOT NULL
+);
+DROP TABLE IF EXISTS media;
+CREATE TABLE media (
+    filename TEXT PRIMARY KEY NOT NULL CHECK (filename LIKE '/%'),
+    content_type TEXT,
+    etag TEXT,
+    title TEXT,
+    date TEXT,
+    artist TEXT,          -- Only relevant to audio
+    album TEXT,           -- Only relevant to audio
+    album_artist TEXT,    -- Only relevant to audio
+    genre TEXT,           -- Only relevant to audio
+    disc_number INTEGER,  -- Only relevant to audio
+    track_number INTEGER, -- Only relevant to audio
+    duration INTEGER,
+    width INTEGER,        -- Only relevant to video/images
+    height INTEGER,       -- Only relevant to video/images
+    latitude DOUBLE,
+    longitude DOUBLE,
+    has_thumbnail INTEGER CHECK (has_thumbnail IN (0, 1)),
+    mtime INTEGER,
+    type INTEGER CHECK (type IN (1, 2, 3)) -- MediaType enum
+);
+CREATE INDEX media_type_idx ON media(type);
+CREATE INDEX media_song_info_idx ON media(type, album_artist, album, disc_number, track_number, title) WHERE type = 0;
+CREATE INDEX media_genre_idx ON media(type, genre) WHERE type = 0;
+CREATE INDEX media_artist_idx ON media(type, artist) WHERE type = 0;
+CREATE TRIGGER media_bu BEFORE UPDATE ON media BEGIN
+  DELETE FROM media_fts WHERE docid=old.rowid;
+END;
+CREATE TRIGGER media_bd BEFORE DELETE ON media BEGIN
+  DELETE FROM media_fts WHERE docid=old.rowid;
+END;
+CREATE TRIGGER media_au AFTER UPDATE ON media BEGIN
+  INSERT INTO media_fts(docid, title, artist, album) VALUES (new.rowid, new.title, new.artist, new.album);
+END;
+CREATE TRIGGER media_ai AFTER INSERT ON media BEGIN
+  INSERT INTO media_fts(docid, title, artist, album) VALUES (new.rowid, new.title, new.artist, new.album);
+END;
+PRAGMA writable_schema=OFF;
+COMMIT;

=== modified file 'tests/autopilot/music_app/content/mediascanner-2.0/mediastore.db'
Binary files tests/autopilot/music_app/content/mediascanner-2.0/mediastore.db	2015-11-01 16:17:33 +0000 and tests/autopilot/music_app/content/mediascanner-2.0/mediastore.db	2015-12-17 03:22:43 +0000 differ
=== modified file 'tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch'
--- tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch	2015-11-03 02:43:10 +0000
+++ tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch	2015-12-17 03:22:43 +0000
@@ -27,6 +27,7 @@
 CREATE INDEX media_genre_idx ON media(type, genre) WHERE type = 1;
 CREATE INDEX media_mtime_idx ON media(type, mtime);
 CREATE TABLE media_attic (
+    id INTEGER PRIMARY KEY,
     filename TEXT UNIQUE NOT NULL,
     content_type TEXT,
     etag TEXT,
@@ -48,7 +49,7 @@
     type INTEGER   -- 0=Audio, 1=Video
 );
 CREATE VIRTUAL TABLE media_fts
-USING fts4(content='media', title, artist, album, tokenize=mozporter);
+USING fts4(content='media', title, artist, album, tokenize=porter);
 CREATE TABLE 'media_fts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
 CREATE TABLE 'media_fts_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
 CREATE TABLE 'media_fts_docsize'(docid INTEGER PRIMARY KEY, size BLOB);

=== modified file 'tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sql'
--- tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sql	2015-11-03 02:43:10 +0000
+++ tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sql	2015-12-17 03:22:43 +0000
@@ -1,8 +1,8 @@
 BEGIN TRANSACTION;
 DELETE FROM `schemaVersion`;
-INSERT INTO `schemaVersion` VALUES(10);
+INSERT INTO `schemaVersion` VALUES(9);
 
-DROP TABLE media;
+DROP TABLE  media;
 CREATE TABLE media (
     filename TEXT PRIMARY KEY NOT NULL CHECK (filename LIKE '/%'),
     content_type TEXT,

=== added directory 'tests/autopilot/music_app/content/mediascanner-2.0/songs'
=== renamed file 'tests/autopilot/music_app/content/1.ogg' => 'tests/autopilot/music_app/content/mediascanner-2.0/songs/1.ogg'
=== renamed file 'tests/autopilot/music_app/content/2.ogg' => 'tests/autopilot/music_app/content/mediascanner-2.0/songs/2.ogg'
=== renamed file 'tests/autopilot/music_app/content/3.mp3' => 'tests/autopilot/music_app/content/mediascanner-2.0/songs/3.mp3'
=== modified file 'tests/autopilot/music_app/tests/__init__.py'
--- tests/autopilot/music_app/tests/__init__.py	2015-02-03 14:42:34 +0000
+++ tests/autopilot/music_app/tests/__init__.py	2015-12-17 03:22:43 +0000
@@ -22,6 +22,7 @@
 import sqlite3
 import logging
 import music_app
+import sys
 
 import fixtures
 from music_app import MusicApp
@@ -34,13 +35,9 @@
 
 logger = logging.getLogger(__name__)
 
-
-class BaseTestCaseWithPatchedHome(AutopilotTestCase):
-
+class BaseTestClassWithPatchedHome(AutopilotTestCase):
     """A common test case class that provides several useful methods for
-    music-app tests.
-
-    """
+    music-app tests."""
 
     working_dir = os.getcwd()
     local_location_dir = os.path.dirname(os.path.dirname(working_dir))
@@ -59,11 +56,7 @@
             test_type = 'click'
         return launch, test_type
 
-    def setUp(self):
-        super(BaseTestCaseWithPatchedHome, self).setUp()
-        self.launcher, self.test_type = self.get_launcher_method_and_type()
-        self.home_dir = self._patch_home()
-        self._create_music_library()
+
 
     @autopilot_logging.log_action(logger.info)
     def launch_test_local(self):
@@ -141,29 +134,31 @@
             logger.debug("Patched home to fake home directory %s" % temp_dir)
         return temp_dir
 
-    def _create_music_library(self):
+    def _create_music_library(self, db_dir):
         logger.debug("Creating music library for %s test" % self.test_type)
         logger.debug("Home set to %s" % self.home_dir)
         musicpath = os.path.join(self.home_dir, 'Music')
         logger.debug("Music path set to %s" % musicpath)
         mediascannerpath = os.path.join(self.home_dir,
                                         '.cache/mediascanner-2.0')
+        logger.debug("Mediascanner path set to %s" % mediascannerpath)
+
         if not os.path.exists(musicpath):
             os.makedirs(musicpath)
-        logger.debug("Mediascanner path set to %s" % mediascannerpath)
 
         # set content path
         content_dir = os.path.join(os.path.dirname(music_app.__file__),
-                                   'content')
-
+                                                 'content', db_dir)
+        songs_dir = os.path.join(content_dir, 'songs')
         logger.debug("Content dir set to %s" % content_dir)
 
         # copy content
-        shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)
-        shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)
-        shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)
+        if os.path.isdir(songs_dir):
+            shutil.copy(os.path.join(songs_dir, '1.ogg'), musicpath)
+            shutil.copy(os.path.join(songs_dir, '2.ogg'), musicpath)
+            shutil.copy(os.path.join(songs_dir, '3.mp3'), musicpath)
 
-        logger.debug("Music copied, files " + str(os.listdir(musicpath)))
+            logger.debug("Music copied, files " + str(os.listdir(musicpath)))
 
         if self.test_type is not 'click':
             self._patch_mediascanner_home(content_dir, mediascannerpath)
@@ -172,8 +167,8 @@
         # do some inline db patching
         # patch mediaindex to proper home
         # these values are dependent upon our sampled db
-        shutil.copytree(
-            os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
+        shutil.copytree(content_dir, mediascannerpath)
+
         logger.debug("Patching fake mediascanner database in %s" %
                      mediascannerpath)
         logger.debug(
@@ -182,6 +177,7 @@
 
         relhome = self.home_dir[1:]
         dblocation = "home/phablet"
+
         # patch mediaindex
         self._file_find_replace(mediascannerpath +
                                 "/mediastore.sql", dblocation, relhome)
@@ -190,7 +186,12 @@
         f = open(mediascannerpath + "/mediastore.sql", 'rb')
         sql = f.read().decode("utf-8")
         cur = con.cursor()
-        cur.executescript(sql)
+        try:
+            cur.executescript(sql)
+            con.commit()
+        except:
+            logger.debug("Mediscanner patching failed %s" % sys.exc_info()[0])
+            raise
         con.close()
 
         logger.debug(
@@ -213,6 +214,27 @@
         os.rename(out_filename, in_filename)
 
 
+class BaseTestCaseWithPatchedHome(BaseTestClassWithPatchedHome):
+
+    """ Base test case class for music-app, with viable audio files loaded."""
+
+    def setUp(self):
+        super(BaseTestClassWithPatchedHome, self).setUp()
+        self.launcher, self.test_type = self.get_launcher_method_and_type()
+        self.home_dir = self._patch_home()
+        self._create_music_library('mediascanner-2.0')
+
+class EmptyLibraryWithPatchedHome(BaseTestClassWithPatchedHome):
+
+    """ Base test case class for music-app with empty library. """
+
+    def setUp(self):
+        super(BaseTestClassWithPatchedHome, self).setUp()
+        self.launcher, self.test_type = self.get_launcher_method_and_type()
+        self.home_dir = self._patch_home()
+        self._create_music_library('blank-mediascanner-2.0')
+
+
 class MusicAppTestCase(BaseTestCaseWithPatchedHome):
 
     """Base test case that launches the music-app."""
@@ -220,3 +242,18 @@
     def setUp(self):
         super(MusicAppTestCase, self).setUp()
         self.app = MusicApp(self.launcher())
+
+
+class MusicAppTestCaseEmptyLibrary(EmptyLibraryWithPatchedHome):
+
+    """Test case that launches the music-app with no music: an empty library."""
+
+    def setUp(self):
+        super(MusicAppTestCaseEmptyLibrary, self).setUp()
+        self.app = MusicApp(self.launcher())
+
+
+
+
+
+

=== modified file 'tests/autopilot/music_app/tests/test_music.py'
--- tests/autopilot/music_app/tests/test_music.py	2015-11-02 05:19:12 +0000
+++ tests/autopilot/music_app/tests/test_music.py	2015-12-17 03:22:43 +0000
@@ -14,10 +14,25 @@
 from testtools.matchers import Equals, GreaterThan, LessThan, NotEquals
 
 
-from music_app.tests import MusicAppTestCase
+from music_app.tests import MusicAppTestCase, MusicAppTestCaseEmptyLibrary
 
 logger = logging.getLogger(__name__)
 
+class TestEmptyLibrary(MusicAppTestCaseEmptyLibrary):
+
+    def setUp(self):
+        super(TestEmptyLibrary, self).setUp()
+        self.app.get_walkthrough_page().skip()
+
+    def test_display_message_when_no_music(self):
+        """When no music is detected, the app must display a certain message"""
+
+        #obtain the LibraryEmptyState page
+        library = self.app.get_LibraryEmptyState()
+
+        #check if the correct page(LibraryEmptyState) is being shown
+        self.assertThat(library.visible, Eventually(Equals(True)))
+    
 
 class TestMainWindow(MusicAppTestCase):
 


Follow ups