Merge lp:~fazerlicourice/music-app/test-empty-library into lp:music-app

Proposed by Vamshi Balanaga
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 988
Merged at revision: 960
Proposed branch: lp:~fazerlicourice/music-app/test-empty-library
Merge into: lp:music-app
Diff against target: 357 lines (+118/-32)
8 files modified
AUTHORS (+1/-0)
app/ui/LibraryEmptyState.qml (+8/-0)
debian/changelog (+4/-1)
tests/autopilot/music_app/__init__.py (+12/-2)
tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql (+1/-0)
tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch (+2/-1)
tests/autopilot/music_app/tests/__init__.py (+73/-27)
tests/autopilot/music_app/tests/test_music.py (+17/-1)
To merge this branch: bzr merge lp:~fazerlicourice/music-app/test-empty-library
Reviewer Review Type Date Requested Status
Jenkins Bot continuous-integration Approve
Victor Thompson Approve
Andrew Hayzen Approve
Nicholas Skaggs (community) Needs Fixing
Review via email: mp+280794@code.launchpad.net

Commit message

* Add test to make sure that the LibraryEmptyState page is visible when no music is detected on the device.

Description of the change

Created a test to check if the LibraryEmptyState page is displayed when no music is detected in the target directory.

To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

In addition to the comments below, does this pass pep8?

Revision history for this message
Nicholas Skaggs (nskaggs) :
review: Needs Fixing
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

So add the removal code, and this is a +1 from me. Good work!

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Looking good so far, a few inline comments, I haven't run the code yet these are just observations :-)

Also the code should pass PEP8 and pyflakes, see the link [0] for the current errors.

And could you add an entry for yourself in the debian/changelog (simply run $ dch) and link bug 1261587 as has been done in other entries.

0 - http://pastebin.ubuntu.com/14082325/

review: Needs Fixing
Revision history for this message
Victor Thompson (vthompson) wrote :

I don't think we should be setting the schema version of mediascanner2 back to version 9. If it is perhaps an issue for developers/testers not running the development release, then we need to add instructions on how to install the newest release of mediascanner2 that is on the phone. Likewise, I think the other changes to the mediastore.db file should be reverted.

review: Needs Fixing
Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

It now passes pep8 and snowflake tests and I have added an entry for me in debian/changelog.

Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

If I attempt to edit any of the .sql files, when I try to read them and convert them to .db, it doesn't work. The current .db files are from nskaggs' patch. I was unable to get the sql stuff to work. I get the error- 'no such table: schemaVersion' just like I was getting earlier. If I revert back to the patch that nskaggs had provided, they all work, but if I make any changes and then attempt to read them with "sqlite3 mediastore.db < mediastore.sql" it doesn't work.

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Victor, ohh you DO want schema 10? I needed it locally, but for some reason, I thought you wanted schema 9. The changes to mediastore.db should be easy enough to revert if you don't like / want them.

Vamshi, The new files are in tests/autopilot/music_app/content/blank-mediascanner-2.0. You don't need to touch them and they are fine. I repeat, you don't need to create any database files, so don't worry about that.

From reading the comments I would:

1) Update the insert schema version to 10 in the sql files
2) Checkout the older revision of tests/autopilot/music_app/content/mediascanner-2.0/mediastore.db and replace it so there is no diff with this MP.

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

One additional comment on how you are removing files.

review: Needs Fixing
Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

Like I said earlier, when I try to edit the sql files, the tests fail regardless of whether or not I had sqlite3 read them and convert to .db. Initially I'll get an error that says incomplete sql, this is because there is no semi-colon at the end of the line. After I add the semi-colon, it says no such table schemaVersion.

Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

I changed the schemaVersion to 10 and I changed the file removal parameter. The tests no longer work for me because its schemaVersion 10 but Nicholas informed me that its right.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Some more inline comments :-)

1) I don't think you need to add the visible: false as the object is created when it is required.
2) I wonder if this method should be get_library_empty_state() or get_library_empty_state_page() ? To match the pattern of the other methods?
3) Can the double space be fixed to a single space?
4) This import can be removed, see further details below.
5) If the first os.remove() fails, then this throws the exception before it can attempt to remove the others?
6) Change this to
except Exception as e:
    logger.debug("Mediscanner patching failed %s" % e)

Or for exactly the same
except Exception as e:
    logger.debug("Mediscanner patching failed %s" % type(e))

review: Needs Fixing
Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

Andrew, I made those changes and pushed.

Revision history for this message
Victor Thompson (vthompson) wrote :

When I run these tests on the device or when run on the desktop, each test produces the "No music found" view. Here is the output on the desktop: http://paste.ubuntu.com/14123722/

review: Needs Fixing
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

The error is "Could not initialise media store: Tried to open a db with schema version 9, while supported version is 10."

bzr thinks that the mediastore.db has been modified, so what changes have been made to that?

=== 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-20 00:11:18 +0000 differ

Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

I didn't make any changes to the .db files. All I did was change the
schemaVersion in the .sql files to 10. I tried converting those .sql files
to .db files but I got some errors and when I told Nicholas he said that I
don't need to do that, and that I should leave the .db files as they are.

Vamshi Balanaga

On Mon, Dec 21, 2015 at 7:21 AM, Andrew Hayzen <email address hidden> wrote:

> The error is "Could not initialise media store: Tried to open a db with
> schema version 9, while supported version is 10."
>
> bzr thinks that the mediastore.db has been modified, so what changes have
> been made to that?
>
> === 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-20
> 00:11:18 +0000 differ
> --
>
> https://code.launchpad.net/~vamrocks602/music-app/test-empty-library/+merge/280794
> You are the owner of lp:~vamrocks602/music-app/test-empty-library.
>

Revision history for this message
Victor Thompson (vthompson) wrote :

Vamshi,

It seems that the test you added is failing: http://paste.ubuntu.com/14134202/

Should "get_LibraryEmptyState" actually be "get_library_empty_state_page" or something else perhaps?

review: Needs Fixing
Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

I apologize for that, I thought that I changed that. It's done now, just
pushed.

Revision history for this message
Victor Thompson (vthompson) wrote :

Vamshi,

The test still does not work. Here's the log output--I believe you need to ad "_page" to the method call.

test-log: {{{
18:34:56.811 INFO logging:45 - TestEmptyLibrary: launch_test_local. Arguments (). Keyword arguments: {}.
18:34:56.811 WARNING base:52 - This function is deprecated. Use get_toolkit_launcher_command() instead.
18:34:56.811 INFO _launcher:392 - Attempting to launch application '/usr/lib/x86_64-linux-gnu/qt5/bin/qmlscene' with arguments '/home/victor/Development/test-empty-library/app/music-app.qml debug' as a normal process
18:34:56.821 INFO _launcher:450 - Launching process: ['/usr/lib/x86_64-linux-gnu/qt5/bin/qmlscene', '-testability', '/home/victor/Development/test-empty-library/app/music-app.qml', 'debug']
18:35:00.423 INFO _launcher:563 - waiting for process to exit.
18:35:00.423 INFO _launcher:586 - Killing process 36773
18:35:00.531 WARNING content:83 - Followed stream is empty.
}}}

Traceback (most recent call last):
  File "/home/victor/Development/test-empty-library/tests/autopilot/music_app/tests/test_music.py", line 32, in test_display_message_when_no_music
    library = self.app.get_library_empty_state()
AttributeError: 'MusicApp' object has no attribute 'get_library_empty_state'

Ran 20 tests in 253.585s
FAILED (failures=1)

review: Needs Fixing
Revision history for this message
Victor Thompson (vthompson) wrote :

Also, you'll need to resolve the merge conflict in the debian/changelog file. We get such conflicts frequently as multiple people work to propose merges.

