1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/internal/file_store.py Thu Jun 01 23:26:38 2017 +0200
1.3 @@ -0,0 +1,160 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Test file-based storage.
1.8 +
1.9 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from imiptools.dates import get_datetime
1.26 +from imiptools.freebusy.common import *
1.27 +from imiptools.text import FileTable, FileTableDict, FileTableSingle
1.28 +from imiptools.stores.file import Store
1.29 +
1.30 +# Test free/busy collection.
1.31 +
1.32 +fb = FreeBusyCollection(FileTable("testfb.tmp",
1.33 + in_converter=period_from_tuple(FreeBusyPeriod),
1.34 + out_converter=period_to_tuple))
1.35 +fb.clear()
1.36 +
1.37 +start = get_datetime("20170530T210700Z")
1.38 +end = get_datetime("20170530T210900Z")
1.39 +p1 = FreeBusyPeriod(start, end)
1.40 +fb.insert_period(p1)
1.41 +
1.42 +start = get_datetime("20170530T205600Z")
1.43 +end = get_datetime("20170530T205800Z")
1.44 +p2 = FreeBusyPeriod(start, end)
1.45 +fb.insert_period(p2)
1.46 +
1.47 +print list(fb)
1.48 +fb.close()
1.49 +
1.50 +fb = FreeBusyCollection(FileTable("testfb.tmp",
1.51 + in_converter=period_from_tuple(FreeBusyPeriod),
1.52 + out_converter=period_to_tuple))
1.53 +print list(fb)
1.54 +
1.55 +print "----"
1.56 +
1.57 +
1.58 +
1.59 +# Test single value table.
1.60 +
1.61 +values = FileTableSingle("testsv.tmp")
1.62 +values.clear()
1.63 +
1.64 +values.append("Hello")
1.65 +values.insert(0, "world")
1.66 +
1.67 +print list(values)
1.68 +values.close()
1.69 +
1.70 +values = FileTableSingle("testsv.tmp")
1.71 +print list(values)
1.72 +
1.73 +print "----"
1.74 +
1.75 +
1.76 +
1.77 +# Test dictionary table.
1.78 +
1.79 +limits = FileTableDict("testdt.tmp")
1.80 +limits.clear()
1.81 +
1.82 +limits["mailto:paul.boddie@example.com"] = "PT1H"
1.83 +
1.84 +print list(limits)
1.85 +limits.close()
1.86 +
1.87 +limits = FileTableDict("testdt.tmp")
1.88 +print list(limits)
1.89 +
1.90 +print "----"
1.91 +
1.92 +
1.93 +
1.94 +# Test store.
1.95 +
1.96 +s = Store("store.tmp")
1.97 +
1.98 +fb = s.get_freebusy("mailto:paul.boddie@example.com")
1.99 +try:
1.100 + fb.insert_period(p1)
1.101 +except TypeError:
1.102 + print "Free/busy collection not mutable, as expected."
1.103 +
1.104 +fb = s.get_freebusy("mailto:paul.boddie@example.com", mutable=True)
1.105 +fb.insert_period(p1)
1.106 +fb.insert_period(p2)
1.107 +s.set_freebusy("mailto:paul.boddie@example.com", fb)
1.108 +s.set_freebusy("mailto:harvey.horse@example.com", fb)
1.109 +
1.110 +print list(fb)
1.111 +
1.112 +s = Store("store.tmp")
1.113 +
1.114 +fb = s.get_freebusy("mailto:paul.boddie@example.com")
1.115 +print list(fb)
1.116 +fb = s.get_freebusy("mailto:harvey.horse@example.com")
1.117 +print list(fb)
1.118 +
1.119 +
1.120 +
1.121 +# Test store.
1.122 +
1.123 +s = Store("store.tmp")
1.124 +
1.125 +req = s.get_requests("mailto:paul.boddie@example.com")
1.126 +req.clear()
1.127 +
1.128 +req.append(("uid1@example.com", None, None))
1.129 +req.append(("uid2@example.com", None, None))
1.130 +req.append(("uid2@example.com", "20170531T140100Z", None))
1.131 +req.append(("uid2@example.com", "20170531T140900Z", "COUNTER"))
1.132 +s.set_requests("mailto:paul.boddie@example.com", req)
1.133 +s.set_requests("mailto:harvey.horse@example.com", req)
1.134 +
1.135 +print list(req)
1.136 +
1.137 +s = Store("store.tmp")
1.138 +
1.139 +req = s.get_requests("mailto:paul.boddie@example.com")
1.140 +print list(req)
1.141 +req = s.get_requests("mailto:harvey.horse@example.com")
1.142 +print list(req)
1.143 +
1.144 +
1.145 +
1.146 +# Test store.
1.147 +
1.148 +s = Store("store.tmp")
1.149 +
1.150 +fb = s.get_freebusy_for_other("mailto:paul.boddie@example.com", "mailto:harvey.horse@example.com", mutable=True)
1.151 +fb.clear()
1.152 +fb.insert_period(p1)
1.153 +fb.insert_period(p2)
1.154 +s.set_freebusy_for_other("mailto:paul.boddie@example.com", fb, "mailto:harvey.horse@example.com")
1.155 +
1.156 +print list(fb)
1.157 +
1.158 +s = Store("store.tmp")
1.159 +
1.160 +fb = s.get_freebusy_for_other("mailto:paul.boddie@example.com", "mailto:harvey.horse@example.com")
1.161 +print list(fb)
1.162 +
1.163 +# vim: tabstop=4 expandtab shiftwidth=4