Providing setters for netbiosname, firstorg and firstou is messy.
[jelmer/openchange.git] / pyopenchange / tests / mapistoredb_test.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 import sys
5
6 sys.path.append("python")
7
8 import os
9 import openchange
10 import openchange.mapistoredb as mapistoredb
11 import openchange.mapistore as mapistore
12 from openchange import mapi
13
14 os.mkdir("/tmp/mapistoredb");
15
16 def newTitle(title, separator):
17     print ""
18     print "%s" % title
19     print separator * len(title)
20
21 newTitle("[Step 1]. Initializing mapistore database", '=')
22 MAPIStoreDB = mapistoredb.mapistoredb("/tmp/mapistoredb")
23
24 newTitle("[Step 2]. Provisioning mapistore database", '=')
25 ret = MAPIStoreDB.provision(netbiosname = "server",
26                             firstorg = "OpenChange Project",
27                             firstou = "OpenChange Development Unit")
28 if (ret == 0):
29     print "\t* Provisioning: SUCCESS"
30 else:
31     print "\t* Provisioning: FAILURE"
32
33 MAPIStoreDB.dump_configuration()
34
35 newTitle("[Step 3]. Testing API parts", '=')
36
37 newTitle("A. Testing NetBIOS name", '-')
38 print "* NetBIOS name: %s" %MAPIStoreDB.netbiosname
39
40 newTitle("B. Testing First OU", '-')
41 print "* FirstOU: %s" %MAPIStoreDB.firstou
42
43 newTitle("C. Testing First Organisation", '-')
44 print "* First Organisation: %s" %MAPIStoreDB.firstorg
45
46
47 newTitle("[Step 4]. Retrieve mapistore URI for fsocpf", '=')
48 newTitle("*fsocpf:", '=')
49 print "\t* Inbox: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_INBOX, "jkerihuel", "fsocpf://")
50 print "\t* Calendar: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_CALENDAR, "jkerihuel", "fsocpf://")
51 print "\t* Outbox: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_OUTBOX, "jkerihuel", "fsocpf://")
52 print "\t* Contacts: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_CONTACTS, "jkerihuel", "fsocpf://")
53
54 newTitle("mstoredb:", '=')
55 print "\t* Mailbox Root: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_ROOT_FOLDER, "jkerihuel", "mstoredb://")
56 print "\t* IPM SUbtree: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_IPM_SUBTREE, "jkerihuel", "mstoredb://")
57 print "\t* Inbox: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_INBOX, "jkerihuel", "mstoredb://")
58
59 newTitle("[Step 5]. Create a new mailbox", '=')
60 uri = MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_ROOT_FOLDER, "jkerihuel", "mstoredb://")
61 ret = MAPIStoreDB.new_mailbox("jkerihuel", uri)
62 print "\t* new_mailbox: ret = %d" % ret
63
64 newTitle("[Step 6]. Get and Set a new allocation range to the mailbox ", '=')
65 (retval,rstart,rend) = MAPIStoreDB.get_new_allocation_range("jkerihuel", 0x1000)
66 if retval == 0:
67     print "\t* range start = 0x%.16x" % rstart
68     print "\t* range end = 0x%.16x" % rend
69 retval = MAPIStoreDB.set_mailbox_allocation_range("jkerihuel", rstart, rend)
70 print "\t* allocation range on mailbox: %d" % retval
71
72
73 newTitle("[Step 7]. Retrieve a new FID", '=')
74 fid = MAPIStoreDB.get_new_fid("jkerihuel")
75 print "\t* FID = 0x%.16x" % fid
76
77 newTitle("[Step 8]. Retrieve a new allocation range", '=')
78 (retval,rstart,rend) = MAPIStoreDB.get_new_allocation_range("jkerihuel", 0x1000)
79 if retval == 0:
80     print "\t* range_start = 0x%.16x" % rstart
81     print "\t* range_end   = 0x%.16x" % rend
82
83 newTitle("[Step 9]. Retrieve a new FID", '=')
84 new_fid = MAPIStoreDB.get_new_fid("jkerihuel")
85 print "\t* FID = 0x%.16x" % new_fid
86