michael@0: #!/usr/bin/env python michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import mozfile michael@0: import os michael@0: import shutil michael@0: import sqlite3 michael@0: import tempfile michael@0: import unittest michael@0: from mozprofile.permissions import Permissions michael@0: michael@0: class PermissionsTest(unittest.TestCase): michael@0: michael@0: locations = """http://mochi.test:8888 primary,privileged michael@0: http://127.0.0.1:80 noxul michael@0: http://127.0.0.1:8888 privileged michael@0: """ michael@0: michael@0: def setUp(self): michael@0: self.profile_dir = tempfile.mkdtemp() michael@0: self.locations_file = mozfile.NamedTemporaryFile() michael@0: self.locations_file.write(self.locations) michael@0: self.locations_file.flush() michael@0: michael@0: def tearDown(self): michael@0: if self.profile_dir: michael@0: shutil.rmtree(self.profile_dir) michael@0: if self.locations_file: michael@0: self.locations_file.close() michael@0: michael@0: def test_schema_version(self): michael@0: perms = Permissions(self.profile_dir, self.locations_file.name) michael@0: perms_db_filename = os.path.join(self.profile_dir, 'permissions.sqlite') michael@0: perms.write_db(self.locations_file) michael@0: michael@0: stmt = 'PRAGMA user_version;' michael@0: michael@0: con = sqlite3.connect(perms_db_filename) michael@0: cur = con.cursor() michael@0: cur.execute(stmt) michael@0: entries = cur.fetchall() michael@0: michael@0: schema_version = entries[0][0] michael@0: self.assertEqual(schema_version, 2) michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()