imip-agent

Annotated tests/internal/file_store.py

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