<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15073] CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15073">15073</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-08-27 12:07:18 -0700 (Thu, 27 Aug 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add missing-location fix option. Add unit tests.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesreleaseCalendarServer54devcalendarservertoolscalverifypy">CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer54devcalendarservertoolstesttest_calverifypy">CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesreleaseCalendarServer54devcalendarservertoolscalverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py (15072 => 15073)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py        2015-08-27 19:06:30 UTC (rev 15072)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/calverify.py        2015-08-27 19:07:18 UTC (rev 15073)
</span><span class="lines">@@ -2701,7 +2701,7 @@
</span><span class="cx"> ot = time.time()
</span><span class="cx">
</span><span class="cx"> # Check loop over uuid
</span><del>- UUIDDetails = collections.namedtuple("UUIDDetails", ("uuid", "rname", "purged",))
</del><ins>+ UUIDDetails = collections.namedtuple("UUIDDetails", ("uuid", "rname", "missing",))
</ins><span class="cx"> self.uuid_details = []
</span><span class="cx"> if len(self.options["uuid"]) != 36:
</span><span class="cx"> self.txn = self.store.newTransaction()
</span><span class="lines">@@ -2768,16 +2768,16 @@
</span><span class="cx"> if rows:
</span><span class="cx"> if not self.options["summary"]:
</span><span class="cx"> self.addSummaryBreak()
</span><del>- purged = yield self.missingLocation(rows, uuid)
</del><ins>+ missing = yield self.missingLocation(rows, uuid, rname)
</ins><span class="cx"> else:
</span><del>- purged = False
</del><ins>+ missing = False
</ins><span class="cx">
</span><del>- self.uuid_details.append(UUIDDetails(uuid, rname, purged))
</del><ins>+ self.uuid_details.append(UUIDDetails(uuid, rname, missing))
</ins><span class="cx">
</span><span class="cx"> if not self.options["summary"]:
</span><span class="cx"> self.printSummary()
</span><span class="cx"> else:
</span><del>- self.output.write(" - %s\n" % ("Bad Events" if purged else "OK",))
</del><ins>+ self.output.write(" - %s\n" % ("Bad Events" if missing else "OK",))
</ins><span class="cx"> self.output.flush()
</span><span class="cx">
</span><span class="cx"> if count == 0:
</span><span class="lines">@@ -2786,7 +2786,7 @@
</span><span class="cx"> if self.options["summary"]:
</span><span class="cx"> table = tables.Table()
</span><span class="cx"> table.addHeader(("GUID", "Name", "RID", "UID",))
</span><del>- purged = 0
</del><ins>+ missing = 0
</ins><span class="cx"> for item in sorted(self.uuid_details):
</span><span class="cx"> if not item.purged:
</span><span class="cx"> continue
</span><span class="lines">@@ -2801,8 +2801,8 @@
</span><span class="cx"> ))
</span><span class="cx"> uuid = ""
</span><span class="cx"> rname = ""
</span><del>- purged += 1
- table.addFooter(("Total", "%d" % (purged,), "", "", "",))
</del><ins>+ missing += 1
+ table.addFooter(("Total", "%d" % (missing,), "", "", "",))
</ins><span class="cx"> self.output.write("\n")
</span><span class="cx"> table.printTable(os=self.output)
</span><span class="cx">
</span><span class="lines">@@ -2811,9 +2811,9 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def missingLocation(self, rows, uuid):
</del><ins>+ def missingLocation(self, rows, uuid, rname):
</ins><span class="cx"> """
</span><del>- Check each calendar resource by looking at any ORGANIER property value and verifying it is valid.
</del><ins>+ Check each calendar resource by looking at any ORGANIZER property value and verifying it is valid.
</ins><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> if not self.options["summary"]:
</span><span class="lines">@@ -2858,10 +2858,7 @@
</span><span class="cx"> if fail:
</span><span class="cx"> details.append(Details(resid, uid,))
</span><span class="cx"> if self.fix:
</span><del>- # Add location value
- # TODO: locate organizer's copy of event
- # Add LOCATION property to components
- # Write it back to trigger scheduling
</del><ins>+ yield self.fixCalendarData(cal, rname)
</ins><span class="cx"> fixed += 1
</span><span class="cx">
</span><span class="cx"> if self.options["verbose"] and not self.options["summary"]:
</span><span class="lines">@@ -2909,7 +2906,54 @@
</span><span class="cx"> returnValue(details)
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def fixCalendarData(self, cal, rname):
+ """
+ Fix problems in calendar data using store APIs.
+ """
</ins><span class="cx">
</span><ins>+ # Extract organizer (strip off urn:uuid:) and UID
+ organizer = cal.getOrganizer()[9:]
+ uid = cal.resourceUID()
+ _ignore_calendar, resid, _ignore_created, _ignore_modified = yield self.getCalendarForOwnerByUID(organizer, uid)
+
+ # Get the organizer's calendar object and data
+ homeID, calendarID = yield self.getAllResourceInfoForResourceID(resid)
+ home = yield self.txn.calendarHomeWithResourceID(homeID)
+ calendar = yield home.childWithID(calendarID)
+ calendarObj = yield calendar.objectResourceWithID(resid)
+
+ try:
+ component = yield calendarObj.componentForUser()
+ except InternalDataStoreError:
+ returnValue((False, "Failed parse: "))
+
+ # Add missing location to all components (need to dup component when modifying)
+ component = component.duplicate()
+ for comp in component.subcomponents():
+ if comp.name() != "VEVENT":
+ continue
+ location = comp.propertyValue("LOCATION")
+ if location is None:
+ comp.addProperty(Property("LOCATION", rname))
+
+ # Write out fix, commit and get a new transaction
+ result = True
+ message = ""
+ try:
+ yield calendarObj.setComponent(component)
+ except Exception, e:
+ print(e, component)
+ print(traceback.print_exc())
+ result = False
+ message = "Exception fix: "
+ yield self.txn.commit()
+ self.txn = self.store.newTransaction()
+
+ returnValue((result, message,))
+
+
+
</ins><span class="cx"> class EventSplitService(CalVerifyService):
</span><span class="cx"> """
</span><span class="cx"> Service which splits a recurring event at a specific date-time value.
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer54devcalendarservertoolstesttest_calverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py (15072 => 15073)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py        2015-08-27 19:06:30 UTC (rev 15072)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py        2015-08-27 19:07:18 UTC (rev 15073)
</span><span class="lines">@@ -21,12 +21,12 @@
</span><span class="cx">
</span><span class="cx"> from calendarserver.tools.calverify import BadDataService, \
</span><span class="cx"> SchedulingMismatchService, DoubleBookingService, DarkPurgeService, \
</span><del>- EventSplitService
</del><ins>+ EventSplitService, MissingLocationService
</ins><span class="cx">
</span><span class="cx"> from pycalendar.datetime import PyCalendarDateTime
</span><span class="cx">
</span><span class="cx"> from twisted.internet import reactor
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><ins>+from twisted.internet.defer import inlineCallbacks, Deferred
</ins><span class="cx">
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.ical import normalize_iCalStr
</span><span class="lines">@@ -513,7 +513,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_old = (yield (yield self.calendarUnderTest()).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": True,
</span><span class="lines">@@ -557,7 +557,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_old = (yield (yield self.calendarUnderTest()).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": True,
</span><span class="lines">@@ -629,7 +629,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_old = (yield (yield self.calendarUnderTest()).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -669,7 +669,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_old = (yield (yield self.calendarUnderTest()).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -1420,7 +1420,7 @@
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_old2 = (yield (yield self.calendarUnderTest(home=self.uuid2, name="calendar")).syncToken())
</span><span class="cx"> sync_token_old3 = (yield (yield self.calendarUnderTest(home=self.uuid3, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -1487,7 +1487,7 @@
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_old2 = (yield (yield self.calendarUnderTest(home=self.uuid2, name="calendar")).syncToken())
</span><span class="cx"> sync_token_old3 = (yield (yield self.calendarUnderTest(home=self.uuid3, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -1578,7 +1578,7 @@
</span><span class="cx"> self.assertNotEqual(sync_token_old3, sync_token_new3)
</span><span class="cx">
</span><span class="cx"> # Re-scan after changes to make sure there are no errors
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx"> options["fix"] = False
</span><span class="cx"> calverify = SchedulingMismatchService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="cx"> yield calverify.doAction()
</span><span class="lines">@@ -1696,7 +1696,7 @@
</span><span class="cx">
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -1747,7 +1747,7 @@
</span><span class="cx">
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -1805,7 +1805,7 @@
</span><span class="cx"> self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
</span><span class="cx">
</span><span class="cx"> # Re-scan after changes to make sure there are no errors
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx"> options["fix"] = False
</span><span class="cx"> calverify = SchedulingMismatchService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="cx"> yield calverify.doAction()
</span><span class="lines">@@ -1923,7 +1923,7 @@
</span><span class="cx">
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -1972,7 +1972,7 @@
</span><span class="cx">
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -2023,7 +2023,7 @@
</span><span class="cx"> self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
</span><span class="cx">
</span><span class="cx"> # Re-scan after changes to make sure there are no errors
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx"> options["fix"] = False
</span><span class="cx"> options["uuid"] = CalVerifyMismatchTestsBase.uuidl1
</span><span class="cx"> calverify = SchedulingMismatchService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="lines">@@ -2432,7 +2432,7 @@
</span><span class="cx">
</span><span class="cx"> sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name="calendar")).syncToken())
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -2594,7 +2594,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -2641,7 +2641,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -2680,7 +2680,7 @@
</span><span class="cx"> self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
</span><span class="cx">
</span><span class="cx"> # Re-scan after changes to make sure there are no errors
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx"> options["fix"] = False
</span><span class="cx"> options["uuid"] = self.uuidl1
</span><span class="cx"> calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="lines">@@ -2700,7 +2700,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -2739,7 +2739,7 @@
</span><span class="cx"> self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
</span><span class="cx">
</span><span class="cx"> # Re-scan after changes to make sure there are no errors
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx"> options["fix"] = False
</span><span class="cx"> options["uuid"] = self.uuidl1
</span><span class="cx"> calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="lines">@@ -2759,7 +2759,7 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx">
</span><span class="cx"> options = {
</span><span class="cx"> "ical": False,
</span><span class="lines">@@ -2798,7 +2798,7 @@
</span><span class="cx"> self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
</span><span class="cx">
</span><span class="cx"> # Re-scan after changes to make sure there are no errors
</span><del>- self.commit()
</del><ins>+ yield self.commit()
</ins><span class="cx"> options["fix"] = False
</span><span class="cx"> options["uuid"] = self.uuidl1
</span><span class="cx"> calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="lines">@@ -3127,3 +3127,218 @@
</span><span class="cx"> self.assertTrue("%(now_fwd10)s" % self.subs in result)
</span><span class="cx"> self.assertTrue("%(now_fwd11)s *" % self.subs in result)
</span><span class="cx"> self.assertTrue("%(now_fwd12)s" % self.subs in result)
</span><ins>+
+
+
+class CalVerifyMissingLocations(CalVerifyMismatchTestsBase):
+ """
+ Tests calverify for events.
+ """
+
+ subs = {
+ "year": nowYear,
+ "month": nowMonth,
+ "uuid1": CalVerifyMismatchTestsBase.uuid1,
+ "uuid2": CalVerifyMismatchTestsBase.uuid2,
+ "uuid3": CalVerifyMismatchTestsBase.uuid3,
+ "uuidl1": CalVerifyMismatchTestsBase.uuidl1,
+ }
+
+ # Valid event
+ VALID_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:VALID_ICS
+TRANSP:OPAQUE
+SUMMARY:VALID_ICS
+DTSTART:%(year)s%(month)02d08T100000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE:urn:uuid:%(uuidl1)s
+LOCATION:Location 1
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n") % subs
+
+ # Invalid event
+ INVALID_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:INVALID_ICS
+TRANSP:OPAQUE
+SUMMARY:INVALID_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE:urn:uuid:%(uuidl1)s
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n") % subs
+
+ allEvents = {
+ "invite1.ics" : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+ "invite2.ics" : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+ }
+
+ requirements = {
+ CalVerifyMismatchTestsBase.uuid1 : {
+ "calendar" : allEvents,
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuid2 : {
+ "calendar" : allEvents,
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuid3 : {
+ "calendar" : {},
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuidl1 : {
+ "calendar" : allEvents,
+ "inbox" : {},
+ },
+ }
+
+ @inlineCallbacks
+ def test_scanMissingLocations(self):
+ """
+ MissingLocationService.doAction without fix for missing locations. Make sure it detects
+ as much as it can. Make sure sync-token is not changed.
+ """
+
+ sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
+ yield self.commit()
+
+ options = {
+ "ical": False,
+ "badcua": False,
+ "mismatch": False,
+ "nobase64": False,
+ "double": False,
+ "dark-purge": False,
+ "missing-location": True,
+ "fix": False,
+ "verbose": False,
+ "details": False,
+ "summary": False,
+ "days": 365,
+ "uid": "",
+ "uuid": self.uuidl1,
+ "tzid": "utc",
+ "start": PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+ "no-organizer": False,
+ "invalid-organizer": False,
+ "disabled-organizer": False,
+ }
+ output = StringIO()
+ calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
+ self.assertEqual(
+ sorted([i.uid for i in calverify.results["Bad Events"]]),
+ ["INVALID_ICS", ]
+ )
+ self.assertEqual(calverify.results["Number of bad events"], 1)
+ self.assertTrue("Fix bad events" not in calverify.results)
+
+ sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
+ self.assertEqual(sync_token_oldl1, sync_token_newl1)
+
+
+ @inlineCallbacks
+ def test_fixMissingLocations(self):
+ """
+ MissingLocationService.doAction with fix for missing locations. Make sure it detects
+ as much as it can. Make sure sync-token is changed.
+ """
+
+ self.patch(config.Scheduling.Options, "AttendeeRefreshBatchDelaySeconds", 0)
+
+ # Make sure location is in each users event
+ for uid in (self.uuid1, self.uuid2, self.uuidl1,):
+ calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name="calendar", name="invite2.ics")
+ caldata = yield calobj.componentForUser()
+ self.assertTrue("LOCATION:" not in str(caldata))
+ yield self.commit()
+
+ sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
+ yield self.commit()
+
+ options = {
+ "ical": False,
+ "badcua": False,
+ "mismatch": False,
+ "nobase64": False,
+ "double": False,
+ "dark-purge": False,
+ "missing-location": True,
+ "fix": True,
+ "verbose": False,
+ "details": False,
+ "summary": False,
+ "days": 365,
+ "uid": "",
+ "uuid": self.uuidl1,
+ "tzid": "utc",
+ "start": PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+ "no-organizer": False,
+ "invalid-organizer": False,
+ "disabled-organizer": False,
+ }
+ output = StringIO()
+ calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
+ self.assertEqual(
+ sorted([i.uid for i in calverify.results["Bad Events"]]),
+ ["INVALID_ICS", ]
+ )
+ self.assertEqual(calverify.results["Number of bad events"], 1)
+ self.assertEqual(calverify.results["Fix bad events"], 1)
+
+ sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name="calendar")).syncToken())
+ self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
+ yield self.commit()
+
+ # Need to wait for organizer inbox item to appear to verify that auto-accept process call has completed
+ cobjs = []
+ while len(cobjs) != 1:
+ d = Deferred()
+ reactor.callLater(1.0, lambda: d.callback(None))
+ yield d
+ calendar = yield self.calendarUnderTest(home=self.uuid1, name="inbox")
+ cobjs = yield calendar.calendarObjects()
+ yield self.commit()
+
+ # Re-scan after changes to make sure there are no errors
+ options["fix"] = False
+ options["uuid"] = self.uuidl1
+ calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
+ self.assertEqual(len(calverify.results["Bad Events"]), 0)
+ self.assertTrue("Fix bad events" not in calverify.results)
+
+ # Make sure location is in each users event
+ for uid in (self.uuid1, self.uuid2, self.uuidl1,):
+ calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name="calendar", name="invite2.ics")
+ caldata = yield calobj.componentForUser()
+ self.assertTrue("LOCATION:" in str(caldata))
+ yield self.commit()
</ins></span></pre>
</div>
</div>
</body>
</html>