1 #!/usr/bin/env python 2 3 """ 4 Test file-based storage. 5 6 Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 from imiptools.dates import get_datetime 23 from imiptools.freebusy.common import * 24 from imiptools.text import FileTable, FileTableDict, FileTableSingle 25 from imiptools.stores.file import Store 26 27 # Test free/busy collection. 28 29 fb = FreeBusyCollection(FileTable("testfb.tmp", 30 in_converter=period_from_tuple(FreeBusyPeriod), 31 out_converter=period_to_tuple)) 32 fb.clear() 33 34 start = get_datetime("20170530T210700Z") 35 end = get_datetime("20170530T210900Z") 36 p1 = FreeBusyPeriod(start, end) 37 fb.insert_period(p1) 38 39 start = get_datetime("20170530T205600Z") 40 end = get_datetime("20170530T205800Z") 41 p2 = FreeBusyPeriod(start, end) 42 fb.insert_period(p2) 43 44 print list(fb) 45 fb.close() 46 47 fb = FreeBusyCollection(FileTable("testfb.tmp", 48 in_converter=period_from_tuple(FreeBusyPeriod), 49 out_converter=period_to_tuple)) 50 print list(fb) 51 52 print "----" 53 54 55 56 # Test single value table. 57 58 values = FileTableSingle("testsv.tmp") 59 values.clear() 60 61 values.append("Hello") 62 values.insert(0, "world") 63 64 print list(values) 65 values.close() 66 67 values = FileTableSingle("testsv.tmp") 68 print list(values) 69 70 print "----" 71 72 73 74 # Test dictionary table. 75 76 limits = FileTableDict("testdt.tmp") 77 limits.clear() 78 79 limits["mailto:paul.boddie@example.com"] = "PT1H" 80 81 print list(limits) 82 limits.close() 83 84 limits = FileTableDict("testdt.tmp") 85 print list(limits) 86 87 print "----" 88 89 90 91 # Test store. 92 93 s = Store("store.tmp") 94 95 fb = s.get_freebusy("mailto:paul.boddie@example.com") 96 try: 97 fb.insert_period(p1) 98 except TypeError: 99 print "Free/busy collection not mutable, as expected." 100 101 fb = s.get_freebusy("mailto:paul.boddie@example.com", mutable=True) 102 fb.insert_period(p1) 103 fb.insert_period(p2) 104 s.set_freebusy("mailto:paul.boddie@example.com", fb) 105 s.set_freebusy("mailto:harvey.horse@example.com", fb) 106 107 print list(fb) 108 109 s = Store("store.tmp") 110 111 fb = s.get_freebusy("mailto:paul.boddie@example.com") 112 print list(fb) 113 fb = s.get_freebusy("mailto:harvey.horse@example.com") 114 print list(fb) 115 116 117 118 # Test store. 119 120 s = Store("store.tmp") 121 122 req = s.get_requests("mailto:paul.boddie@example.com") 123 req.clear() 124 125 req.append(("uid1@example.com", None, None)) 126 req.append(("uid2@example.com", None, None)) 127 req.append(("uid2@example.com", "20170531T140100Z", None)) 128 req.append(("uid2@example.com", "20170531T140900Z", "COUNTER")) 129 s.set_requests("mailto:paul.boddie@example.com", req) 130 s.set_requests("mailto:harvey.horse@example.com", req) 131 132 print list(req) 133 134 s = Store("store.tmp") 135 136 req = s.get_requests("mailto:paul.boddie@example.com") 137 print list(req) 138 req = s.get_requests("mailto:harvey.horse@example.com") 139 print list(req) 140 141 142 143 # Test store. 144 145 s = Store("store.tmp") 146 147 fb = s.get_freebusy_for_other("mailto:paul.boddie@example.com", "mailto:harvey.horse@example.com", mutable=True) 148 fb.clear() 149 fb.insert_period(p1) 150 fb.insert_period(p2) 151 s.set_freebusy_for_other("mailto:paul.boddie@example.com", fb, "mailto:harvey.horse@example.com") 152 153 print list(fb) 154 155 s = Store("store.tmp") 156 157 fb = s.get_freebusy_for_other("mailto:paul.boddie@example.com", "mailto:harvey.horse@example.com") 158 print list(fb) 159 160 # vim: tabstop=4 expandtab shiftwidth=4