testing/mozbase/mozprofile/tests/bug785146.py

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2e601f9e8cc8
1 #!/usr/bin/env python
2
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 # You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 import mozfile
8 import os
9 import shutil
10 import sqlite3
11 import tempfile
12 import unittest
13 from mozprofile.permissions import Permissions
14
15 class PermissionsTest(unittest.TestCase):
16
17 locations = """http://mochi.test:8888 primary,privileged
18 http://127.0.0.1:80 noxul
19 http://127.0.0.1:8888 privileged
20 """
21
22 def setUp(self):
23 self.profile_dir = tempfile.mkdtemp()
24 self.locations_file = mozfile.NamedTemporaryFile()
25 self.locations_file.write(self.locations)
26 self.locations_file.flush()
27
28 def tearDown(self):
29 if self.profile_dir:
30 shutil.rmtree(self.profile_dir)
31 if self.locations_file:
32 self.locations_file.close()
33
34 def test_schema_version(self):
35 perms = Permissions(self.profile_dir, self.locations_file.name)
36 perms_db_filename = os.path.join(self.profile_dir, 'permissions.sqlite')
37 perms.write_db(self.locations_file)
38
39 stmt = 'PRAGMA user_version;'
40
41 con = sqlite3.connect(perms_db_filename)
42 cur = con.cursor()
43 cur.execute(stmt)
44 entries = cur.fetchall()
45
46 schema_version = entries[0][0]
47 self.assertEqual(schema_version, 2)
48
49 if __name__ == '__main__':
50 unittest.main()

mercurial