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
=== modified file 'AUTHORS'
--- AUTHORS 2015-09-08 08:12:31 +0000
+++ AUTHORS 2016-01-04 23:02:20 +0000
@@ -37,5 +37,6 @@
37Stefano Verzegnassi <stefano92.100@gmail.com>37Stefano Verzegnassi <stefano92.100@gmail.com>
38Ted Gould <ted@gould.cx>38Ted Gould <ted@gould.cx>
39Tim Peeters <tim.peeters@canonical.com>39Tim Peeters <tim.peeters@canonical.com>
40Vamshi Balanaga <vamrocks602@gmail.com>
40Víctor R. Ruiz <victor.ruiz@canonical.com>41Víctor R. Ruiz <victor.ruiz@canonical.com>
41Victor Thompson <victor.thompson@gmail.com>42Victor Thompson <victor.thompson@gmail.com>
4243
=== modified file 'app/ui/LibraryEmptyState.qml'
--- app/ui/LibraryEmptyState.qml 2015-10-28 01:05:33 +0000
+++ app/ui/LibraryEmptyState.qml 2016-01-04 23:02:20 +0000
@@ -22,6 +22,7 @@
2222
23Page {23Page {
24 id: libraryEmptyPage24 id: libraryEmptyPage
25 objectName: "emptyLibrary"
25 anchors {26 anchors {
26 fill: parent27 fill: parent
27 }28 }
@@ -32,6 +33,11 @@
32 locked: true33 locked: true
33 }34 }
3435
36 // Hack for autopilot otherwise LibraryEmptyState appears as Page
37 // due to bug 1341671 it is required that there is a property so that
38 // qml doesn't optimise using the parent type
39 property bool bug1341671workaround: true
40
35 // Overlay to show when no tracks detected on the device41 // Overlay to show when no tracks detected on the device
36 Rectangle {42 Rectangle {
37 id: libraryEmpty43 id: libraryEmpty
@@ -105,6 +111,7 @@
105111
106 Label {112 Label {
107 color: styleMusic.libraryEmpty.labelColor113 color: styleMusic.libraryEmpty.labelColor
114 objectName: "titleText"
108 elide: Text.ElideRight115 elide: Text.ElideRight
109 fontSize: "x-large"116 fontSize: "x-large"
110 horizontalAlignment: Text.AlignLeft117 horizontalAlignment: Text.AlignLeft
@@ -116,6 +123,7 @@
116123
117 Label {124 Label {
118 color: styleMusic.libraryEmpty.labelColor125 color: styleMusic.libraryEmpty.labelColor
126 objectName:"descriptiveText"
119 elide: Text.ElideRight127 elide: Text.ElideRight
120 fontSize: "large"128 fontSize: "large"
121 horizontalAlignment: Text.AlignLeft129 horizontalAlignment: Text.AlignLeft
122130
=== modified file 'debian/changelog'
--- debian/changelog 2015-12-17 20:43:26 +0000
+++ debian/changelog 2016-01-04 23:02:20 +0000
@@ -1,11 +1,14 @@
1music-app (2.3) UNRELEASED; urgency=medium1music-app (2.3) UNRELEASED; urgency=medium
22
3 [ Andrew Hayzen ]3 [ Andrew Hayzen ]
4 * Release 2.2ubuntu2 and start on 2.34 * Release 2.2ubuntu2 and start on 2.3
55
6 [ Ken VanDine ]6 [ Ken VanDine ]
7 * Install the content-hub json file in the correct place for peer registry7 * Install the content-hub json file in the correct place for peer registry
88
9 [ Vamshi Balanaga ]
10 * Add test to make sure that the LibraryEmptyState page is visible when no audio is detected on the device (LP: #1261587).
11
9 [ Girish Rawat ]12 [ Girish Rawat ]
10 * Expanded and updated READMEs13 * Expanded and updated READMEs
1114
1215
=== 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 2016-01-04 23:02:20 +0000
@@ -135,6 +135,16 @@
135 # wait for now playing page to be visible135 # wait for now playing page to be visible
136 self.get_now_playing_page().visible.wait_for(True)136 self.get_now_playing_page().visible.wait_for(True)
137137
138 def get_library_empty_state_page(self):
139 return self.app.wait_select_single(LibraryEmptyState,
140 objectName="emptyLibrary")
141
142
143class LibraryEmptyState(UbuntuUIToolkitCustomProxyObjectBase):
144 """Autopilot helper for LibraryEmptyState"""
145 def __init__(self, *args):
146 super(LibraryEmptyState, self).__init__(*args)
147
138148
139class Page(UbuntuUIToolkitCustomProxyObjectBase):149class Page(UbuntuUIToolkitCustomProxyObjectBase):
140 """Autopilot helper for Pages."""150 """Autopilot helper for Pages."""
@@ -335,8 +345,8 @@
335 @click_object345 @click_object
336 def click_artist(self, i):346 def click_artist(self, i):
337 return self.wait_select_single("Card",347 return self.wait_select_single("Card",
338 objectName="albumsPageGridItem"348 objectName="albumsPageGridItem" +
339 + str(i))349 str(i))
340350
341 def get_artist(self):351 def get_artist(self):
342 return self.wait_select_single("UCLabel",352 return self.wait_select_single("UCLabel",
343353
=== added directory 'tests/autopilot/music_app/content/blank-mediascanner-2.0'
=== added file 'tests/autopilot/music_app/content/blank-mediascanner-2.0/mediastore.db'
344Binary 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 differ354Binary 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
=== 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 2016-01-04 23:02:20 +0000
@@ -0,0 +1,1 @@
1INSERT INTO schemaVersion VALUES(10)
02
=== modified file 'tests/autopilot/music_app/content/mediascanner-2.0/mediastore.db'
1Binary 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 differ3Binary 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
=== 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 2016-01-04 23:02:20 +0000
@@ -27,6 +27,7 @@
27CREATE INDEX media_genre_idx ON media(type, genre) WHERE type = 1;27CREATE INDEX media_genre_idx ON media(type, genre) WHERE type = 1;
28CREATE INDEX media_mtime_idx ON media(type, mtime);28CREATE INDEX media_mtime_idx ON media(type, mtime);
29CREATE TABLE media_attic (29CREATE TABLE media_attic (
30 id INTEGER PRIMARY KEY,
30 filename TEXT UNIQUE NOT NULL,31 filename TEXT UNIQUE NOT NULL,
31 content_type TEXT,32 content_type TEXT,
32 etag TEXT,33 etag TEXT,
@@ -48,7 +49,7 @@
48 type INTEGER -- 0=Audio, 1=Video49 type INTEGER -- 0=Audio, 1=Video
49);50);
50CREATE VIRTUAL TABLE media_fts51CREATE VIRTUAL TABLE media_fts
51USING fts4(content='media', title, artist, album, tokenize=mozporter);52USING fts4(content='media', title, artist, album, tokenize=porter);
52CREATE TABLE 'media_fts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);53CREATE TABLE 'media_fts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
53CREATE TABLE 'media_fts_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));54CREATE TABLE 'media_fts_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
54CREATE TABLE 'media_fts_docsize'(docid INTEGER PRIMARY KEY, size BLOB);55CREATE TABLE 'media_fts_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
5556
=== 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 2016-01-04 23:02:20 +0000
@@ -35,12 +35,9 @@
35logger = logging.getLogger(__name__)35logger = logging.getLogger(__name__)
3636
3737
38class BaseTestCaseWithPatchedHome(AutopilotTestCase):38class BaseTestClassWithPatchedHome(AutopilotTestCase):
39
40 """A common test case class that provides several useful methods for39 """A common test case class that provides several useful methods for
41 music-app tests.40 music-app tests."""
42
43 """
4441
45 working_dir = os.getcwd()42 working_dir = os.getcwd()
46 local_location_dir = os.path.dirname(os.path.dirname(working_dir))43 local_location_dir = os.path.dirname(os.path.dirname(working_dir))
@@ -59,12 +56,6 @@
59 test_type = 'click'56 test_type = 'click'
60 return launch, test_type57 return launch, test_type
6158
62 def setUp(self):
63 super(BaseTestCaseWithPatchedHome, self).setUp()
64 self.launcher, self.test_type = self.get_launcher_method_and_type()
65 self.home_dir = self._patch_home()
66 self._create_music_library()
67
68 @autopilot_logging.log_action(logger.info)59 @autopilot_logging.log_action(logger.info)
69 def launch_test_local(self):60 def launch_test_local(self):
70 return self.launch_test_application(61 return self.launch_test_application(
@@ -90,8 +81,8 @@
90 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)81 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
9182
92 def _copy_xauthority_file(self, directory):83 def _copy_xauthority_file(self, directory):
93 """ Copy .Xauthority file to directory, if it exists in /home84 """ Copy .Xauthority file to directory, if it exists in /home"""
94 """85
95 # If running under xvfb, as jenkins does,86 # If running under xvfb, as jenkins does,
96 # xsession will fail to start without xauthority file87 # xsession will fail to start without xauthority file
97 # Thus if the Xauthority file is in the home directory88 # Thus if the Xauthority file is in the home directory
@@ -107,8 +98,7 @@
107 os.path.join(directory, '.Xauthority'))98 os.path.join(directory, '.Xauthority'))
10899
109 def _patch_home(self):100 def _patch_home(self):
110 """ mock /home for testing purposes to preserve user data101 """ mock /home for testing purposes to preserve user data"""
111 """
112102
113 # if running on non-phablet device,103 # if running on non-phablet device,
114 # run in temp folder to avoid mucking up home104 # run in temp folder to avoid mucking up home
@@ -141,29 +131,47 @@
141 logger.debug("Patched home to fake home directory %s" % temp_dir)131 logger.debug("Patched home to fake home directory %s" % temp_dir)
142 return temp_dir132 return temp_dir
143133
144 def _create_music_library(self):134 def _create_music_library(self, db_dir):
145 logger.debug("Creating music library for %s test" % self.test_type)135 logger.debug("Creating music library for %s test" % self.test_type)
146 logger.debug("Home set to %s" % self.home_dir)136 logger.debug("Home set to %s" % self.home_dir)
147 musicpath = os.path.join(self.home_dir, 'Music')137 musicpath = os.path.join(self.home_dir, 'Music')
148 logger.debug("Music path set to %s" % musicpath)138 logger.debug("Music path set to %s" % musicpath)
149 mediascannerpath = os.path.join(self.home_dir,139 mediascannerpath = os.path.join(self.home_dir,
150 '.cache/mediascanner-2.0')140 '.cache/mediascanner-2.0')
141 logger.debug("Mediascanner path set to %s" % mediascannerpath)
142
151 if not os.path.exists(musicpath):143 if not os.path.exists(musicpath):
152 os.makedirs(musicpath)144 os.makedirs(musicpath)
153 logger.debug("Mediascanner path set to %s" % mediascannerpath)
154145
155 # set content path146 # set content path
156 content_dir = os.path.join(os.path.dirname(music_app.__file__),147 content_dir = os.path.join(os.path.dirname(music_app.__file__),
157 'content')148 'content', db_dir)
158149 songs_dir = os.path.join(content_dir, 'songs')
159 logger.debug("Content dir set to %s" % content_dir)150 logger.debug("Content dir set to %s" % content_dir)
160151
161 # copy content152 # copy content
162 shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)153 if os.path.isdir(songs_dir) and db_dir == 'mediascanner-2.0':
163 shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)154 shutil.copy(os.path.join(songs_dir, '1.ogg'), musicpath)
164 shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath)155 shutil.copy(os.path.join(songs_dir, '2.ogg'), musicpath)
165156 shutil.copy(os.path.join(songs_dir, '3.mp3'), musicpath)
166 logger.debug("Music copied, files " + str(os.listdir(musicpath)))157
158 logger.debug("Music copied, files " + str(os.listdir(musicpath)))
159 # delete content if previously copied
160 elif not os.path.isdir(songs_dir):
161 try:
162 os.remove(os.path.join(musicpath, '1.ogg'))
163 except OSError as e:
164 logger.debug("Error removing" + str(e))
165 try:
166 os.remove(os.path.join(musicpath, '2.ogg'))
167 except OSError as e:
168 logger.debug("Error removing" + str(e))
169 try:
170 os.remove(os.path.join(musicpath, '3.mp3'))
171 except OSError as e:
172 logger.debug("Error removing" + str(e))
173
174 logger.debug("Music deleted, files " + str(os.listdir(musicpath)))
167175
168 if self.test_type is not 'click':176 if self.test_type is not 'click':
169 self._patch_mediascanner_home(content_dir, mediascannerpath)177 self._patch_mediascanner_home(content_dir, mediascannerpath)
@@ -172,8 +180,8 @@
172 # do some inline db patching180 # do some inline db patching
173 # patch mediaindex to proper home181 # patch mediaindex to proper home
174 # these values are dependent upon our sampled db182 # these values are dependent upon our sampled db
175 shutil.copytree(183 shutil.copytree(content_dir, mediascannerpath)
176 os.path.join(content_dir, 'mediascanner-2.0'), mediascannerpath)184
177 logger.debug("Patching fake mediascanner database in %s" %185 logger.debug("Patching fake mediascanner database in %s" %
178 mediascannerpath)186 mediascannerpath)
179 logger.debug(187 logger.debug(
@@ -182,6 +190,7 @@
182190
183 relhome = self.home_dir[1:]191 relhome = self.home_dir[1:]
184 dblocation = "home/phablet"192 dblocation = "home/phablet"
193
185 # patch mediaindex194 # patch mediaindex
186 self._file_find_replace(mediascannerpath +195 self._file_find_replace(mediascannerpath +
187 "/mediastore.sql", dblocation, relhome)196 "/mediastore.sql", dblocation, relhome)
@@ -190,7 +199,12 @@
190 f = open(mediascannerpath + "/mediastore.sql", 'rb')199 f = open(mediascannerpath + "/mediastore.sql", 'rb')
191 sql = f.read().decode("utf-8")200 sql = f.read().decode("utf-8")
192 cur = con.cursor()201 cur = con.cursor()
193 cur.executescript(sql)202 try:
203 cur.executescript(sql)
204 con.commit()
205 except Exception as e:
206 logger.debug("Mediscanner patching failed %s" % e)
207 raise
194 con.close()208 con.close()
195209
196 logger.debug(210 logger.debug(
@@ -213,6 +227,28 @@
213 os.rename(out_filename, in_filename)227 os.rename(out_filename, in_filename)
214228
215229
230class BaseTestCaseWithPatchedHome(BaseTestClassWithPatchedHome):
231
232 """ Base test case class for music-app, with viable audio files loaded."""
233
234 def setUp(self):
235 super(BaseTestClassWithPatchedHome, self).setUp()
236 self.launcher, self.test_type = self.get_launcher_method_and_type()
237 self.home_dir = self._patch_home()
238 self._create_music_library('mediascanner-2.0')
239
240
241class EmptyLibraryWithPatchedHome(BaseTestClassWithPatchedHome):
242
243 """ Base test case class for music-app with empty library. """
244
245 def setUp(self):
246 super(BaseTestClassWithPatchedHome, self).setUp()
247 self.launcher, self.test_type = self.get_launcher_method_and_type()
248 self.home_dir = self._patch_home()
249 self._create_music_library('blank-mediascanner-2.0')
250
251
216class MusicAppTestCase(BaseTestCaseWithPatchedHome):252class MusicAppTestCase(BaseTestCaseWithPatchedHome):
217253
218 """Base test case that launches the music-app."""254 """Base test case that launches the music-app."""
@@ -220,3 +256,13 @@
220 def setUp(self):256 def setUp(self):
221 super(MusicAppTestCase, self).setUp()257 super(MusicAppTestCase, self).setUp()
222 self.app = MusicApp(self.launcher())258 self.app = MusicApp(self.launcher())
259
260
261class MusicAppTestCaseEmptyLibrary(EmptyLibraryWithPatchedHome):
262
263 """Test case that launches the music-app with no music:
264 an empty library."""
265
266 def setUp(self):
267 super(MusicAppTestCaseEmptyLibrary, self).setUp()
268 self.app = MusicApp(self.launcher())
223269
=== 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 2016-01-04 23:02:20 +0000
@@ -14,11 +14,27 @@
14from testtools.matchers import Equals, GreaterThan, LessThan, NotEquals14from testtools.matchers import Equals, GreaterThan, LessThan, NotEquals
1515
1616
17from music_app.tests import MusicAppTestCase17from music_app.tests import MusicAppTestCase, MusicAppTestCaseEmptyLibrary
1818
19logger = logging.getLogger(__name__)19logger = logging.getLogger(__name__)
2020
2121
22class TestEmptyLibrary(MusicAppTestCaseEmptyLibrary):
23
24 def setUp(self):
25 super(TestEmptyLibrary, self).setUp()
26 self.app.get_walkthrough_page().skip()
27
28 def test_display_message_when_no_music(self):
29 """When no music is detected, the app must display a certain Page"""
30
31 # obtain the LibraryEmptyState page
32 library = self.app.get_library_empty_state_page()
33
34 # check if the correct page(LibraryEmptyState) is being shown
35 self.assertThat(library.visible, Eventually(Equals(True)))
36
37
22class TestMainWindow(MusicAppTestCase):38class TestMainWindow(MusicAppTestCase):
2339
24 def setUp(self):40 def setUp(self):

Subscribers

People subscribed via source and target branches