Merge lp:~osomon/webbrowser-app/autopilot-temp-profile into lp:webbrowser-app

Proposed by Olivier Tilloy on 2015-04-27
Status: Merged
Approved by: Olivier Tilloy on 2015-05-06
Approved revision: 984
Merged at revision: 994
Proposed branch: lp:~osomon/webbrowser-app/autopilot-temp-profile
Merge into: lp:webbrowser-app
Diff against target: 114 lines (+32/-16)
3 files modified
tests/autopilot/webbrowser_app/tests/__init__.py (+28/-6)
tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py (+0/-4)
tests/autopilot/webbrowser_app/tests/test_suggestions.py (+4/-6)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/autopilot-temp-profile
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2015-04-27
Ubuntu Phablet Team 2015-04-27 Pending
Review via email: mp+257490@code.launchpad.net

Commit message

Run autopilot tests in a temporary profile directory, to avoid polluting the current user’s profile.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
2--- tests/autopilot/webbrowser_app/tests/__init__.py 2015-03-31 16:13:25 +0000
3+++ tests/autopilot/webbrowser_app/tests/__init__.py 2015-04-27 03:28:30 +0000
4@@ -18,6 +18,7 @@
5
6 import os
7 import shutil
8+import tempfile
9 import urllib.request
10
11 import fixtures
12@@ -46,7 +47,34 @@
13
14 ARGS = ["--new-session"]
15
16+ def create_temporary_profile(self):
17+ # This method is meant to be called exactly once, in setUp().
18+ # Tests that need to pre-populate the profile may call it earlier.
19+ if hasattr(self, '_temp_xdg_dir'):
20+ return
21+ self._temp_xdg_dir = tempfile.mkdtemp()
22+ self.addCleanup(shutil.rmtree, self._temp_xdg_dir)
23+
24+ appname = 'webbrowser-app'
25+
26+ xdg_data = os.path.join(self._temp_xdg_dir, 'data')
27+ self.useFixture(fixtures.EnvironmentVariable(
28+ 'XDG_DATA_HOME',
29+ xdg_data))
30+ self.data_location = os.path.join(xdg_data, appname)
31+ if not os.path.exists(self.data_location):
32+ os.makedirs(self.data_location)
33+
34+ xdg_cache = os.path.join(self._temp_xdg_dir, 'cache')
35+ self.useFixture(fixtures.EnvironmentVariable(
36+ 'XDG_CACHE_HOME',
37+ xdg_cache))
38+ self.cache_location = os.path.join(xdg_cache, appname)
39+ if not os.path.exists(self.cache_location):
40+ os.makedirs(self.cache_location)
41+
42 def setUp(self):
43+ self.create_temporary_profile()
44 self.pointing_device = uitk.get_pointing_device()
45 super(BrowserTestCaseBase, self).setUp()
46 self.app = self.launch_app()
47@@ -78,12 +106,6 @@
48 app_type='qt',
49 emulator_base=browser.Webbrowser)
50
51- def clear_datadir(self):
52- datadir = os.path.join(os.path.expanduser("~"), ".local", "share",
53- "webbrowser-app")
54- shutil.rmtree(datadir, True)
55- os.makedirs(datadir)
56-
57 @property
58 def main_window(self):
59 return self.app.main_window
60
61=== modified file 'tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py'
62--- tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py 2015-03-23 07:49:19 +0000
63+++ tests/autopilot/webbrowser_app/tests/test_addressbar_bookmark.py 2015-04-27 03:28:30 +0000
64@@ -22,10 +22,6 @@
65
66 class TestAddressBarBookmark(StartOpenRemotePageTestCaseBase):
67
68- def setUp(self):
69- self.clear_datadir()
70- super(TestAddressBarBookmark, self).setUp()
71-
72 def test_switching_tabs_updates_bookmark_toggle(self):
73 chrome = self.main_window.chrome
74 address_bar = self.main_window.address_bar
75
76=== modified file 'tests/autopilot/webbrowser_app/tests/test_suggestions.py'
77--- tests/autopilot/webbrowser_app/tests/test_suggestions.py 2015-04-16 18:15:06 +0000
78+++ tests/autopilot/webbrowser_app/tests/test_suggestions.py 2015-04-27 03:28:30 +0000
79@@ -30,14 +30,13 @@
80 """Helper test class that pre-populates history and bookmarks databases."""
81
82 def setUp(self):
83- self.clear_datadir()
84+ self.create_temporary_profile()
85 self.populate_history()
86 self.populate_bookmarks()
87 super(PrepopulatedDatabaseTestCaseBase, self).setUp()
88
89 def populate_history(self):
90- db_path = os.path.join(os.path.expanduser("~"), ".local", "share",
91- "webbrowser-app", "history.sqlite")
92+ db_path = os.path.join(self.data_location, "history.sqlite")
93 connection = sqlite3.connect(db_path)
94 connection.execute("""CREATE TABLE IF NOT EXISTS history
95 (url VARCHAR, domain VARCHAR, title VARCHAR,
96@@ -74,8 +73,7 @@
97 connection.close()
98
99 def populate_bookmarks(self):
100- db_path = os.path.join(os.path.expanduser("~"), ".local", "share",
101- "webbrowser-app", "bookmarks.sqlite")
102+ db_path = os.path.join(self.data_location, "bookmarks.sqlite")
103 connection = sqlite3.connect(db_path)
104 connection.execute("""CREATE TABLE IF NOT EXISTS bookmarks
105 (url VARCHAR, title VARCHAR, icon VARCHAR,
106@@ -115,7 +113,7 @@
107 """Test the address bar suggestions (based on history and bookmarks)."""
108
109 def setUp(self):
110- super().setUp()
111+ super(TestSuggestions, self).setUp()
112 self.address_bar = self.main_window.address_bar
113
114 def assert_suggestions_eventually_shown(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: