This file is indexed.

/usr/lib/python2.7/dist-packages/txdav/caldav/datastore/test/common.py is in calendarserver 5.2+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
# -*- test-case-name: txdav.caldav.datastore -*-
##
# Copyright (c) 2010-2014 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##

"""
Tests for common calendar store API functions.
"""

from StringIO import StringIO

from twisted.internet.defer import Deferred, inlineCallbacks, returnValue, \
    maybeDeferred
from twisted.internet.protocol import Protocol
from twisted.python import hashlib

from twext.python.clsprop import classproperty
from twext.python.vcomponent import VComponent
from twext.python.filepath import CachingFilePath as FilePath
from twext.enterprise.ienterprise import AlreadyFinishedError

from txdav.xml.element import WebDAVUnknownElement
from txdav.idav import IPropertyStore, IDataStore
from txdav.base.propertystore.base import PropertyName
from txdav.common.icommondatastore import HomeChildNameAlreadyExistsError, \
    ICommonTransaction, InvalidComponentForStoreError, InvalidUIDError
from txdav.common.icommondatastore import InvalidObjectResourceError
from txdav.common.icommondatastore import NoSuchHomeChildError
from txdav.common.icommondatastore import ObjectResourceNameAlreadyExistsError
from txdav.common.inotifications import INotificationObject
from txdav.common.datastore.test.util import CommonCommonTests
from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE, _BIND_MODE_READ

from txdav.caldav.icalendarstore import (
    ICalendarObject, ICalendarHome,
    ICalendar, ICalendarTransaction,
    ComponentUpdateState)

from twistedcaldav.customxml import InviteNotification, InviteSummary
from txdav.common.datastore.test.util import transactionClean
from txdav.common.icommondatastore import ConcurrentModification
from twistedcaldav.ical import Component
from twistedcaldav.config import config
from calendarserver.push.util import PushPriority


storePath = FilePath(__file__).parent().child("calendar_store")

homeRoot = storePath.child("ho").child("me").child("home1")
cal1Root = homeRoot.child("calendar_1")

homeSplitsRoot = storePath.child("ho").child("me").child("home_splits")
cal1SplitsRoot = homeSplitsRoot.child("calendar_1")
cal2SplitsRoot = homeSplitsRoot.child("calendar_2")

homeNoSplitsRoot = storePath.child("ho").child("me").child("home_no_splits")
cal1NoSplitsRoot = homeNoSplitsRoot.child("calendar_1")

homeDefaultsRoot = storePath.child("ho").child("me").child("home_defaults")
cal1DefaultsRoot = homeDefaultsRoot.child("calendar_1")

calendar1_objectNames = [
    "1.ics",
    "2.ics",
    "3.ics",
    "4.ics",
]

home1_calendarNames = [
    "calendar_1",
    "calendar_2",
    "calendar_empty",
]

OTHER_HOME_UID = "home_splits"

test_event_text = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.1//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:US/Pacific
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
DTSTART:20070311T020000
TZNAME:PDT
TZOFFSETTO:-0700
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
DTSTART:20071104T020000
TZNAME:PST
TZOFFSETTO:-0800
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20100203T013849Z
UID:uid-test
DTEND;TZID=US/Pacific:20100207T173000
TRANSP:OPAQUE
SUMMARY:New Event
DTSTART;TZID=US/Pacific:20100207T170000
DTSTAMP:20100203T013909Z
SEQUENCE:3
X-APPLE-DROPBOX:/calendars/users/wsanchez/dropbox/uid-test.dropbox
BEGIN:VALARM
X-WR-ALARMUID:1377CCC7-F85C-4610-8583-9513D4B364E1
TRIGGER:-PT20M
ATTACH:Basso
ACTION:AUDIO
END:VALARM
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")



test_event_notCalDAV_text = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.1//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
CREATED:20100203T013849Z
UID:test-bad1
DTEND:20100207T173000Z
TRANSP:OPAQUE
SUMMARY:New Event
DTSTART:20100207T170000Z
DTSTAMP:20100203T013909Z
SEQUENCE:3
END:VEVENT
BEGIN:VEVENT
CREATED:20100203T013849Z
UID:test-bad2
DTEND:20100207T173000Z
TRANSP:OPAQUE
SUMMARY:New Event
DTSTART:20100207T170000Z
DTSTAMP:20100203T013909Z
SEQUENCE:3
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")



event1modified_text = test_event_text.replace(
    "\r\nUID:uid-test\r\n",
    "\r\nUID:uid1\r\n"
)


class CaptureProtocol(Protocol):
    """
    A proocol that captures the data delivered to it, and calls back a Deferred
    with that data.

    @ivar deferred: a L{Deferred} which will be called back with all the data
        yet delivered to C{dataReceived} when C{connectionLost} is called.
    """

    def __init__(self):
        self.deferred = Deferred()
        self.io = StringIO()
        self.dataReceived = self.io.write


    def connectionLost(self, reason):
        self.deferred.callback(self.io.getvalue())



