<!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(&quot;UUIDDetails&quot;, (&quot;uuid&quot;, &quot;rname&quot;, &quot;purged&quot;,))
</del><ins>+        UUIDDetails = collections.namedtuple(&quot;UUIDDetails&quot;, (&quot;uuid&quot;, &quot;rname&quot;, &quot;missing&quot;,))
</ins><span class="cx">         self.uuid_details = []
</span><span class="cx">         if len(self.options[&quot;uuid&quot;]) != 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[&quot;summary&quot;]:
</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[&quot;summary&quot;]:
</span><span class="cx">                 self.printSummary()
</span><span class="cx">             else:
</span><del>-                self.output.write(&quot; - %s\n&quot; % (&quot;Bad Events&quot; if purged else &quot;OK&quot;,))
</del><ins>+                self.output.write(&quot; - %s\n&quot; % (&quot;Bad Events&quot; if missing else &quot;OK&quot;,))
</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[&quot;summary&quot;]:
</span><span class="cx">             table = tables.Table()
</span><span class="cx">             table.addHeader((&quot;GUID&quot;, &quot;Name&quot;, &quot;RID&quot;, &quot;UID&quot;,))
</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 = &quot;&quot;
</span><span class="cx">                     rname = &quot;&quot;
</span><del>-                    purged += 1
-            table.addFooter((&quot;Total&quot;, &quot;%d&quot; % (purged,), &quot;&quot;, &quot;&quot;, &quot;&quot;,))
</del><ins>+                    missing += 1
+            table.addFooter((&quot;Total&quot;, &quot;%d&quot; % (missing,), &quot;&quot;, &quot;&quot;, &quot;&quot;,))
</ins><span class="cx">             self.output.write(&quot;\n&quot;)
</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">         &quot;&quot;&quot;
</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">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if not self.options[&quot;summary&quot;]:
</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[&quot;verbose&quot;] and not self.options[&quot;summary&quot;]:
</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):
+        &quot;&quot;&quot;
+        Fix problems in calendar data using store APIs.
+        &quot;&quot;&quot;
</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, &quot;Failed parse: &quot;))
+
+        # Add missing location to all components (need to dup component when modifying)
+        component = component.duplicate()
+        for comp in component.subcomponents():
+            if comp.name() != &quot;VEVENT&quot;:
+                continue
+            location = comp.propertyValue(&quot;LOCATION&quot;)
+            if location is None:
+                comp.addProperty(Property(&quot;LOCATION&quot;, rname))
+
+        # Write out fix, commit and get a new transaction
+        result = True
+        message = &quot;&quot;
+        try:
+            yield calendarObj.setComponent(component)
+        except Exception, e:
+            print(e, component)
+            print(traceback.print_exc())
+            result = False
+            message = &quot;Exception fix: &quot;
+        yield self.txn.commit()
+        self.txn = self.store.newTransaction()
+
+        returnValue((result, message,))
+
+
+
</ins><span class="cx"> class EventSplitService(CalVerifyService):
</span><span class="cx">     &quot;&quot;&quot;
</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">         &quot;&quot;&quot;
</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">             &quot;ical&quot;: True,
</span><span class="lines">@@ -557,7 +557,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</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">             &quot;ical&quot;: True,
</span><span class="lines">@@ -629,7 +629,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</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">             &quot;ical&quot;: False,
</span><span class="lines">@@ -669,7 +669,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</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">             &quot;ical&quot;: False,
</span><span class="lines">@@ -1420,7 +1420,7 @@
</span><span class="cx">         sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_old2 = (yield (yield self.calendarUnderTest(home=self.uuid2, name=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_old3 = (yield (yield self.calendarUnderTest(home=self.uuid3, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: False,
</span><span class="lines">@@ -1487,7 +1487,7 @@
</span><span class="cx">         sync_token_old1 = (yield (yield self.calendarUnderTest(home=self.uuid1, name=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_old2 = (yield (yield self.calendarUnderTest(home=self.uuid2, name=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_old3 = (yield (yield self.calendarUnderTest(home=self.uuid3, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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[&quot;fix&quot;] = 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=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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[&quot;fix&quot;] = 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=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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[&quot;fix&quot;] = False
</span><span class="cx">         options[&quot;uuid&quot;] = 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=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: False,
</span><span class="lines">@@ -2594,7 +2594,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: False,
</span><span class="lines">@@ -2641,7 +2641,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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[&quot;fix&quot;] = False
</span><span class="cx">         options[&quot;uuid&quot;] = 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">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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[&quot;fix&quot;] = False
</span><span class="cx">         options[&quot;uuid&quot;] = 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">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><del>-        self.commit()
</del><ins>+        yield self.commit()
</ins><span class="cx"> 
</span><span class="cx">         options = {
</span><span class="cx">             &quot;ical&quot;: 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[&quot;fix&quot;] = False
</span><span class="cx">         options[&quot;uuid&quot;] = 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(&quot;%(now_fwd10)s&quot; % self.subs in result)
</span><span class="cx">         self.assertTrue(&quot;%(now_fwd11)s *&quot; % self.subs in result)
</span><span class="cx">         self.assertTrue(&quot;%(now_fwd12)s&quot; % self.subs in result)
</span><ins>+
+
+
+class CalVerifyMissingLocations(CalVerifyMismatchTestsBase):
+    &quot;&quot;&quot;
+    Tests calverify for events.
+    &quot;&quot;&quot;
+
+    subs = {
+        &quot;year&quot;: nowYear,
+        &quot;month&quot;: nowMonth,
+        &quot;uuid1&quot;: CalVerifyMismatchTestsBase.uuid1,
+        &quot;uuid2&quot;: CalVerifyMismatchTestsBase.uuid2,
+        &quot;uuid3&quot;: CalVerifyMismatchTestsBase.uuid3,
+        &quot;uuidl1&quot;: CalVerifyMismatchTestsBase.uuidl1,
+    }
+
+    # Valid event
+    VALID_ICS = &quot;&quot;&quot;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
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
+    # Invalid event
+    INVALID_ICS = &quot;&quot;&quot;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
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
+    allEvents = {
+        &quot;invite1.ics&quot;      : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+        &quot;invite2.ics&quot;      : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+    }
+
+    requirements = {
+        CalVerifyMismatchTestsBase.uuid1 : {
+            &quot;calendar&quot; : allEvents,
+            &quot;inbox&quot; : {},
+        },
+        CalVerifyMismatchTestsBase.uuid2 : {
+            &quot;calendar&quot; : allEvents,
+            &quot;inbox&quot; : {},
+        },
+        CalVerifyMismatchTestsBase.uuid3 : {
+            &quot;calendar&quot; : {},
+            &quot;inbox&quot; : {},
+        },
+        CalVerifyMismatchTestsBase.uuidl1 : {
+            &quot;calendar&quot; : allEvents,
+            &quot;inbox&quot; : {},
+        },
+    }
+
+    @inlineCallbacks
+    def test_scanMissingLocations(self):
+        &quot;&quot;&quot;
+        MissingLocationService.doAction without fix for missing locations. Make sure it detects
+        as much as it can. Make sure sync-token is not changed.
+        &quot;&quot;&quot;
+
+        sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
+        yield self.commit()
+
+        options = {
+            &quot;ical&quot;: False,
+            &quot;badcua&quot;: False,
+            &quot;mismatch&quot;: False,
+            &quot;nobase64&quot;: False,
+            &quot;double&quot;: False,
+            &quot;dark-purge&quot;: False,
+            &quot;missing-location&quot;: True,
+            &quot;fix&quot;: False,
+            &quot;verbose&quot;: False,
+            &quot;details&quot;: False,
+            &quot;summary&quot;: False,
+            &quot;days&quot;: 365,
+            &quot;uid&quot;: &quot;&quot;,
+            &quot;uuid&quot;: self.uuidl1,
+            &quot;tzid&quot;: &quot;utc&quot;,
+            &quot;start&quot;: PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+            &quot;no-organizer&quot;: False,
+            &quot;invalid-organizer&quot;: False,
+            &quot;disabled-organizer&quot;: False,
+        }
+        output = StringIO()
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
+        yield calverify.doAction()
+
+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]))
+        self.assertEqual(
+            sorted([i.uid for i in calverify.results[&quot;Bad Events&quot;]]),
+            [&quot;INVALID_ICS&quot;, ]
+        )
+        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 1)
+        self.assertTrue(&quot;Fix bad events&quot; not in calverify.results)
+
+        sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
+        self.assertEqual(sync_token_oldl1, sync_token_newl1)
+
+
+    @inlineCallbacks
+    def test_fixMissingLocations(self):
+        &quot;&quot;&quot;
+        MissingLocationService.doAction with fix for missing locations. Make sure it detects
+        as much as it can. Make sure sync-token is changed.
+        &quot;&quot;&quot;
+
+        self.patch(config.Scheduling.Options, &quot;AttendeeRefreshBatchDelaySeconds&quot;, 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=&quot;calendar&quot;, name=&quot;invite2.ics&quot;)
+            caldata = yield calobj.componentForUser()
+            self.assertTrue(&quot;LOCATION:&quot; not in str(caldata))
+        yield self.commit()
+
+        sync_token_oldl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
+        yield self.commit()
+
+        options = {
+            &quot;ical&quot;: False,
+            &quot;badcua&quot;: False,
+            &quot;mismatch&quot;: False,
+            &quot;nobase64&quot;: False,
+            &quot;double&quot;: False,
+            &quot;dark-purge&quot;: False,
+            &quot;missing-location&quot;: True,
+            &quot;fix&quot;: True,
+            &quot;verbose&quot;: False,
+            &quot;details&quot;: False,
+            &quot;summary&quot;: False,
+            &quot;days&quot;: 365,
+            &quot;uid&quot;: &quot;&quot;,
+            &quot;uuid&quot;: self.uuidl1,
+            &quot;tzid&quot;: &quot;utc&quot;,
+            &quot;start&quot;: PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+            &quot;no-organizer&quot;: False,
+            &quot;invalid-organizer&quot;: False,
+            &quot;disabled-organizer&quot;: False,
+        }
+        output = StringIO()
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
+        yield calverify.doAction()
+
+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]))
+        self.assertEqual(
+            sorted([i.uid for i in calverify.results[&quot;Bad Events&quot;]]),
+            [&quot;INVALID_ICS&quot;, ]
+        )
+        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 1)
+        self.assertEqual(calverify.results[&quot;Fix bad events&quot;], 1)
+
+        sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).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=&quot;inbox&quot;)
+            cobjs = yield calendar.calendarObjects()
+            yield self.commit()
+
+        # Re-scan after changes to make sure there are no errors
+        options[&quot;fix&quot;] = False
+        options[&quot;uuid&quot;] = self.uuidl1
+        calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
+        yield calverify.doAction()
+
+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]))
+        self.assertEqual(len(calverify.results[&quot;Bad Events&quot;]), 0)
+        self.assertTrue(&quot;Fix bad events&quot; 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=&quot;calendar&quot;, name=&quot;invite2.ics&quot;)
+            caldata = yield calobj.componentForUser()
+            self.assertTrue(&quot;LOCATION:&quot; in str(caldata))
+        yield self.commit()
</ins></span></pre>
</div>
</div>

</body>
</html>