Merge lp:~sergiusens/music-app/ap_click_mods into lp:music-app/trusty

Proposed by Sergio Schvezov
Status: Rejected
Rejected by: Nicholas Skaggs
Proposed branch: lp:~sergiusens/music-app/ap_click_mods
Merge into: lp:music-app/trusty
Diff against target: 141 lines (+55/-40)
1 file modified
tests/autopilot/music_app/tests/__init__.py (+55/-40)
To merge this branch: bzr merge lp:~sergiusens/music-app/ap_click_mods
Reviewer Review Type Date Requested Status
Music App Developers Pending
Review via email: mp+190714@code.launchpad.net

Commit message

Test cleanup and initial click support

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

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/music_app/tests/__init__.py'
2--- tests/autopilot/music_app/tests/__init__.py 2013-10-09 18:34:16 +0000
3+++ tests/autopilot/music_app/tests/__init__.py 2013-10-11 16:03:49 +0000
4@@ -41,17 +41,28 @@
5 local_location = local_location_dir + "/music-app.qml"
6 installed_location = "/usr/share/music-app/music-app.qml"
7
8+ def setup_environment(self):
9+ if os.path.exists(self.local_location):
10+ launch = self.launch_test_local
11+ test_type = 'deb'
12+ elif os.path.exists(self.installed_location):
13+ launch = self.launch_test_installed
14+ test_type = 'local'
15+ else:
16+ launch = self.launch_test_click
17+ test_type = 'click'
18+ return launch, test_type
19+
20 def setUp(self):
21- self._patch_home()
22+ launch, self.test_type = self.setup_environment()
23+ if self.test_type != 'click':
24+ self._patch_home()
25+ else:
26+ self.home_dir = self._save_home()
27 self._create_music_library()
28 self.pointing_device = Pointer(self.input_device_class.create())
29 super(MusicTestCase, self).setUp()
30- if os.path.exists(self.local_location):
31- self.launch_test_local()
32- elif os.path.exists(self.installed_location):
33- self.launch_test_installed()
34- else:
35- self.launch_test_click()
36+ launch()
37
38 def launch_test_local(self):
39 self.app = self.launch_test_application(
40@@ -73,6 +84,22 @@
41 "com.ubuntu.music",
42 emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
43
44+ def _save_home(self):
45+ logger.debug('Saving HOME')
46+ home_dir = os.environ['HOME']
47+ backup_list = ('Music', '.cache/mediascanner')
48+ backup_path = [os.path.join(home_dir, i) for i in backup_list]
49+ backups = [(i, '%s.bak' % i) for i in backup_path if os.path.exists(i)]
50+ for b in backups:
51+ logger.debug('backing up %s to %s' % b)
52+ try:
53+ shutil.rmtree(b[1])
54+ except:
55+ pass
56+ shutil.move(b[0], b[1])
57+ #self.addCleanup(shutil.move(b[1], b[0]))
58+ return home_dir
59+
60 def _patch_home(self):
61 #make a temp dir
62 temp_dir = tempfile.mkdtemp()
63@@ -96,34 +123,27 @@
64 patcher.start()
65 logger.debug("Patched home to fake home directory " + temp_dir)
66 self.addCleanup(patcher.stop)
67+ return temp_dir
68
69 def _create_music_library(self):
70- #use fake home
71- home = os.environ['HOME']
72- logger.debug("Home set to " + home)
73- musicpath = home + '/Music'
74- logger.debug("Music path set to " + musicpath)
75- mediascannerpath = home + '/.cache/mediascanner'
76+ logger.debug("Home set to %s" % self.home_dir)
77+ musicpath = os.path.join(self.home_dir, 'Music')
78+ logger.debug("Music path set to %s" % musicpath)
79+ mediascannerpath = os.path.join(self.home_dir, '.cache/mediascanner')
80 os.mkdir(musicpath)
81- logger.debug("Mediascanner path set to " + mediascannerpath)
82-
83- #copy over the music and index
84- if os.path.exists(self.local_location):
85- shutil.copy(self.working_dir + '/music_app/content/'
86- + '1.ogg',
87- musicpath)
88- shutil.copy(self.working_dir + '/music_app/content/'
89- + '2.ogg',
90- musicpath)
91- shutil.copytree(self.working_dir +
92- '/music_app/content/mediascanner',
93- mediascannerpath)
94-
95+ logger.debug("Mediascanner path set to %s" % mediascannerpath)
96+
97+ #set content path
98+ if self.test_type == 'local' or self.test_type == 'click':
99+ content_dir = os.path.join(self.working_dir, 'music_app/content/')
100 else:
101- pkg_dir = '/usr/lib/python2.7/dist-packages/music_app/'
102- shutil.copy(pkg_dir + 'content/' + '1.ogg', musicpath)
103- shutil.copy(pkg_dir + 'content/' + '2.ogg', musicpath)
104- shutil.copytree(pkg_dir + 'content/mediascanner', mediascannerpath)
105+ content_dir = '/usr/lib/python2.7/dist-packages/music_app/content/'
106+
107+ #copy content
108+ shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath)
109+ shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath)
110+ shutil.copytree(os.path.join(content_dir, 'mediascanner'),
111+ mediascannerpath)
112
113 logger.debug("Music copied, files " + str(os.listdir(musicpath)))
114 logger.debug(
115@@ -134,7 +154,7 @@
116 #patch mediaindex to proper home
117 #these values are dependent upon our sampled db
118 logger.debug("Patching fake mediascanner database")
119- relhome = home[1:]
120+ relhome = self.home_dir[1:]
121 dblocation = "home/autopilot-music-app"
122 dbfoldername = "ea50858c-4b21-4f87-9005-40aa960a84a3"
123 #patch mediaindex
124@@ -142,14 +162,9 @@
125 "/mediaindex", dblocation, relhome)
126
127 #patch file indexes
128- self._file_find_replace(mediascannerpath + "/" +
129- dbfoldername + "/_0.cfs", dblocation, relhome)
130- self._file_find_replace(mediascannerpath + "/" +
131- dbfoldername + "/_1.cfs", dblocation, relhome)
132- self._file_find_replace(mediascannerpath + "/" +
133- dbfoldername + "/_2.cfs", dblocation, relhome)
134- self._file_find_replace(mediascannerpath + "/" +
135- dbfoldername + "/_3.cfs", dblocation, relhome)
136+ index_template = '%s/%s/_%%s.cfs' % (mediascannerpath, dbfoldername)
137+ for i in range(4):
138+ self._file_find_replace(index_template % i, dblocation, relhome)
139
140 def _file_find_replace(self, in_filename, find, replace):
141 #replace all occurences of string find with string replace

Subscribers

People subscribed via source and target branches

to status/vote changes: