3 # OpenChange provisioning
4 # Copyright (C) Jelmer Vernooij <jelmer@openchange.org> 2009
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from openchange.mailbox import NoSuchServer, OpenChangeDB, gen_mailbox_folder_fid
25 class OpenChangeDBTests(unittest.TestCase):
26 """Tests for OpenChangeDB."""
29 if os.path.exists("openchange.ldb"):
30 os.unlink("openchange.ldb")
31 self.db = OpenChangeDB("openchange.ldb")
34 def test_user_exists_no_server(self):
35 self.assertRaises(NoSuchServer, self.db.user_exists, "someserver", "foo")
37 def test_server_lookup_doesnt_exist(self):
38 self.assertRaises(NoSuchServer, self.db.lookup_server,
41 def test_server_lookup(self):
42 self.db.add_server("dc=blaserver", "blaserver", "firstorg", "firstou")
43 self.assertEquals("dc=blaserver", str(self.db.lookup_server("blaserver")['dn']))
45 def test_add_mailbox_user(self):
46 self.db.add_server("cn=myserver", "myserver", "firstorg", "firstou")
47 self.db.add_mailbox_user("cn=firstorg,cn=firstou,cn=myserver", "someuser")
48 self.assertTrue(self.db.user_exists("myserver", "someuser"))
50 def test_msg_globalcount_initial(self):
51 self.db.add_server("dc=myserver", "myserver", "firstorg", "firstou")
52 self.assertEquals(1, self.db.get_message_GlobalCount("myserver"))
54 def test_set_msg_globalcount(self):
55 self.db.add_server("dc=myserver", "myserver", "firstorg", "firstou")
56 self.db.set_message_GlobalCount("myserver", 42)
57 self.assertEquals(42, self.db.get_message_GlobalCount("myserver"))
59 def test_msg_replicaid_initial(self):
60 self.db.add_server("dc=myserver", "myserver", "firstorg", "firstou")
61 self.assertEquals(1, self.db.get_message_ReplicaID("myserver"))
64 class MailboxFIDTests(unittest.TestCase):
66 def test_simple(self):
67 self.assertEquals("0x00000000109282806", gen_mailbox_folder_fid(4242, 534534))