server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / python / openchange / tests / test_mailbox.py
1 #!/usr/bin/python
2
3 # OpenChange provisioning
4 # Copyright (C) Jelmer Vernooij <jelmer@openchange.org> 2009
5 #
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.
10 #   
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.
15 #   
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/>.
18 #
19
20 from openchange.mailbox import NoSuchServer, OpenChangeDB, gen_mailbox_folder_fid
21
22 import os
23 import unittest
24
25 class OpenChangeDBTests(unittest.TestCase):
26     """Tests for OpenChangeDB."""
27
28     def setUp(self):
29         if os.path.exists("openchange.ldb"):
30             os.unlink("openchange.ldb")
31         self.db = OpenChangeDB("openchange.ldb") 
32         self.db.setup()
33
34     def test_user_exists_no_server(self):
35         self.assertRaises(NoSuchServer, self.db.user_exists, "someserver", "foo")
36
37     def test_server_lookup_doesnt_exist(self):
38         self.assertRaises(NoSuchServer, self.db.lookup_server, 
39             "nonexistantserver")
40
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']))
44
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"))
49
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"))
53
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"))
58
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"))
62
63
64 class MailboxFIDTests(unittest.TestCase):
65     
66     def test_simple(self):
67         self.assertEquals("0x00000000109282806", gen_mailbox_folder_fid(4242, 534534))
68