To fix, do the following:

$ bzr merge lp:music-app

Then, fix the conflict in the debian/changelog and save it. Then run:

$ bzr resolve debian/changelog

From there just commit and push the changes as usual.

Revision history for this message
Victor Thompson (vthompson) wrote :

Lastly, when I run this on the device I get the "No music found" page consistently. I imagine there might be something in the change to how we do mocking that might have caused it.

ahazyen, balloons: Can you guys work with Vamshi to fix this issue?

review: Needs Fixing
Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

I fixed the method name, and resolved the conflict.

Vamshi Balanaga

On Tue, Dec 22, 2015 at 8:09 PM, Victor Thompson <email address hidden>
wrote:

> Review: Needs Fixing
>
> Lastly, when I run this on the device I get the "No music found" page
> consistently. I imagine there might be something in the change to how we do
> mocking that might have caused it.
>
> ahazyen, balloons: Can you guys work with Vamshi to fix this issue?
> --
>
> https://code.launchpad.net/~vamrocks602/music-app/test-empty-library/+merge/280794
> You are the owner of lp:~vamrocks602/music-app/test-empty-library.
>

Revision history for this message
Victor Thompson (vthompson) wrote :

Thanks Vamshi.

We still need input/verification on the device tests. I won't have the time to help you with this in the near term.

Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

By verification, do you mean you have to see if it works? Or do know that it doesn't work and you need to see what's wrong?

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Hey Vamshi! I've asked Andrew to do 2 things.

1) Test this out so we can merge it :-)
2) Add some more autopilot tasks to GCI so you can have some more fun.

Thanks again for working on this and sorry for the delay in verifying.

Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

Thank you very much.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

OK this is erroring still due to
[Errno 2] No such file or directory: '/tmp/adt-run.XH20gO/tree/tests/autopilot/music_app/content/blank-mediascanner-2.0/songs/1.ogg'
[Errno 2] No such file or directory: '/tmp/adt-run.XH20gO/tree/tests/autopilot/music_app/content/blank-mediascanner-2.0/songs/2.ogg'
[Errno 2] No such file or directory: '/tmp/adt-run.XH20gO/tree/tests/autopilot/music_app/content/blank-mediascanner-2.0/songs/3.mp3'

However it was silently failing, so we didn't know it was unable to remove the files, full log with my extra debugging can be found here [0]

There are two inline comments (3 instances of each) to fix, which should resolve this
1) This should be
os.remove(os.path.join(musicpath, '1.ogg'))
2) As these were failing silently, can we change these to
except OSError as e:
    logger.debug("Error removing" + str(e))

Once you have fixed those issues, the test passes for me :-) My diff looks like this [1]

0 - http://pastebin.ubuntu.com/14404744/
1 - http://pastebin.ubuntu.com/14404783/

review: Needs Fixing
Revision history for this message
Vamshi Balanaga (fazerlicourice) wrote :

Made the changes and pushed.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

LGTM! Thanks for your patience and time spent on this :-)

Took me 4 runs but I eventually got

test autopilot: - - - - - - - - - - results - - - - - - - - - -
autopilot PASS

\o/

For the other 3 runs I had test_shuffle (once) and test_pressing_prev_from_first_song_plays_last_when_repeat_on (twice) fail looks like they are possibly flaky tests, hopefully test_shuffle will be improved after the bgplaylists, or just because I'm running custom versions of qtubuntu-media.

review: Approve
Revision history for this message
Victor Thompson (vthompson) wrote :

Running from the deksopt:

Tests running...

Ran 20 tests in 392.937s
OK

We can try to fix the flakiness of the tests at a later time--as it wouldn't have been introduced under this change.

Thanks! lgtm!

review: Approve
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://core-apps-jenkins.ubuntu.com/job/music-app-autolanding/8/
Executed test runs:
    None: https://core-apps-jenkins.ubuntu.com/job/generic-land-mp/1393/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) :
review: Approve (continuous-integration)
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :

FAILED: Autolanding.
Approved revid is not set in launchpad. This is most likely a launchpad issue and re-approve should fix it. There is also a chance (although a very small one) this is a permission problem of the ps-jenkins bot.
https://core-apps-jenkins.ubuntu.com/job/music-app-autolanding/9/
Executed test runs:
    None: https://core-apps-jenkins.ubuntu.com/job/generic-land-mp/1394/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AUTHORS'
2--- AUTHORS 2015-09-08 08:12:31 +0000
3+++ AUTHORS 2016-01-04 23:02:20 +0000
4@@ -37,5 +37,6 @@
5 Stefano Verzegnassi <stefano92.100@gmail.com>
6 Ted Gould <ted@gould.cx>
7 Tim Peeters <tim.peeters@canonical.com>
8+Vamshi Balanaga <vamrocks602@gmail.com>
9 VĂ­ctor R. Ruiz <victor.ruiz@canonical.com>
10 Victor Thompson <victor.thompson@gmail.com>
11
12=== modified file 'app/ui/LibraryEmptyState.qml'
13--- app/ui/LibraryEmptyState.qml 2015-10-28 01:05:33 +0000
14+++ app/ui/LibraryEmptyState.qml 2016-01-04 23:02:20 +0000
15@@ -22,6 +22,7 @@
16
17 Page {
18 id: libraryEmptyPage
19+ objectName: "emptyLibrary"
20 anchors {
21 fill: parent
22 }
23@@ -32,6 +33,11 @@
24 locked: true
25 }
26
27+ // Hack for autopilot otherwise LibraryEmptyState appears as Page
28+ // due to bug 1341671 it is required that there is a property so that
29+ // qml doesn't optimise using the parent type
30+ property bool bug1341671workaround: true
31+
32 // Overlay to show when no tracks detected on the device
33 Rectangle {
34 id: libraryEmpty
35@@ -105,6 +111,7 @@
36
37 Label {
38 color: styleMusic.libraryEmpty.labelColor
39+ objectName: "titleText"
40 elide: Text.ElideRight
41 fontSize: "x-large"
42 horizontalAlignment: Text.AlignLeft
43@@ -116,6 +123,7 @@
44
45 Label {
46 color: styleMusic.libraryEmpty.labelColor
47+ objectName:"descriptiveText"
48 elide: Text.ElideRight
49 fontSize: "large"
50 horizontalAlignment: Text.AlignLeft
51
52=== modified file 'debian/changelog'
53--- debian/changelog 2015-12-17 20:43:26 +0000
54+++ debian/changelog 2016-01-04 23:02:20 +0000
55@@ -1,11 +1,14 @@
56 music-app (2.3) UNRELEASED; urgency=medium
57-
58+
59 [ Andrew Hayzen ]
60 * Release 2.2ubuntu2 and start on 2.3
61
62 [ Ken VanDine ]
63 * Install the content-hub json file in the correct place for peer registry
64
65+ [ Vamshi Balanaga ]
66+ * Add test to make sure that the LibraryEmptyState page is visible when no audio is detected on the device (LP: #1261587).
67+
68 [ Girish Rawat ]
69 * Expanded and updated READMEs
70
71
72=== modified file 'tests/autopilot/music_app/__init__.py'
73--- tests/autopilot/music_app/__init__.py 2015-11-03 03:55:07 +0000
74+++ tests/autopilot/music_app/__init__.py 2016-01-04 23:02:20 +0000
75@@ -135,6 +135,16 @@
76 # wait for now playing page to be visible
77 self.get_now_playing_page().visible.wait_for(True)
78
79+ def get_library_empty_state_page(self):
80+ return self.app.wait_select_single(LibraryEmptyState,
81+ objectName="emptyLibrary")
82+
83+
84+class LibraryEmptyState(UbuntuUIToolkitCustomProxyObjectBase):
85+ """Autopilot helper for LibraryEmptyState"""
86+ def __init__(self, *args):
87+ super(LibraryEmptyState, self).__init__(*args)
88+
89
90 class Page(UbuntuUIToolkitCustomProxyObjectBase):
91 """Autopilot helper for Pages."""
92@@ -335,8 +345,8 @@
93 @click_object
94 def click_artist(self, i):
95 return self.wait_select_single("Card",
96- objectName="albumsPageGridItem"
97- + str(i))
98+ objectName="albumsPageGridItem" +
99+ str(i))
100
101 def get_artist(self):
102 return self.wait_select_single("UCLabel",
103
104=== added directory 'tests/autopilot/music_app/content/blank-mediascanner-2.0'
105=== added file 'tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.db'
106Binary 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 2016-01-04 23:02:20 +0000 differ
107=== added file 'tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql'
108--- tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql 1970-01-01 00:00:00 +0000
109+++ tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.sql 2016-01-04 23:02:20 +0000
110@@ -0,0 +1,1 @@
111+INSERT INTO schemaVersion VALUES(10)
112
113=== modified file 'tests/autopilot/music_app/content/mediascanner-2.0/mediastore.db'
114Binary 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 2016-01-04 23:02:20 +0000 differ
115=== modified file 'tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch'
116--- tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch 2015-11-03 02:43:10 +0000
117+++ tests/autopilot/music_app/content/mediascanner-2.0/mediastore.sch 2016-01-04 23:02:20 +0000
118@@ -27,6 +27,7 @@
119 CREATE INDEX media_genre_idx ON media(type, genre) WHERE type = 1;
120 CREATE INDEX media_mtime_idx ON media(type, mtime);
121 CREATE TABLE media_attic (
122+ id INTEGER PRIMARY KEY,
123 filename TEXT UNIQUE NOT NULL,
124 content_type TEXT,
125 etag TEXT,
126@@ -48,7 +49,7 @@
127 type INTEGER -- 0=Audio, 1=Video
128 );
129 CREATE VIRTUAL TABLE media_fts
130-USING fts4(content='media', title, artist, album, tokenize=mozporter);
131+USING fts4(content='media', title, artist, album, tokenize=porter);
132 CREATE TABLE 'media_fts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
133 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));
134 CREATE TABLE 'media_fts_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
135
136=== added directory 'tests/autopilot/music_app/content/mediascanner-2.0/songs'
137=== renamed file 'tests/autopilot/music_app/content/1.ogg' => 'tests/autopilot/music_app/content/mediascanner-2.0/songs/1.ogg'
138=== renamed file 'tests/autopilot/music_app/content/2.ogg' => 'tests/autopilot/music_app/content/mediascanner-2.0/songs/2.ogg'
139=== renamed file 'tests/autopilot/music_app/content/3.mp3' => 'tests/autopilot/music_app/content/mediascanner-2.0/songs/3.mp3'
140=== modified file 'tests/autopilot/music_app/tests/__init__.py'
141--- tests/autopilot/music_app/tests/__init__.py 2015-02-03 14:42:34 +0000
142+++ tests/autopilot/music_app/tests/__init__.py 2016-01-04 23:02:20 +0000
143@@ -35,12 +35,9 @@
144 logger = logging.getLogger(__name__)
145
146
147-class BaseTestCaseWithPatchedHome(AutopilotTestCase):
148-
149+class BaseTestClassWithPatchedHome(AutopilotTestCase):
150 """A common test case class that provides several useful methods for
151- music-app tests.
152-
153- """
154+ music-app tests."""
155
156 working_dir = os.getcwd()
157 local_location_dir = os.path.dirname(os.path.dirname(working_dir))
158@@ -59,12 +56,6 @@
159 test_type = 'click'
160 return launch, test_type
161
162- def setUp(self):
163- super(BaseTestCaseWithPatchedHome, self).setUp()
164- self.launcher, self.test_type = self.get_launcher_method_and_type()
165- self.home_dir = self._patch_home()
166- self._create_music_library()
167-
168 @autopilot_logging.log_action(logger.info)
169 def launch_test_local(self):
170 return self.launch_test_application(
171@@ -90,8 +81,8 @@
172 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
173
174 def _copy_xauthority_file(self, directory):
175- """ Copy .Xauthority file to directory, if it exists in /home
176- """
177+ """ Copy .Xauthority file to directory, if it exists in /home"""
178+
179 # If running under xvfb, as jenkins does,
180 # xsession will fail to start without xauthority file
181 # Thus if the Xauthority file is in the home directory
182@@ -107,8 +98,7 @@
183 os.path.join(directory, '.Xauthority'))
184
185 def _patch_home(self):
186- """ mock /home for testing purposes to preserve user data
187- """
188+ """ mock /home for testing purposes to preserve user data"""
189
190 # if running on non-phablet device,
191 # run in temp folder to avoid mucking up home
192@@ -141,29 +131,47 @@
193 logger.debug("Patched home to fake home directory %s" % temp_dir)
194 return temp_dir
195
196- def _create_music_library(self):
197+ def _create_music_library(self, db_dir):
198 logger.debug("Creating music library for %s test" % self.test_type)
199 logger.debug("Home set to %s" % self.home_dir)
200 musicpath = os.path.join(self.home_dir, 'Music')
201 logger.debug("Music path set to %s" % musicpath)
202 mediascannerpath = os.path.join(self.home_dir,
203 '.cache/mediascanner-2.0')
204+ logger.debug("Mediascanner path set to %s" % mediascannerpath)
205+
206 if not os.path.exists(musicpath):
207 os.makedirs(musicpath)
208- logger.debug("Mediascanner path set to %s" % mediascannerpath)
209
210 # set content path
211 content_dir = os.path.join(os.path.dirname(music_app.__file__),
212- 'content')
213-
214+ 'content', db_dir)
215+ songs_dir = os.path.join(content_dir, 'songs')
216 logger.debug("Content dir set to %s" % content_dir)
217
218 # copy content
219- shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)
220- shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)
221- shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)
222-
223- logger.debug("Music copied, files " + str(os.listdir(musicpath)))
224+ if os.path.isdir(songs_dir) and db_dir == 'mediascanner-2.0':
225+ shutil.copy(os.path.join(songs_dir, '1.ogg'), musicpath)
226+ shutil.copy(os.path.join(songs_dir, '2.ogg'), musicpath)
227+ shutil.copy(os.path.join(songs_dir, '3.mp3'), musicpath)
228+
229+ logger.debug("Music copied, files " + str(os.listdir(musicpath)))
230+ # delete content if previously copied
231+ elif not os.path.isdir(songs_dir):
232+ try:
233+ os.remove(os.path.join(musicpath, '1.ogg'))
234+ except OSError as e:
235+ logger.debug("Error removing" + str(e))
236+ try:
237+ os.remove(os.path.join(musicpath, '2.ogg'))
238+ except OSError as e:
239+ logger.debug("Error removing" + str(e))
240+ try:
241+ os.remove(os.path.join(musicpath, '3.mp3'))
242+ except OSError as e:
243+ logger.debug("Error removing" + str(e))
244+
245+ logger.debug("Music deleted, files " + str(os.listdir(musicpath)))
246
247 if self.test_type is not 'click':
248 self._patch_mediascanner_home(content_dir, mediascannerpath)
249@@ -172,8 +180,8 @@
250 # do some inline db patching
251 # patch mediaindex to proper home
252 # these values are dependent upon our sampled db
253- shutil.copytree(
254- os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)
255+ shutil.copytree(content_dir, mediascannerpath)
256+
257 logger.debug("Patching fake mediascanner database in %s" %
258 mediascannerpath)
259 logger.debug(
260@@ -182,6 +190,7 @@
261
262 relhome = self.home_dir[1:]
263 dblocation = "home/phablet"
264+
265 # patch mediaindex
266 self._file_find_replace(mediascannerpath +
267 "/mediastore.sql", dblocation, relhome)
268@@ -190,7 +199,12 @@
269 f = open(mediascannerpath + "/mediastore.sql", 'rb')
270 sql = f.read().decode("utf-8")
271 cur = con.cursor()
272- cur.executescript(sql)
273+ try:
274+ cur.executescript(sql)
275+ con.commit()
276+ except Exception as e:
277+ logger.debug("Mediscanner patching failed %s" % e)
278+ raise
279 con.close()
280
281 logger.debug(
282@@ -213,6 +227,28 @@
283 os.rename(out_filename, in_filename)
284
285
286+class BaseTestCaseWithPatchedHome(BaseTestClassWithPatchedHome):
287+
288+ """ Base test case class for music-app, with viable audio files loaded."""
289+
290+ def setUp(self):
291+ super(BaseTestClassWithPatchedHome, self).setUp()
292+ self.launcher, self.test_type = self.get_launcher_method_and_type()
293+ self.home_dir = self._patch_home()
294+ self._create_music_library('mediascanner-2.0')
295+
296+
297+class EmptyLibraryWithPatchedHome(BaseTestClassWithPatchedHome):
298+
299+ """ Base test case class for music-app with empty library. """
300+
301+ def setUp(self):
302+ super(BaseTestClassWithPatchedHome, self).setUp()
303+ self.launcher, self.test_type = self.get_launcher_method_and_type()
304+ self.home_dir = self._patch_home()
305+ self._create_music_library('blank-mediascanner-2.0')
306+
307+
308 class MusicAppTestCase(BaseTestCaseWithPatchedHome):
309
310 """Base test case that launches the music-app."""
311@@ -220,3 +256,13 @@
312 def setUp(self):
313 super(MusicAppTestCase, self).setUp()
314 self.app = MusicApp(self.launcher())
315+
316+
317+class MusicAppTestCaseEmptyLibrary(EmptyLibraryWithPatchedHome):
318+
319+ """Test case that launches the music-app with no music:
320+ an empty library."""
321+
322+ def setUp(self):
323+ super(MusicAppTestCaseEmptyLibrary, self).setUp()
324+ self.app = MusicApp(self.launcher())
325
326=== modified file 'tests/autopilot/music_app/tests/test_music.py'
327--- tests/autopilot/music_app/tests/test_music.py 2015-11-02 05:19:12 +0000
328+++ tests/autopilot/music_app/tests/test_music.py 2016-01-04 23:02:20 +0000
329@@ -14,11 +14,27 @@
330 from testtools.matchers import Equals, GreaterThan, LessThan, NotEquals
331
332
333-from music_app.tests import MusicAppTestCase
334+from music_app.tests import MusicAppTestCase, MusicAppTestCaseEmptyLibrary
335
336 logger = logging.getLogger(__name__)
337
338
339+class TestEmptyLibrary(MusicAppTestCaseEmptyLibrary):
340+
341+ def setUp(self):
342+ super(TestEmptyLibrary, self).setUp()
343+ self.app.get_walkthrough_page().skip()
344+
345+ def test_display_message_when_no_music(self):
346+ """When no music is detected, the app must display a certain Page"""
347+
348+ # obtain the LibraryEmptyState page
349+ library = self.app.get_library_empty_state_page()
350+
351+ # check if the correct page(LibraryEmptyState) is being shown
352+ self.assertThat(library.visible, Eventually(Equals(True)))
353+
354+
355 class TestMainWindow(MusicAppTestCase):
356
357 def setUp(self):

Subscribers

People subscribed via source and target branches