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