class CommonTests(CommonCommonTests):
    """
    Tests for common functionality of interfaces defined in
    L{txdav.caldav.icalendarstore}.
    """

    metadata1 = {
        "accessMode": "PUBLIC",
        "isScheduleObject": True,
        "scheduleTag": "abc",
        "scheduleEtags": (),
        "hasPrivateComment": False,
    }
    metadata2 = {
        "accessMode": "PRIVATE",
        "isScheduleObject": False,
        "scheduleTag": "",
        "scheduleEtags": (),
        "hasPrivateComment": False,
    }
    metadata3 = {
        "accessMode": "PUBLIC",
        "isScheduleObject": None,
        "scheduleTag": "abc",
        "scheduleEtags": (),
        "hasPrivateComment": True,
    }
    metadata4 = {
        "accessMode": "PUBLIC",
        "isScheduleObject": True,
        "scheduleTag": "abc4",
        "scheduleEtags": (),
        "hasPrivateComment": False,
    }
    metadata5 = {
        "accessMode": "PUBLIC",
        "isScheduleObject": True,
        "scheduleTag": "abc5",
        "scheduleEtags": (),
        "hasPrivateComment": False,
    }

    md5Values = (
        hashlib.md5("1234").hexdigest(),
        hashlib.md5("5678").hexdigest(),
        hashlib.md5("9ABC").hexdigest(),
        hashlib.md5("DEFG").hexdigest(),
        hashlib.md5("HIJK").hexdigest(),
    )

    @classproperty(cache=False)
    def requirements(cls): #@NoSelf
        metadata1 = cls.metadata1.copy()
        metadata2 = cls.metadata2.copy()
        metadata3 = cls.metadata3.copy()
        metadata4 = cls.metadata4.copy()
        return {
        "home1": {
            "calendar_1": {
                "1.ics": (cal1Root.child("1.ics").getContent(), metadata1),
                "2.ics": (cal1Root.child("2.ics").getContent(), metadata2),
                "3.ics": (cal1Root.child("3.ics").getContent(), metadata3),
                "4.ics": (cal1Root.child("4.ics").getContent(), metadata4),
            },
            "calendar_2": {},
            "calendar_empty": {},
            "not_a_calendar": None
        },
        "not_a_home": None,
        "home_splits": {
            "calendar_1": {
                "1.ics": (cal1SplitsRoot.child("1.ics").getContent(), metadata1),
                "2.ics": (cal1SplitsRoot.child("2.ics").getContent(), metadata2),
                "3.ics": (cal1SplitsRoot.child("3.ics").getContent(), metadata3),
            },
            "calendar_2": {
                "1.ics": (cal2SplitsRoot.child("1.ics").getContent(), metadata1),
                "2.ics": (cal2SplitsRoot.child("2.ics").getContent(), metadata2),
                "3.ics": (cal2SplitsRoot.child("3.ics").getContent(), metadata3),
                "4.ics": (cal2SplitsRoot.child("4.ics").getContent(), metadata4),
                "5.ics": (cal2SplitsRoot.child("5.ics").getContent(), metadata4),
            },
        },
        "home_no_splits": {
            "calendar_1": {
                "1.ics": (cal1NoSplitsRoot.child("1.ics").getContent(), metadata1),
                "2.ics": (cal1NoSplitsRoot.child("2.ics").getContent(), metadata2),
                "3.ics": (cal1NoSplitsRoot.child("3.ics").getContent(), metadata3),
            },
        },
        "home_splits_shared": {
            "calendar_1": {},
        },
        "home_defaults": {
            "calendar_1": {
                "1.ics": (cal1DefaultsRoot.child("1.ics").getContent(), metadata1),
                "3.ics": (cal1DefaultsRoot.child("3.ics").getContent(), metadata3),
            },
            "inbox" : {},
        },
    }
    md5s = {
        "home1": {
            "calendar_1": {
                "1.ics": md5Values[0],
                "2.ics": md5Values[1],
                "3.ics": md5Values[2],
                "4.ics": md5Values[3],
            },
            "calendar_2": {},
            "calendar_empty": {},
            "not_a_calendar": None
        },
        "not_a_home": None,
        "home_splits": {
            "calendar_1": {
                "1.ics": md5Values[0],
                "2.ics": md5Values[1],
                "3.ics": md5Values[2],
            },
            "calendar_2": {
                "1.ics": md5Values[0],
                "2.ics": md5Values[1],
                "3.ics": md5Values[2],
                "4.ics": md5Values[3],
                "5.ics": md5Values[4],
            },
        },
        "home_no_splits": {
            "calendar_1": {
                "1.ics": md5Values[0],
                "2.ics": md5Values[1],
                "3.ics": md5Values[2],
            },
        },
    }


    def test_calendarStoreProvides(self):
        """
        The calendar store provides L{IDataStore} and its required attributes.
        """
        calendarStore = self.storeUnderTest()
        self.assertProvides(IDataStore, calendarStore)


    def test_transactionProvides(self):
        """
        The transactions generated by the calendar store provide
        L{ICommonStoreTransaction}, L{ICalendarTransaction}, and their
        respectively required attributes.
        """
        txn = self.transactionUnderTest()
        self.assertProvides(ICommonTransaction, txn)
        self.assertProvides(ICalendarTransaction, txn)


    @inlineCallbacks
    def test_homeProvides(self):
        """
        The calendar homes generated by the calendar store provide
        L{ICalendarHome} and its required attributes.
        """
        self.assertProvides(ICalendarHome, (yield self.homeUnderTest()))


    @inlineCallbacks
    def test_calendarProvides(self):
        """
        The calendars generated by the calendar store provide L{ICalendar} and
        its required attributes.
        """
        self.assertProvides(ICalendar, (yield self.calendarUnderTest()))


    @inlineCallbacks
    def test_calendarObjectProvides(self):
        """
        The calendar objects generated by the calendar store provide
        L{ICalendarObject} and its required attributes.
        """
        self.assertProvides(
            ICalendarObject, (yield self.calendarObjectUnderTest())
        )


    @inlineCallbacks
    def notificationUnderTest(self):
        txn = self.transactionUnderTest()
        notifications = yield txn.notificationsWithUID("home1")
        inviteNotification = InviteNotification()
        yield notifications.writeNotificationObject("abc", inviteNotification,
            inviteNotification.toxml())
        notificationObject = yield notifications.notificationObjectWithUID("abc")
        returnValue(notificationObject)


    @inlineCallbacks
    def test_notificationObjectProvides(self):
        """
        The objects retrieved from the notification home (the object returned
        from L{notificationsWithUID}) provide L{INotificationObject}.
        """
        notificationObject = yield self.notificationUnderTest()
        self.assertProvides(INotificationObject, notificationObject)


    @inlineCallbacks
    def test_notificationSyncToken(self):
        """
        L{ICalendar.resourceNamesSinceToken} will return the names of calendar
        objects changed or deleted since
        """
        txn = self.transactionUnderTest()
        coll = yield txn.notificationsWithUID("home1")
        invite1 = InviteNotification()
        yield coll.writeNotificationObject("1", invite1, invite1.toxml())
        st = yield coll.syncToken()
        yield coll.writeNotificationObject("2", invite1, invite1.toxml())
        rev = self.token2revision(st)
        yield coll.removeNotificationObjectWithUID("1")
        st2 = yield coll.syncToken()
        rev2 = self.token2revision(st2)
        changed, deleted = yield coll.resourceNamesSinceToken(rev)
        self.assertEquals(set(changed), set(["2.xml"]))
        self.assertEquals(set(deleted), set(["1.xml"]))
        changed, deleted = yield coll.resourceNamesSinceToken(rev2)
        self.assertEquals(set(changed), set([]))
        self.assertEquals(set(deleted), set([]))


    @inlineCallbacks
    def test_replaceNotification(self):
        """
        L{INotificationCollection.writeNotificationObject} will silently
        overwrite the notification object.
        """
        notifications = yield self.transactionUnderTest().notificationsWithUID(
            "home1"
        )
        inviteNotification = InviteNotification()
        yield notifications.writeNotificationObject("abc", inviteNotification,
            inviteNotification.toxml())
        inviteNotification2 = InviteNotification(InviteSummary("a summary"))
        yield notifications.writeNotificationObject(
            "abc", inviteNotification, inviteNotification2.toxml())
        abc = yield notifications.notificationObjectWithUID("abc")
        self.assertEquals((yield abc.xmldata()), inviteNotification2.toxml())


    @inlineCallbacks
    def test_addRemoveNotification(self):
        """
        L{INotificationCollection.writeNotificationObject} will silently
        overwrite the notification object.
        """
        # Prime the home collection first
        yield self.transactionUnderTest().notificationsWithUID(
            "home1"
        )
        yield self.commit()

        notifications = yield self.transactionUnderTest().notificationsWithUID(
            "home1"
        )
        self.notifierFactory.reset()
        inviteNotification = InviteNotification()
        yield notifications.writeNotificationObject("abc", inviteNotification,
            inviteNotification.toxml())

        # notify is called prior to commit
        self.assertEquals(
            set(self.notifierFactory.history),
            set([
                ("/CalDAV/example.com/home1/", PushPriority.high),
                ("/CalDAV/example.com/home1/notification/", PushPriority.high),
            ])
        )
        yield self.commit()

        notifications = yield self.transactionUnderTest().notificationsWithUID(
            "home1"
        )
        self.notifierFactory.reset()
        yield notifications.removeNotificationObjectWithUID("abc")
        abc = yield notifications.notificationObjectWithUID("abc")
        self.assertEquals(abc, None)

        # notify is called prior to commit
        self.assertEquals(
            set(self.notifierFactory.history),
            set([
                ("/CalDAV/example.com/home1/", PushPriority.high),
                ("/CalDAV/example.com/home1/notification/", PushPriority.high),
            ])
        )
        yield self.commit()


    @inlineCallbacks
    def test_loadAllNotifications(self):
        """
        L{INotificationCollection.writeNotificationObject} will silently
        overwrite the notification object.
        """
        notifications = yield self.transactionUnderTest().notificationsWithUID(
            "home1"
        )
        inviteNotification = InviteNotification()
        yield notifications.writeNotificationObject("abc", inviteNotification,
            inviteNotification.toxml())
        inviteNotification2 = InviteNotification(InviteSummary("a summary"))
        yield notifications.writeNotificationObject(
            "def", inviteNotification, inviteNotification2.toxml())

        yield self.commit()

        notifications = yield self.transactionUnderTest().notificationsWithUID(
            "home1"
        )
        allObjects = yield notifications.notificationObjects()
        self.assertEqual(set([obj.uid() for obj in allObjects]),
                         set(["abc", "def"]))


    @inlineCallbacks
    def test_notificationObjectMetaData(self):
        """
        The objects retrieved from the notification home have various
        methods which return metadata values.
        """
        notification = yield self.notificationUnderTest()
        self.assertIsInstance(notification.md5(), basestring)
        self.assertIsInstance(notification.size(), int)
        self.assertIsInstance(notification.created(), int)
        self.assertIsInstance(notification.modified(), int)


    @inlineCallbacks
    def test_notificationObjectParent(self):
        """
        L{INotificationObject.notificationCollection} returns the
        L{INotificationCollection} that the object was retrieved from.
        """
        txn = self.transactionUnderTest()
        collection = yield txn.notificationsWithUID("home1")
        notification = yield self.notificationUnderTest()
        self.assertIdentical(collection, notification.notificationCollection())


    @inlineCallbacks
    def test_notifierID(self):
        home = yield self.homeUnderTest()
        self.assertEquals(home.notifierID(), ("CalDAV", "home1",))
        calendar = yield home.calendarWithName("calendar_1")
        self.assertEquals(calendar.notifierID(), ("CalDAV", "home1/calendar_1",))


    @inlineCallbacks
    def test_displayNameNone(self):
        """
        L{ICalendarHome.calendarWithName} returns C{None} for calendars which
        do not exist.
        """
        home = (yield self.homeUnderTest())
        calendar = (yield home.calendarWithName("calendar_1"))
        name = (yield calendar.displayName())
        self.assertEquals(name, None)


    @inlineCallbacks
    def test_setDisplayName(self):
        """
        L{ICalendarHome.calendarWithName} returns C{None} for calendars which
        do not exist.
        """
        home = (yield self.homeUnderTest())
        calendar = (yield home.calendarWithName("calendar_1"))

        calendar.setDisplayName(u"quux")
        name = calendar.displayName()
        self.assertEquals(name, u"quux")

        calendar.setDisplayName(None)
        name = calendar.displayName()
        self.assertEquals(name, None)


    @inlineCallbacks
    def test_setDisplayNameBytes(self):
        """
        L{ICalendarHome.calendarWithName} returns C{None} for calendars which
        do not exist.
        """
        home = (yield self.homeUnderTest())
        calendar = (yield home.calendarWithName("calendar_1"))
        self.assertRaises(ValueError, calendar.setDisplayName, "quux")


    @inlineCallbacks
    def test_calendarHomeWithUID_exists(self):
        """
        Finding an existing calendar home by UID results in an object that
        provides L{ICalendarHome} and has a C{uid()} method that returns the
        same value that was passed in.
        """
        calendarHome = (yield self.transactionUnderTest()
                        .calendarHomeWithUID("home1"))
        self.assertEquals(calendarHome.uid(), "home1")
        self.assertProvides(ICalendarHome, calendarHome)


    @inlineCallbacks
    def test_calendarHomeWithUID_absent(self):
        """
        L{ICommonStoreTransaction.calendarHomeWithUID} should return C{None}
        when asked for a non-existent calendar home.
        """
        txn = self.transactionUnderTest()
        self.assertEquals((yield txn.calendarHomeWithUID("xyzzy")), None)


    @inlineCallbacks
    def test_calendarTasks_exists(self):
        """
        L{ICalendarHome.createdHome} creates a calendar only, or a calendar and tasks
        collection only, in addition to inbox.
        """
        self.patch(config, "RestrictCalendarsToOneComponentType", False)
        home1 = yield self.transactionUnderTest().calendarHomeWithUID("home_provision1", create=True)
        for name in ("calendar", "inbox",):
            calendar = yield home1.calendarWithName(name)
            if calendar is None:
                self.fail("calendar %r didn't exist" % (name,))
            self.assertProvides(ICalendar, calendar)
            self.assertEquals(calendar.name(), name)
        for name in ("tasks",):
            calendar = yield home1.calendarWithName(name)
            if calendar is not None:
                self.fail("calendar %r exists" % (name,))

        self.patch(config, "RestrictCalendarsToOneComponentType", True)
        home2 = yield self.transactionUnderTest().calendarHomeWithUID("home_provision2", create=True)
        for name in ("calendar", "tasks", "inbox",):
            calendar = yield home2.calendarWithName(name)
            if calendar is None:
                self.fail("calendar %r didn't exist" % (name,))
            self.assertProvides(ICalendar, calendar)
            self.assertEquals(calendar.name(), name)


    @inlineCallbacks
    def test_calendarWithName_exists(self):
        """
        L{ICalendarHome.calendarWithName} returns an L{ICalendar} provider,
        whose name matches the one passed in.
        """
        home = yield self.homeUnderTest()
        for name in home1_calendarNames:
            calendar = yield home.calendarWithName(name)
            if calendar is None:
                self.fail("calendar %r didn't exist" % (name,))
            self.assertProvides(ICalendar, calendar)
            self.assertEquals(calendar.name(), name)


    @inlineCallbacks
    def test_calendarRename(self):
        """
        L{ICalendar.rename} changes the name of the L{ICalendar}.
        """
        home = yield self.homeUnderTest()
        calendar = yield home.calendarWithName("calendar_1")
        yield calendar.rename("some_other_name")
        @inlineCallbacks
        def positiveAssertions():
            self.assertEquals(calendar.name(), "some_other_name")
            self.assertEquals(
                calendar, (yield home.calendarWithName("some_other_name")))
            self.assertEquals(
                None, (yield home.calendarWithName("calendar_1")))
        yield positiveAssertions()
        yield self.commit()
        home = yield self.homeUnderTest()
        calendar = yield home.calendarWithName("some_other_name")
        yield positiveAssertions()
        # FIXME: revert
        # FIXME: test for multiple renames
        # FIXME: test for conflicting renames (a->b, c->a in the same txn)


    @inlineCallbacks
    def test_calendarWithName_absent(self):
        """
        L{ICalendarHome.calendarWithName} returns C{None} for calendars which
        do not exist.
        """
        home = yield self.homeUnderTest()
        calendar = yield home.calendarWithName("xyzzy")
        self.assertEquals(calendar, None)


    @inlineCallbacks
    def test_createCalendarWithName_absent(self):
        """
        L{ICalendarHome.createCalendarWithName} creates a new L{ICalendar} that
        can be retrieved with L{ICalendarHome.calendarWithName}.
        """
        home = yield self.homeUnderTest()
        name = "new"
        self.assertIdentical((yield home.calendarWithName(name)), None)
        yield home.createCalendarWithName(name)
        self.assertNotIdentical((yield home.calendarWithName(name)), None)
        calendarProperties = (yield home.calendarWithName(name)).properties()
        self.assertEqual(len(calendarProperties), 0)
        # notify is called prior to commit
        self.assertTrue(("/CalDAV/example.com/home1/", PushPriority.high) in self.notifierFactory.history)
        yield self.commit()

        # Make sure it's available in a new transaction; i.e. test the commit.
        home = yield self.homeUnderTest()
        self.assertNotIdentical((yield home.calendarWithName(name)), None)


    @inlineCallbacks
    def test_createCalendarWithName_exists(self):
        """
        L{ICalendarHome.createCalendarWithName} raises
        L{CalendarAlreadyExistsError} when the name conflicts with an already-
        existing
        """
        home = yield self.homeUnderTest()
        for name in home1_calendarNames:
            yield self.failUnlessFailure(
                maybeDeferred(home.createCalendarWithName, name),
                HomeChildNameAlreadyExistsError
            )


    @inlineCallbacks
    def test_removeCalendarWithName_exists(self):
        """
        L{ICalendarHome.removeCalendarWithName} removes a calendar that already
        exists.
        """
        home = yield self.homeUnderTest()

        # FIXME: test transactions
        for name in home1_calendarNames:
            self.assertNotIdentical((yield home.calendarWithName(name)), None)
            yield home.removeCalendarWithName(name)
            self.assertEquals((yield home.calendarWithName(name)), None)

        yield self.commit()

        # Make sure notification fired after commit
        self.assertEquals(
            set(self.notifierFactory.history),
            set([
                ("/CalDAV/example.com/home1/", PushPriority.high),
                ("/CalDAV/example.com/home1/calendar_1/", PushPriority.high),
                ("/CalDAV/example.com/home1/calendar_2/", PushPriority.high),
                ("/CalDAV/example.com/home1/calendar_empty/", PushPriority.high),
            ])
        )


    @inlineCallbacks
    def test_removeCalendarWithName_absent(self):
        """
        Attempt to remove an non-existing calendar should raise.
        """
        home = yield self.homeUnderTest()
        yield self.failUnlessFailure(
            maybeDeferred(home.removeCalendarWithName, "xyzzy"),
            NoSuchHomeChildError
        )


    @inlineCallbacks
    def test_supportedComponentSet(self):
        """
        Attempt to remove an non-existing calendar object should raise.
        """
        calendar = yield self.calendarUnderTest()

        result = yield maybeDeferred(calendar.getSupportedComponents)
        self.assertEquals(result, None)

        yield maybeDeferred(calendar.setSupportedComponents, "VEVENT,VTODO")
        result = yield maybeDeferred(calendar.getSupportedComponents)
        self.assertEquals(result, "VEVENT,VTODO")

        yield maybeDeferred(calendar.setSupportedComponents, None)
        result = yield maybeDeferred(calendar.getSupportedComponents)
        self.assertEquals(result, None)


    @inlineCallbacks
    def test_countComponentTypes(self):
        """
        Test Calendar._countComponentTypes to make sure correct counts are returned.
        """

        tests = (
            ("calendar_1", (("VEVENT", 3),)),
            ("calendar_2", (("VEVENT", 3), ("VTODO", 2))),
        )

        for calname, results in tests:
            testalendar = yield (yield self.transactionUnderTest().calendarHomeWithUID(
                "home_splits")).calendarWithName(calname)
            result = yield maybeDeferred(testalendar._countComponentTypes)
            self.assertEquals(result, results)


    @inlineCallbacks
    def test_calendarObjects(self):
        """
        L{ICalendar.calendarObjects} will enumerate the calendar objects present
        in the filesystem, in name order, but skip those with hidden names.
        """
        calendar1 = yield self.calendarUnderTest()
        calendarObjects = list((yield calendar1.calendarObjects()))

        for calendarObject in calendarObjects:
            self.assertProvides(ICalendarObject, calendarObject)
            self.assertEquals(
                (yield calendar1.calendarObjectWithName(calendarObject.name())),
                calendarObject
            )

        self.assertEquals(
            set(list(o.name() for o in calendarObjects)),
            set(calendar1_objectNames)
        )


    @inlineCallbacks
    def test_calendarObjectsWithRemovedObject(self):
        """
        L{ICalendar.calendarObjects} skips those objects which have been
        removed by L{CalendarObject.remove} in the same
        transaction, even if it has not yet been committed.
        """
        calendar1 = yield self.calendarUnderTest()
        obj1 = yield calendar1.calendarObjectWithName("2.ics")
        yield obj1.remove()
        calendarObjects = list((yield calendar1.calendarObjects()))
        self.assertEquals(set(o.name() for o in calendarObjects),
                          set(calendar1_objectNames) - set(["2.ics"]))


    @inlineCallbacks
    def test_calendarObjectRemoveConcurrent(self):
        """
        If a transaction, C{A}, is examining an L{ICalendarObject} C{O} while
        another transaction, C{B}, deletes O, L{O.component()} should raise
        L{ConcurrentModification}.  (This assumes that we are in the default
        serialization level, C{READ COMMITTED}.  This test might fail if
        something changes that.)
        """
        calendarObject = yield self.calendarObjectUnderTest()
        ctxn = self.concurrentTransaction()
        calendar1prime = yield self.calendarUnderTest(ctxn)
        obj1 = yield calendar1prime.calendarObjectWithName("1.ics")
        yield obj1.remove()
        yield ctxn.commit()
        try:
            retrieval = yield calendarObject.component()
        except ConcurrentModification:
            pass
        else:
            self.fail("ConcurrentModification not raised, %r returned." %
                      (retrieval,))


    @inlineCallbacks
    def test_ownerCalendarHome(self):
        """
        L{ICalendar.ownerCalendarHome} should match the home UID.
        """
        self.assertEquals(
            (yield self.calendarUnderTest()).ownerCalendarHome().uid(),
            (yield self.homeUnderTest()).uid()
        )


    @inlineCallbacks
    def test_calendarObjectWithName_exists(self):
        """
        L{ICalendar.calendarObjectWithName} returns an L{ICalendarObject}
        provider for calendars which already exist.
        """
        calendar1 = yield self.calendarUnderTest()
        for name in calendar1_objectNames:
            calendarObject = yield calendar1.calendarObjectWithName(name)
            self.assertProvides(ICalendarObject, calendarObject)
            self.assertEquals(calendarObject.name(), name)
            # FIXME: add more tests based on CommonTests.requirements


    @inlineCallbacks
    def test_calendarObjectWithName_absent(self):
        """
        L{ICalendar.calendarObjectWithName} returns C{None} for calendars which
        don't exist.
        """
        calendar1 = yield self.calendarUnderTest()
        self.assertEquals((yield calendar1.calendarObjectWithName("xyzzy")), None)


    @inlineCallbacks
    def test_CalendarObjectWithUID_remove_exists(self):
        """
        Remove an existing calendar object.
        """
        calendar = yield self.calendarUnderTest()
        for name in calendar1_objectNames:
            uid = (u'uid' + name.rstrip(".ics"))
            obj1 = (yield calendar.calendarObjectWithUID(uid))
            self.assertNotIdentical(obj1, None)
            yield obj1.remove()
            self.assertEquals(
                (yield calendar.calendarObjectWithUID(uid)),
                None
            )
            self.assertEquals(
                (yield calendar.calendarObjectWithName(name)),
                None
            )

        # notify is called prior to commit
        self.assertEquals(
            set(self.notifierFactory.history),
            set([
                ("/CalDAV/example.com/home1/", PushPriority.high),
                ("/CalDAV/example.com/home1/calendar_1/", PushPriority.high),
            ])
        )
        yield self.commit()


    @inlineCallbacks
    def test_CalendarObject_remove(self):
        """
        Remove an existing calendar object.
        """
        calendar = yield self.calendarUnderTest()
        for name in calendar1_objectNames:
            obj1 = (yield calendar.calendarObjectWithName(name))
            self.assertNotIdentical(obj1, None)
            yield obj1.remove()
            self.assertIdentical(
                (yield calendar.calendarObjectWithName(name)), None
            )


    @inlineCallbacks
    def test_calendarName(self):
        """
        L{Calendar.name} reflects the name of the calendar.
        """
        self.assertEquals((yield self.calendarUnderTest()).name(), "calendar_1")


    @inlineCallbacks
    def test_shareWith(self):
        """
        L{ICalendar.shareWith} will share a calendar with a given home UID.
        """
        cal = yield self.calendarUnderTest()
        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
        newCalName = yield cal.shareWith(other, _BIND_MODE_WRITE)
        self.sharedName = newCalName
        yield self.commit()
        normalCal = yield self.calendarUnderTest()
        otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
        otherCal = yield otherHome.childWithName(newCalName)
        self.assertNotIdentical(otherCal, None)
        self.assertEqual(
            (yield
             (yield otherCal.calendarObjectWithName("1.ics")).component()),
            (yield
             (yield normalCal.calendarObjectWithName("1.ics")).component())
        )


    @inlineCallbacks
    def test_shareAgainChangesMode(self):
        """
        If a calendar is already shared with a given calendar home,
        L{ICalendar.shareWith} will change the sharing mode.
        """
        yield self.test_shareWith()
        # yield self.commit() # txn is none? why?
        cal = yield self.calendarUnderTest()
        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
        newName = yield cal.shareWith(other, _BIND_MODE_READ)
        otherCal = yield other.childWithName(self.sharedName)

        # Name should not change just because we updated the mode.
        self.assertEqual(newName, self.sharedName)
        self.assertNotIdentical(otherCal, None)

        invitedCals = yield cal.sharingInvites()
        self.assertEqual(len(invitedCals), 1)
        self.assertEqual(invitedCals[0].mode(), _BIND_MODE_READ)


    @inlineCallbacks
    def test_unshareWith(self, commit=False):
        """
        L{ICalendar.unshareWith} will remove a previously-shared calendar from
        another user's calendar home.
        """
        yield self.test_shareWith()
        if commit:
            yield self.commit()
        cal = yield self.calendarUnderTest()
        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
        newName = yield cal.unshareWith(other)
        otherCal = yield other.childWithName(newName)
        self.assertIdentical(otherCal, None)
        invitedCals = yield cal.sharingInvites()
        self.assertEqual(len(invitedCals), 0)


    @inlineCallbacks
    def test_unshareSharerSide(self, commit=False):
        """
        Verify the coll.unshare( ) method works when called from the
        sharer's copy
        """
        yield self.test_shareWith()
        if commit:
            yield self.commit()
        cal = yield self.calendarUnderTest()
        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
        otherCal = yield other.childWithName(self.sharedName)
        self.assertNotEqual(otherCal, None)
        yield cal.unshare()
        otherCal = yield other.childWithName(self.sharedName)
        self.assertEqual(otherCal, None)
        invitedCals = yield cal.sharingInvites()
        self.assertEqual(len(invitedCals), 0)


    @inlineCallbacks
    def test_unshareShareeSide(self, commit=False):
        """
        Verify the coll.unshare( ) method works when called from the
        sharee's copy
        """
        yield self.test_shareWith()
        if commit:
            yield self.commit()
        cal = yield self.calendarUnderTest()
        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
        otherCal = yield other.childWithName(self.sharedName)
        self.assertNotEqual(otherCal, None)
        yield otherCal.unshare()
        otherCal = yield other.childWithName(self.sharedName)
        self.assertEqual(otherCal, None)
        invitedCals = yield cal.sharingInvites()
        self.assertEqual(len(invitedCals), 0)


    @inlineCallbacks
    def test_unshareWithInDifferentTransaction(self):
        """
        L{ICalendar.unshareWith} will remove a previously-shared calendar from
        another user's calendar home, assuming the sharing was committed in a
        previous transaction.
        """
        yield self.test_unshareWith(True)


    @inlineCallbacks
    def test_sharingInvites(self):
        """
        L{ICalendar.sharingInvites} returns an iterable of all versions of a shared
        calendar.
        """
        cal = yield self.calendarUnderTest()
        sharedBefore = yield cal.sharingInvites()
        # It's not shared yet; make sure sharingInvites doesn't include owner version.
        self.assertEqual(len(sharedBefore), 0)
        yield self.test_shareWith()
        # FIXME: don't know why this separate transaction is needed; remove it.
        yield self.commit()
        cal = yield self.calendarUnderTest()
        sharedAfter = yield cal.sharingInvites()
        self.assertEqual(len(sharedAfter), 1)
        self.assertEqual(sharedAfter[0].mode(), _BIND_MODE_WRITE)
        self.assertEqual(sharedAfter[0].shareeUID(), OTHER_HOME_UID)


    @inlineCallbacks
    def test_sharedNotifierID(self):
        yield self.test_shareWith()
        yield self.commit()

        home = yield self.homeUnderTest()
        self.assertEquals(home.notifierID(), ("CalDAV", "home1",))
        calendar = yield home.calendarWithName("calendar_1")
        self.assertEquals(calendar.notifierID(), ("CalDAV", "home1/calendar_1",))
        yield self.commit()

        home = yield self.homeUnderTest(name=OTHER_HOME_UID)
        self.assertEquals(home.notifierID(), ("CalDAV", OTHER_HOME_UID,))
        calendar = yield home.calendarWithName(self.sharedName)
        self.assertEquals(calendar.notifierID(), ("CalDAV", "home1/calendar_1",))
        yield self.commit()


    @inlineCallbacks
    def test_hasCalendarResourceUIDSomewhereElse(self):
        """
        L{ICalendarHome.hasCalendarResourceUIDSomewhereElse} will determine if
        a calendar object with a conflicting iCalendar UID is found anywhere
        within the calendar home.
        """
        home = yield self.homeUnderTest()
        object = yield self.calendarObjectUnderTest()
        result = (yield home.hasCalendarResourceUIDSomewhereElse("123", object, "schedule"))
        self.assertFalse(result)

        result = (yield home.hasCalendarResourceUIDSomewhereElse("uid1", object, "schedule"))
        self.assertFalse(result is not None)

        result = (yield home.hasCalendarResourceUIDSomewhereElse("uid2", object, "schedule"))
        self.assertTrue(result is not None)

        # FIXME:  do this without legacy calls
        '''
        from twistedcaldav.sharing import SharedCollectionRecord
        scr = SharedCollectionRecord(
            shareuid="opaque", sharetype="D", summary="ignored",
            hosturl="/.../__uids__/home_splits/calendar_2",
            localname="shared_other_calendar"
        )
        yield home.retrieveOldShares().addOrUpdateRecord(scr)
        # uid 2-5 is the UID of a VTODO in home_splits/calendar_2.
        result = (yield home.hasCalendarResourceUIDSomewhereElse(
            "uid2-5", object, "schedule"
        ))
        self.assertFalse(result is not None)
        '''
        yield None


    @inlineCallbacks
    def test_getCalendarResourcesForUID(self):
        """
        L{ICalendar.calendarObjects} will enumerate the calendar objects present
        in the filesystem, in name order, but skip those with hidden names.
        """
        home = yield self.homeUnderTest()
        calendarObjects = (yield home.getCalendarResourcesForUID("123"))
        self.assertEquals(len(calendarObjects), 0)

        calendarObjects = (yield home.getCalendarResourcesForUID("uid1"))
        self.assertEquals(len(calendarObjects), 1)


    @inlineCallbacks
    def test_calendarObjectName(self):
        """
        L{ICalendarObject.name} reflects the name of the calendar object.
        """
        self.assertEquals(
            (yield self.calendarObjectUnderTest()).name(),
            "1.ics"
        )


    @inlineCallbacks
    def test_calendarObjectMetaData(self):
        """
        The objects retrieved from the calendar have a various methods which
        return metadata values.
        """
        calendar = yield self.calendarObjectUnderTest()
        self.assertIsInstance(calendar.name(), basestring)
        self.assertIsInstance(calendar.uid(), basestring)
        self.assertIsInstance(calendar.accessMode, basestring)
        self.assertIsInstance(calendar.isScheduleObject, bool)
        self.assertIsInstance(calendar.scheduleEtags, tuple)
        self.assertIsInstance(calendar.hasPrivateComment, bool)
        self.assertIsInstance(calendar.md5(), basestring)
        self.assertIsInstance(calendar.size(), int)
        self.assertIsInstance(calendar.created(), int)
        self.assertIsInstance(calendar.modified(), int)

        self.assertEqual(calendar.accessMode,
                         CommonTests.metadata1["accessMode"])
        self.assertEqual(calendar.isScheduleObject,
                         CommonTests.metadata1["isScheduleObject"])
        self.assertEqual(calendar.scheduleEtags,
                         CommonTests.metadata1["scheduleEtags"])
        self.assertEqual(calendar.hasPrivateComment,
                         CommonTests.metadata1["hasPrivateComment"])

        calendar.accessMode = Component.ACCESS_PRIVATE
        calendar.isScheduleObject = True
        calendar.scheduleEtags = ("1234", "5678",)
        calendar.hasPrivateComment = True

        self.assertEqual(calendar.accessMode, Component.ACCESS_PRIVATE)
        self.assertEqual(calendar.isScheduleObject, True)
        self.assertEqual(calendar.scheduleEtags, ("1234", "5678",))
        self.assertEqual(calendar.hasPrivateComment, True)


    @inlineCallbacks
    def test_usedQuotaAdjustment(self):
        """
        Adjust used quota on the calendar home and then verify that it's used.
        """
        home = yield self.homeUnderTest()
        initialQuota = yield home.quotaUsedBytes()
        yield home.adjustQuotaUsedBytes(30)
        yield self.commit()
        home2 = yield self.homeUnderTest()
        afterQuota = yield home2.quotaUsedBytes()
        self.assertEqual(afterQuota - initialQuota, 30)
        yield home2.adjustQuotaUsedBytes(-100000)
        yield self.commit()
        home3 = yield self.homeUnderTest()
        self.assertEqual((yield home3.quotaUsedBytes()), 0)


    @inlineCallbacks
    def test_component(self):
        """
        L{ICalendarObject.component} returns a L{VComponent} describing the
        calendar data underlying that calendar object.
        """
        component = yield (yield self.calendarObjectUnderTest()).component()

        self.failUnless(
            isinstance(component, VComponent),
            component
        )

        self.assertEquals(component.name(), "VCALENDAR")
        self.assertEquals(component.mainType(), "VEVENT")
        self.assertEquals(component.resourceUID(), "uid1")

    perUserComponent = lambda self: VComponent.fromString("""BEGIN:VCALENDAR
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
VERSION:2.0
BEGIN:VEVENT
DTSTART:20110101T120000Z
DTEND:20110101T120100Z
DTSTAMP:20080601T120000Z
UID:event-with-some-per-user-data
ATTENDEE:urn:uuid:home1
ORGANIZER:urn:uuid:home1
END:VEVENT
BEGIN:X-CALENDARSERVER-PERUSER
X-CALENDARSERVER-PERUSER-UID:some-other-user
BEGIN:X-CALENDARSERVER-PERINSTANCE
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:somebody else
TRIGGER:-PT20M
END:VALARM
END:X-CALENDARSERVER-PERINSTANCE
END:X-CALENDARSERVER-PERUSER
BEGIN:X-CALENDARSERVER-PERUSER
X-CALENDARSERVER-PERUSER-UID:home1
BEGIN:X-CALENDARSERVER-PERINSTANCE
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:the owner
TRIGGER:-PT20M
END:VALARM
END:X-CALENDARSERVER-PERINSTANCE
END:X-CALENDARSERVER-PERUSER
END:VCALENDAR
""".replace("\n", "\r\n"))

    asSeenByOwner = lambda self: VComponent.fromString("""BEGIN:VCALENDAR
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
VERSION:2.0
BEGIN:VEVENT
DTSTART:20110101T120000Z
DTEND:20110101T120100Z
DTSTAMP:20080601T120000Z
UID:event-with-some-per-user-data
ATTENDEE:urn:uuid:home1
ORGANIZER:urn:uuid:home1
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:the owner
TRIGGER:-PT20M
END:VALARM
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n"))

    asSeenByOther = lambda self: VComponent.fromString("""BEGIN:VCALENDAR
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
VERSION:2.0
BEGIN:VEVENT
DTSTART:20110101T120000Z
DTEND:20110101T120100Z
DTSTAMP:20080601T120000Z
UID:event-with-some-per-user-data
ATTENDEE:urn:uuid:home1
ORGANIZER:urn:uuid:home1
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:somebody else
TRIGGER:-PT20M
END:VALARM
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n"))


    @inlineCallbacks
    def setUpPerUser(self):
        """
        Set up state for testing of per-user components.
        """
        cal = yield self.calendarUnderTest()
        yield cal._createCalendarObjectWithNameInternal(
            "per-user-stuff.ics",
            self.perUserComponent(),
            internal_state=ComponentUpdateState.RAW)
        returnValue((yield cal.calendarObjectWithName("per-user-stuff.ics")))


    @inlineCallbacks
    def test_filteredComponent(self):
        """
        L{ICalendarObject.filteredComponent} returns a L{VComponent} that has
        filtered per-user data.
        """
        obj = yield self.setUpPerUser()
        temp = yield obj.component()
        obj._component = temp.duplicate()
        otherComp = (yield obj.filteredComponent("some-other-user"))
        self.assertEquals(otherComp, self.asSeenByOther())
        obj._component = temp.duplicate()
        ownerComp = (yield obj.filteredComponent("home1"))
        self.assertEquals(ownerComp, self.asSeenByOwner())


    @inlineCallbacks
    def test_iCalendarText(self):
        """
        L{ICalendarObject.iCalendarText} returns a C{str} describing the same
        data provided by L{ICalendarObject.component}.
        """
        text = yield (yield self.calendarObjectUnderTest())._text()
        self.assertIsInstance(text, str)
        self.failUnless(text.startswith("BEGIN:VCALENDAR\r\n"))
        self.assertIn("\r\nUID:uid1\r\n", text)
        self.failUnless(text.endswith("\r\nEND:VCALENDAR\r\n"))


    @inlineCallbacks
    def test_calendarObjectUID(self):
        """
        L{ICalendarObject.uid} returns a C{str} describing the C{UID} property
        of the calendar object's component.
        """
        self.assertEquals(
            (yield self.calendarObjectUnderTest()).uid(), "uid1"
        )


    def test_organizer(self):
        """
        L{ICalendarObject.organizer} returns a C{str} describing the calendar
        user address of the C{ORGANIZER} property of the calendar object's
        component.
        """
        self.assertEquals(
            (yield self.calendarObjectUnderTest()).organizer(),
            "mailto:wsanchez@example.com"
        )


    @inlineCallbacks
    def test_calendarObjectWithUID_absent(self):
        """
        L{ICalendar.calendarObjectWithUID} returns C{None} for calendars which
        don't exist.
        """
        calendar1 = yield self.calendarUnderTest()
        self.assertEquals((yield calendar1.calendarObjectWithUID("xyzzy")),
                          None)


    @inlineCallbacks
    def test_calendars(self):
        """
        L{ICalendarHome.calendars} returns an iterable of L{ICalendar}
        providers, which are consistent with the results from
        L{ICalendar.calendarWithName}.
        """
        # Add a dot directory to make sure we don't find it
        # self.home1._path.child(".foo").createDirectory()
        home = yield self.homeUnderTest()
        calendars = list((yield home.calendars()))

        for calendar in calendars:
            self.assertProvides(ICalendar, calendar)
            self.assertEquals(calendar,
                              (yield home.calendarWithName(calendar.name())))

        self.assertEquals(
            set(c.name() for c in calendars),
            set(home1_calendarNames)
        )


    @inlineCallbacks
    def test_loadAllCalendars(self):
        """
        L{ICalendarHome.loadCalendars} returns an iterable of L{ICalendar}
        providers, which are consistent with the results from
        L{ICalendar.calendarWithName}.
        """
        # Add a dot directory to make sure we don't find it
        # self.home1._path.child(".foo").createDirectory()
        home = yield self.homeUnderTest()
        calendars = (yield home.loadCalendars())

        for calendar in calendars:
            self.assertProvides(ICalendar, calendar)
            self.assertEquals(calendar,
                              (yield home.calendarWithName(calendar.name())))

        self.assertEquals(
            set(c.name() for c in calendars),
            set(home1_calendarNames)
        )

        for c in calendars:
            self.assertTrue(c.properties() is not None)


    @inlineCallbacks
    def test_calendarsAfterAddCalendar(self):
        """
        L{ICalendarHome.calendars} includes calendars recently added with
        L{ICalendarHome.createCalendarWithName}.
        """
        home = yield self.homeUnderTest()
        allCalendars = yield home.calendars()
        before = set(x.name() for x in allCalendars)
        yield home.createCalendarWithName("new-name")
        allCalendars = yield home.calendars()
        after = set(x.name() for x in allCalendars)
        self.assertEquals(before | set(['new-name']), after)


    @inlineCallbacks
    def test_createCalendarObjectWithName_absent(self):
        """
        L{ICalendar.createCalendarObjectWithName} creates a new
        L{ICalendarObject}.
        """
        calendar1 = yield self.calendarUnderTest()
        name = "test.ics"
        self.assertIdentical(
            (yield calendar1.calendarObjectWithName(name)), None
        )
        component = VComponent.fromString(test_event_text)
        metadata = {
            "accessMode": "PUBLIC",
            "isScheduleObject": True,
            "scheduleTag": "abc",
            "scheduleEtags": (),
            "hasPrivateComment": False,
        }
        yield calendar1._createCalendarObjectWithNameInternal(name, component, internal_state=ComponentUpdateState.RAW, options=metadata)

        calendarObject = yield calendar1.calendarObjectWithName(name)
        self.assertEquals((yield calendarObject.componentForUser()), component)
        self.assertEquals((yield calendarObject.getMetadata()), metadata)

        # notify is called prior to commit
        self.assertEquals(
            set(self.notifierFactory.history),
            set([
                ("/CalDAV/example.com/home1/", PushPriority.high),
                ("/CalDAV/example.com/home1/calendar_1/", PushPriority.high),
            ])
        )
        yield self.commit()


    @inlineCallbacks
    def test_createCalendarObjectWithName_exists(self):
        """
        L{ICalendar.createCalendarObjectWithName} raises
        L{CalendarObjectNameAlreadyExistsError} if a calendar object with the
        given name already exists in that calendar.
        """
        cal = yield self.calendarUnderTest()
        comp = VComponent.fromString(test_event_text)
        yield self.failUnlessFailure(
            maybeDeferred(cal.createCalendarObjectWithName, "1.ics", comp),
            ObjectResourceNameAlreadyExistsError,
        )


    @inlineCallbacks
    def test_createCalendarObjectWithName_invalid(self):
        """
        L{ICalendar.createCalendarObjectWithName} raises
        L{InvalidCalendarComponentError} if presented with invalid iCalendar
        text.
        """
        yield self.failUnlessFailure(
            maybeDeferred((yield self.calendarUnderTest()).createCalendarObjectWithName,
            "new", VComponent.fromString(test_event_notCalDAV_text)),
            InvalidObjectResourceError,
            InvalidComponentForStoreError,
        )


    @inlineCallbacks
    def test_setComponent_invalid(self):
        """
        L{ICalendarObject.setComponent} raises L{InvalidICalendarDataError} if
        presented with invalid iCalendar text.
        """
        calendarObject = yield self.calendarObjectUnderTest()
        yield self.failUnlessFailure(
            maybeDeferred(calendarObject.setComponent,
                          VComponent.fromString(test_event_notCalDAV_text)),
            InvalidObjectResourceError,
            InvalidComponentForStoreError,
        )


    @inlineCallbacks
    def test_setComponent_uidchanged(self):
        """
        L{ICalendarObject.setComponent} raises L{InvalidCalendarComponentError}
        when given a L{VComponent} whose UID does not match its existing UID.
        """
        calendar1 = yield self.calendarUnderTest()
        component = VComponent.fromString(test_event_text)
        calendarObject = yield calendar1.calendarObjectWithName("1.ics")
        yield self.failUnlessFailure(
            maybeDeferred(calendarObject.setComponent, component),
            InvalidObjectResourceError,
            InvalidUIDError,
        )


    @inlineCallbacks
    def test_calendarHomeWithUID_create(self):
        """
        L{ICommonStoreTransaction.calendarHomeWithUID} with C{create=True}
        will create a calendar home that doesn't exist yet.
        """
        txn = self.transactionUnderTest()
        noHomeUID = "xyzzy"
        calendarHome = yield txn.calendarHomeWithUID(
            noHomeUID,
            create=True
        )
        @inlineCallbacks
        def readOtherTxn():
            otherTxn = self.savedStore.newTransaction(self.id() + "other txn")
            self.addCleanup(otherTxn.commit)
            returnValue((yield otherTxn.calendarHomeWithUID(noHomeUID)))
        self.assertProvides(ICalendarHome, calendarHome)
        # Default calendar should be automatically created.
        self.assertProvides(ICalendar,
                            (yield calendarHome.calendarWithName("calendar")))
        # A concurrent transaction shouldn't be able to read it yet:
        self.assertIdentical((yield readOtherTxn()), None)
        yield self.commit()
        # But once it's committed, other transactions should see it.
        self.assertProvides(ICalendarHome, (yield readOtherTxn()))


    @inlineCallbacks
    def test_setComponent(self):
        """
        L{CalendarObject.setComponent} changes the result of
        L{CalendarObject.component} within the same transaction.
        """
        component = VComponent.fromString(event1modified_text)

        calendar1 = yield self.calendarUnderTest()
        calendarObject = yield calendar1.calendarObjectWithName("1.ics")
        oldComponent = yield calendarObject.componentForUser()
        self.assertNotEqual(component, oldComponent)
        yield calendarObject.setComponent(component)
        self.assertEquals((yield calendarObject.componentForUser()), component)

        # Also check a new instance
        calendarObject = yield calendar1.calendarObjectWithName("1.ics")
        self.assertEquals((yield calendarObject.componentForUser()), component)

        # notify is called prior to commit
        self.assertEquals(
            set(self.notifierFactory.history),
            set([
                ("/CalDAV/example.com/home1/", PushPriority.high),
                ("/CalDAV/example.com/home1/calendar_1/", PushPriority.high),
            ])
        )
        yield self.commit()


    def checkPropertiesMethod(self, thunk):
        """
        Verify that the given object has a properties method that returns an
        L{IPropertyStore}.
        """
        properties = thunk.properties()
        self.assertProvides(IPropertyStore, properties)


    @inlineCallbacks
    def test_homeProperties(self):
        """
        L{ICalendarHome.properties} returns a property store.
        """
        self.checkPropertiesMethod((yield self.homeUnderTest()))


    @inlineCallbacks
    def test_calendarProperties(self):
        """
        L{ICalendar.properties} returns a property store.
        """
        self.checkPropertiesMethod((yield self.calendarUnderTest()))


    @inlineCallbacks
    def test_calendarObjectProperties(self):
        """
        L{ICalendarObject.properties} returns a property store.
        """
        self.checkPropertiesMethod((yield self.calendarObjectUnderTest()))


    @inlineCallbacks
    def test_newCalendarObjectProperties(self):
        """
        L{ICalendarObject.properties} returns an empty property store for a
        calendar object which has been created but not committed.
        """
        calendar = yield self.calendarUnderTest()
        yield calendar.createCalendarObjectWithName(
            "test.ics", VComponent.fromString(test_event_text)
        )
        newEvent = yield calendar.calendarObjectWithName("test.ics")
        self.assertEquals(newEvent.properties().items(), [])


    @inlineCallbacks
    def test_setComponentPreservesProperties(self):
        """
        L{ICalendarObject.setComponent} preserves properties.

        (Some implementations must go to extra trouble to provide this
        behavior; for example, file storage must copy extended attributes from
        the existing file to the temporary file replacing it.)
        """
        propertyName = PropertyName("http://example.com/ns", "example")
        propertyContent = WebDAVUnknownElement("sample content")
        propertyContent.name = propertyName.name
        propertyContent.namespace = propertyName.namespace

        calobject = (yield self.calendarObjectUnderTest())
        if calobject._parentCollection.objectResourcesHaveProperties():
            (yield self.calendarObjectUnderTest()).properties()[
                propertyName] = propertyContent
            yield self.commit()
            # Sanity check; are properties even readable in a separate transaction?
            # Should probably be a separate test.
            self.assertEquals(
                (yield self.calendarObjectUnderTest()).properties()[propertyName],
                propertyContent)
            obj = yield self.calendarObjectUnderTest()
            event1_text = yield obj._text()
            event1_text_withDifferentSubject = event1_text.replace(
                "SUMMARY:CalDAV protocol updates",
                "SUMMARY:Changed"
            )
            # Sanity check; make sure the test has the right idea of the subject.
            self.assertNotEquals(event1_text, event1_text_withDifferentSubject)
            newComponent = VComponent.fromString(event1_text_withDifferentSubject)
            yield obj.setComponent(newComponent)

            # Putting everything into a separate transaction to account for any
            # caching that may take place.
            yield self.commit()
            self.assertEquals(
                (yield self.calendarObjectUnderTest()).properties()[propertyName],
                propertyContent
            )


    def token2revision(self, token):
        """
        FIXME: the API names for L{syncToken}() and L{resourceNamesSinceToken}()
        are slightly inaccurate; one doesn't produce input for the other.
        Actually it should be resource names since I{revision} and you need to
        understand the structure of the tokens to extract the revision.  Right
        now that logic lives in the protocol layer, so this testing method
        replicates it.
        """
        _ignore_uuid, rev = token.split("_", 1)
        rev = int(rev)
        return rev


    @inlineCallbacks
    def test_simpleHomeSyncToken(self):
        """
        L{ICalendarHome.resourceNamesSinceToken} will return the names of
        calendar objects created since L{ICalendarHome.syncToken} last returned
        a particular value.
        """
        home = yield self.homeUnderTest()
        cal = yield self.calendarUnderTest()
        st = yield home.syncToken()
        yield cal.createCalendarObjectWithName("new.ics", VComponent.fromString(
                test_event_text
            )
        )

        obj1 = yield cal.calendarObjectWithName("2.ics")
        yield obj1.remove()
        yield home.createCalendarWithName("other-calendar")
        st2 = yield home.syncToken()
        self.failIfEquals(st, st2)

        home = yield self.homeUnderTest()

        changed, deleted = yield home.resourceNamesSinceToken(
            self.token2revision(st), "infinity")

        self.assertEquals(set(changed), set(["calendar_1/",
                                             "calendar_1/new.ics",
                                             "calendar_1/2.ics",
                                             "other-calendar/"]))
        self.assertEquals(set(deleted), set(["calendar_1/2.ics"]))

        changed, deleted = yield home.resourceNamesSinceToken(
            self.token2revision(st2), "infinity")
        self.assertEquals(changed, [])
        self.assertEquals(deleted, [])


    @inlineCallbacks
    def test_collectionSyncToken(self):
        """
        L{ICalendar.resourceNamesSinceToken} will return the names of calendar
        objects changed or deleted since
        """
        cal = yield self.calendarUnderTest()
        st = yield cal.syncToken()
        rev = self.token2revision(st)
        yield cal.createCalendarObjectWithName("new.ics", VComponent.fromString(
                test_event_text
            )
        )
        obj1 = yield cal.calendarObjectWithName("2.ics")
        yield obj1.remove()
        st2 = yield cal.syncToken()
        rev2 = self.token2revision(st2)
        changed, deleted = yield cal.resourceNamesSinceToken(rev)
        self.assertEquals(set(changed), set(["new.ics"]))
        self.assertEquals(set(deleted), set(["2.ics"]))
        changed, deleted = yield cal.resourceNamesSinceToken(rev2)
        self.assertEquals(set(changed), set([]))
        self.assertEquals(set(deleted), set([]))


    @inlineCallbacks
    def test_finishedOnCommit(self):
        """
        Calling L{ITransaction.abort} or L{ITransaction.commit} after
        L{ITransaction.commit} has already been called raises an
        L{AlreadyFinishedError}.
        """
        yield self.calendarObjectUnderTest()
        txn = self.lastTransaction
        yield self.commit()

        yield self.failUnlessFailure(
            maybeDeferred(txn.commit),
            AlreadyFinishedError
        )
        yield self.failUnlessFailure(
            maybeDeferred(txn.abort),
            AlreadyFinishedError
        )


    @inlineCallbacks
    def test_dontLeakCalendars(self):
        """
        Calendars in one user's calendar home should not show up in another
        user's calendar home.
        """
        home2 = yield self.transactionUnderTest().calendarHomeWithUID(
            "home2", create=True)
        self.assertIdentical(
            (yield home2.calendarWithName("calendar_1")), None)


    @inlineCallbacks
    def test_dontLeakObjects(self):
        """
        Calendar objects in one user's calendar should not show up in another
        user's via uid or name queries.
        """
        home1 = yield self.homeUnderTest()
        home2 = yield self.transactionUnderTest().calendarHomeWithUID(
            "home2", create=True)
        calendar1 = yield home1.calendarWithName("calendar_1")
        calendar2 = yield home2.calendarWithName("calendar")
        objects = list(
            (yield (yield home2.calendarWithName("calendar")).calendarObjects()))
        self.assertEquals(objects, [])
        for resourceName in self.requirements['home1']['calendar_1'].keys():
            obj = yield calendar1.calendarObjectWithName(resourceName)
            self.assertIdentical(
                (yield calendar2.calendarObjectWithName(resourceName)), None)
            self.assertIdentical(
                (yield calendar2.calendarObjectWithUID(obj.uid())), None)


    @inlineCallbacks
    def test_withEachCalendarHomeDo(self):
        """
        L{ICalendarStore.withEachCalendarHomeDo} executes its C{action}
        argument repeatedly with all homes that have been created.
        """
        additionalUIDs = set('alpha-uid home2 home3 beta-uid'.split())
        txn = self.transactionUnderTest()
        for name in additionalUIDs:
            yield txn.calendarHomeWithUID(name, create=True)
        yield self.commit()
        store = yield self.storeUnderTest()
        def toEachCalendarHome(txn, eachHome):
            return eachHome.createCalendarWithName("a-new-calendar")
        result = yield store.withEachCalendarHomeDo(toEachCalendarHome)
        self.assertEquals(result, None)
        txn2 = self.transactionUnderTest()
        for uid in additionalUIDs:
            home = yield txn2.calendarHomeWithUID(uid)
            self.assertNotIdentical(
                None, (yield home.calendarWithName("a-new-calendar"))
            )


    @transactionClean
    @inlineCallbacks
    def test_withEachCalendarHomeDont(self):
        """
        When the function passed to L{ICalendarStore.withEachCalendarHomeDo}
        raises an exception, processing is halted and the transaction is
        aborted.  The exception is re-raised.
        """
        # create some calendar homes.
        additionalUIDs = set('home2 home3'.split())
        txn = self.transactionUnderTest()
        for uid in additionalUIDs:
            yield txn.calendarHomeWithUID(uid, create=True)
        yield self.commit()


        # try to create a calendar in all of them, then fail.
        class AnException(Exception):
            pass

        caught = []
        @inlineCallbacks
        def toEachCalendarHome(txn, eachHome):
            caught.append(eachHome.uid())
            yield eachHome.createCalendarWithName("wont-be-created")
            raise AnException()
        store = self.storeUnderTest()
        yield self.failUnlessFailure(
            store.withEachCalendarHomeDo(toEachCalendarHome), AnException
        )
        self.assertEquals(len(caught), 1)
        @inlineCallbacks
        def noNewCalendar(x):
            home = yield txn.calendarHomeWithUID(uid, create=False)
            self.assertIdentical(
                (yield home.calendarWithName("wont-be-created")), None
            )
        txn = self.transactionUnderTest()
        yield noNewCalendar(caught[0])
        yield noNewCalendar('home2')
        yield noNewCalendar('home3')