1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozprofile/tests/bug785146.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +import mozfile 1.11 +import os 1.12 +import shutil 1.13 +import sqlite3 1.14 +import tempfile 1.15 +import unittest 1.16 +from mozprofile.permissions import Permissions 1.17 + 1.18 +class PermissionsTest(unittest.TestCase): 1.19 + 1.20 + locations = """http://mochi.test:8888 primary,privileged 1.21 +http://127.0.0.1:80 noxul 1.22 +http://127.0.0.1:8888 privileged 1.23 +""" 1.24 + 1.25 + def setUp(self): 1.26 + self.profile_dir = tempfile.mkdtemp() 1.27 + self.locations_file = mozfile.NamedTemporaryFile() 1.28 + self.locations_file.write(self.locations) 1.29 + self.locations_file.flush() 1.30 + 1.31 + def tearDown(self): 1.32 + if self.profile_dir: 1.33 + shutil.rmtree(self.profile_dir) 1.34 + if self.locations_file: 1.35 + self.locations_file.close() 1.36 + 1.37 + def test_schema_version(self): 1.38 + perms = Permissions(self.profile_dir, self.locations_file.name) 1.39 + perms_db_filename = os.path.join(self.profile_dir, 'permissions.sqlite') 1.40 + perms.write_db(self.locations_file) 1.41 + 1.42 + stmt = 'PRAGMA user_version;' 1.43 + 1.44 + con = sqlite3.connect(perms_db_filename) 1.45 + cur = con.cursor() 1.46 + cur.execute(stmt) 1.47 + entries = cur.fetchall() 1.48 + 1.49 + schema_version = entries[0][0] 1.50 + self.assertEqual(schema_version, 2) 1.51 + 1.52 +if __name__ == '__main__': 1.53 + unittest.main()