本文整理汇总了Python中twistedcaldav.test.util.SimpleStoreRequest类的典型用法代码示例。如果您正苦于以下问题:Python SimpleStoreRequest类的具体用法?Python SimpleStoreRequest怎么用?Python SimpleStoreRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleStoreRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_set_default_vevent_other
def test_set_default_vevent_other(self):
"""
Test that the default URL can be set to another VEVENT calendar
"""
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
# default property is present
default = yield inbox.readProperty(caldavxml.ScheduleDefaultCalendarURL, request)
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar")
# Create a new default calendar
newcalendar = yield request.locateResource("/calendars/users/wsanchez/newcalendar")
yield newcalendar.createCalendarCollection()
yield newcalendar.setSupportedComponents(("VEVENT",))
yield self.commit()
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
yield inbox.writeProperty(caldavxml.ScheduleDefaultCalendarURL(davxml.HRef("/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newcalendar")), request)
default = yield inbox.readProperty(caldavxml.ScheduleDefaultCalendarURL, request)
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newcalendar")
yield self.commit()
开发者ID:eventable,项目名称:CalendarServer,代码行数:26,代码来源:test_resource.py
示例2: test_fail_dot_file_put_in_calendar
def test_fail_dot_file_put_in_calendar(self):
"""
Make (regular) collection in calendar
"""
calendar_uri = "/calendars/users/wsanchez/dot_file_in_calendar/"
principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
request = SimpleStoreRequest(self, "MKCALENDAR", calendar_uri, authPrincipal=principal)
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
stream = self.dataPath.child(
"Holidays").child(
"C318AA54-1ED0-11D9-A5E0-000A958A3252.ics"
).open()
try:
calendar = str(Component.fromStream(stream))
finally:
stream.close()
event_uri = "/".join([calendar_uri, ".event.ics"])
request = SimpleStoreRequest(self, "PUT", event_uri, authPrincipal=principal)
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = MemoryStream(calendar)
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.FORBIDDEN:
self.fail("Incorrect response to dot file PUT: %s" % (response.code,))
开发者ID:nunb,项目名称:calendarserver,代码行数:30,代码来源:test_collectioncontents.py
示例3: _test_file_in_calendar
def _test_file_in_calendar(self, what, *work):
"""
Creates a calendar collection, then PUTs a resource into that collection
with the data from given stream and verifies that the response code from the
PUT request matches the given response_code.
"""
calendar_uri = "/calendars/users/wsanchez/testing_calendar/"
principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
request = SimpleStoreRequest(self, "MKCALENDAR", calendar_uri, authPrincipal=principal)
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
c = 0
for stream, response_code in work:
dst_uri = joinURL(calendar_uri, "dst%d.ics" % (c,))
request = SimpleStoreRequest(self, "PUT", dst_uri, authPrincipal=principal)
request.headers.setHeader("if-none-match", "*")
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = stream
response = yield self.send(request)
response = IResponse(response)
if response.code != response_code:
self.fail("Incorrect response to %s: %s (!= %s)" % (what, response.code, response_code))
c += 1
开发者ID:nunb,项目名称:calendarserver,代码行数:29,代码来源:test_collectioncontents.py
示例4: test_timeoutOnPUT
def test_timeoutOnPUT(self):
"""
PUT gets a 503 on a lock timeout.
"""
# Create a fake lock
txn = self.transactionUnderTest()
yield NamedLock.acquire(txn, "ImplicitUIDLock:%s" % (hashlib.md5("uid1").hexdigest(),))
# PUT fails
principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
request = SimpleStoreRequest(
self,
"PUT",
"/calendars/users/wsanchez/calendar/1.ics",
headers=Headers({"content-type": MimeType.fromString("text/calendar")}),
authPrincipal=principal
)
request.stream = MemoryStream("""BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Apple Computer\, Inc//iCal 2.0//EN
VERSION:2.0
BEGIN:VEVENT
UID:uid1
DTSTART;VALUE=DATE:20020101
DTEND;VALUE=DATE:20020102
DTSTAMP:20020101T121212Z
SUMMARY:New Year's Day
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n"))
response = yield self.send(request)
self.assertEqual(response.code, responsecode.SERVICE_UNAVAILABLE)
开发者ID:eventable,项目名称:CalendarServer,代码行数:33,代码来源:test_wrapping.py
示例5: mkcalendar_cb
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
def put_cb(response):
response = IResponse(response)
if response.code != responsecode.FORBIDDEN:
self.fail("Incorrect response to dot file PUT: %s" % (response.code,))
stream = self.dataPath.child(
"Holidays").child(
"C318AA54-1ED0-11D9-A5E0-000A958A3252.ics"
).open()
try:
calendar = str(Component.fromStream(stream))
finally:
stream.close()
event_uri = "/".join([calendar_uri, ".event.ics"])
request = SimpleStoreRequest(self, "PUT", event_uri, authid="wsanchez")
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = MemoryStream(calendar)
return self.send(request, put_cb)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:test_collectioncontents.py
示例6: addEventsDir
def addEventsDir(testCase, eventsDir, uri):
"""
Add events to a L{twistedcaldav.test.util.TestCase} from a directory.
@param testCase: The test case to add events to.
@type testCase: L{twistedcaldav.test.util.TestCase}
@param eventsDir: A directory full of events.
@type eventsDir: L{FilePath}
@param uri: The URI-path of the calendar to insert events into.
@type uri: C{str}
@return: a L{Deferred} which fires with the number of added calendar object
resources.
"""
count = 0
for child in eventsDir.children():
count += 1
if child.basename().split(".")[-1] != "ics":
continue
request = SimpleStoreRequest(testCase, "PUT", uri + "/" + child.basename())
request.stream = MemoryStream(child.getContent())
yield testCase.send(request)
returnValue(count)
开发者ID:nunb,项目名称:calendarserver,代码行数:25,代码来源:test_calendarquery.py
示例7: test_wikiACL
def test_wikiACL(self):
"""
Ensure shareeAccessControlList( ) honors the access granted by the wiki
to the sharee, so that delegates of the sharee get the same level of
access.
"""
sharedName = yield self.wikiSetup()
access = WikiAccessLevel.read
def stubAccessForRecord(*args):
return succeed(access)
self.patch(WikiDirectoryRecord, "accessForRecord", stubAccessForRecord)
request = SimpleStoreRequest(self, "GET", "/calendars/__uids__/user01/")
collection = yield request.locateResource("/calendars/__uids__/user01/" + sharedName)
# Simulate the wiki server granting Read access
acl = (yield collection.shareeAccessControlList(request))
self.assertFalse("<write/>" in acl.toxml())
# Simulate the wiki server granting Read-Write access
access = WikiAccessLevel.write
acl = (yield collection.shareeAccessControlList(request))
self.assertTrue("<write/>" in acl.toxml())
开发者ID:nunb,项目名称:calendarserver,代码行数:25,代码来源:test_sharing.py
示例8: test_pick_default_vtodo_calendar
def test_pick_default_vtodo_calendar(self):
"""
Test that pickNewDefaultCalendar will choose the correct tasks calendar.
"""
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
default = yield inbox.readProperty(customxml.ScheduleDefaultTasksURL, request)
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/tasks")
yield self.abort()
开发者ID:eventable,项目名称:CalendarServer,代码行数:12,代码来源:test_resource.py
示例9: test_pick_default_vevent_calendar
def test_pick_default_vevent_calendar(self):
"""
Test that pickNewDefaultCalendar will choose the correct calendar.
"""
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
# default property initially present
prop = yield inbox.readProperty(caldavxml.ScheduleDefaultCalendarURL, request)
self.assertEqual(str(prop.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar")
yield self.abort()
开发者ID:eventable,项目名称:CalendarServer,代码行数:13,代码来源:test_resource.py
示例10: calendar_query
def calendar_query(self, query, got_xml):
request = SimpleStoreRequest(self, "REPORT", "/calendars/users/wsanchez/calendar/", authid="wsanchez")
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:14,代码来源:test_calendarquery.py
示例11: test_is_default_calendar
def test_is_default_calendar(self):
"""
Test .isDefaultCalendar() returns the proper class or None.
"""
# Create a new non-default calendar
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
newcalendar = yield request.locateResource("/calendars/users/wsanchez/newcalendar")
yield newcalendar.createCalendarCollection()
yield newcalendar.setSupportedComponents(("VEVENT",))
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
yield inbox.defaultCalendar(request, "VEVENT")
yield inbox.defaultCalendar(request, "VTODO")
yield self.commit()
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
calendar = yield request.locateResource("/calendars/users/wsanchez/calendar")
newcalendar = yield request.locateResource("/calendars/users/wsanchez/newcalendar")
tasks = yield request.locateResource("/calendars/users/wsanchez/tasks")
result = yield calendar.isDefaultCalendar(request)
self.assertTrue(result)
result = yield newcalendar.isDefaultCalendar(request)
self.assertFalse(result)
result = yield tasks.isDefaultCalendar(request)
self.assertTrue(result)
yield self.commit()
开发者ID:eventable,项目名称:CalendarServer,代码行数:31,代码来源:test_resource.py
示例12: requestForPath
def requestForPath(self, path, method='GET'):
"""
Get a L{Request} with a L{FakeChanRequest} for a given path and method.
"""
headers = Headers()
headers.addRawHeader("Host", "localhost:8008")
req = SimpleStoreRequest(self, method, path, headers)
# 'process()' normally sets these. Shame on web2, having so much
# partially-initialized stuff floating around.
req.remoteAddr = '127.0.0.1'
req.chanRequest = FakeChanRequest()
req.credentialFactories = {}
return req
开发者ID:anemitz,项目名称:calendarserver,代码行数:14,代码来源:test_wrapping.py
示例13: calendar_query
def calendar_query(self, query, got_xml, expected_code=responsecode.MULTI_STATUS):
principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
request = SimpleStoreRequest(self, "REPORT", "/calendars/users/wsanchez/calendar/", authPrincipal=principal)
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != expected_code:
self.fail("REPORT failed: %s" % (response.code,))
if got_xml is not None:
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
else:
returnValue(
(yield allDataFromStream(response.stream))
)
开发者ID:eventable,项目名称:CalendarServer,代码行数:20,代码来源:test_calendarquery.py
示例14: calendar_query
def calendar_query(self, calendar_uri, query, got_xml, data, no_init):
if not no_init:
response = yield self.send(SimpleStoreRequest(self, "MKCALENDAR", calendar_uri, authid="wsanchez"))
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
if data:
for filename, icaldata in data.iteritems():
request = SimpleStoreRequest(self, "PUT", joinURL(calendar_uri, filename + ".ics"), authid="wsanchez")
request.stream = MemoryStream(icaldata)
yield self.send(request)
else:
# Add holiday events to calendar
for child in FilePath(self.holidays_dir).children():
if os.path.splitext(child.basename())[1] != ".ics":
continue
request = SimpleStoreRequest(self, "PUT", joinURL(calendar_uri, child.basename()), authid="wsanchez")
request.stream = MemoryStream(child.getContent())
yield self.send(request)
request = SimpleStoreRequest(self, "REPORT", calendar_uri, authid="wsanchez")
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:anemitz,项目名称:calendarserver,代码行数:34,代码来源:test_multiget.py
示例15: test_pick_default_other
def test_pick_default_other(self):
"""
Make calendar
"""
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
# default property present
default = yield inbox.readProperty(caldavxml.ScheduleDefaultCalendarURL, request)
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar")
# Create a new default calendar
newcalendar = yield request.locateResource("/calendars/users/wsanchez/newcalendar")
yield newcalendar.createCalendarCollection()
yield inbox.writeProperty(caldavxml.ScheduleDefaultCalendarURL(davxml.HRef("/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newcalendar")), request)
# Delete the normal calendar
calendar = yield request.locateResource("/calendars/users/wsanchez/calendar")
yield calendar.storeRemove(request)
yield self.commit()
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
default = yield inbox.readProperty(caldavxml.ScheduleDefaultCalendarURL, request)
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newcalendar")
yield self.abort()
开发者ID:eventable,项目名称:CalendarServer,代码行数:29,代码来源:test_resource.py
示例16: addressbook_query
def addressbook_query(self, addressbook_uri, query, got_xml):
''' FIXME: clear address book, possibly by removing
mkcol = """<?xml version="1.0" encoding="utf-8" ?>
<D:mkcol xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
<D:set>
<D:prop>
<D:resourcetype><D:collection/><C:addressbook/></D:resourcetype>
</D:prop>
</D:set>
</D:mkcol>
"""
response = yield self.send(SimpleStoreRequest(self, "MKCOL", addressbook_uri, content=mkcol, authid="wsanchez"))
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCOL failed: %s" % (response.code,))
'''
principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
# Add vCards to addressbook
for child in FilePath(self.vcards_dir).children():
if os.path.splitext(child.basename())[1] != ".vcf":
continue
request = SimpleStoreRequest(
self, "PUT", joinURL(addressbook_uri, child.basename()), authPrincipal=principal
)
request.stream = MemoryStream(child.getContent())
yield self.send(request)
request = SimpleStoreRequest(self, "REPORT", addressbook_uri, authPrincipal=principal)
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue((yield davXMLFromStream(response.stream).addCallback(got_xml)))
开发者ID:eventable,项目名称:CalendarServer,代码行数:39,代码来源:test_addressbookquery.py
示例17: addressbook_query
def addressbook_query(self, addressbook_uri, query, got_xml, data, no_init):
if not no_init:
''' FIXME: clear address book, possibly by removing
mkcol = """<?xml version="1.0" encoding="utf-8" ?>
<D:mkcol xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
<D:set>
<D:prop>
<D:resourcetype><D:collection/><C:addressbook/></D:resourcetype>
</D:prop>
</D:set>
</D:mkcol>
"""
response = yield self.send(SimpleStoreRequest(self, "MKCOL", addressbook_uri, content=mkcol, authPrincipal=self.authPrincipal))
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCOL failed: %s" % (response.code,))
'''
if data:
for filename, icaldata in data.iteritems():
request = SimpleStoreRequest(
self,
"PUT",
joinURL(addressbook_uri, filename + ".vcf"),
headers=Headers({"content-type": MimeType.fromString("text/vcard")}),
authPrincipal=self.authPrincipal
)
request.stream = MemoryStream(icaldata)
yield self.send(request)
else:
# Add vcards to addressbook
for child in FilePath(self.vcards_dir).children():
if os.path.splitext(child.basename())[1] != ".vcf":
continue
request = SimpleStoreRequest(
self,
"PUT",
joinURL(addressbook_uri, child.basename()),
headers=Headers({"content-type": MimeType.fromString("text/vcard")}),
authPrincipal=self.authPrincipal
)
request.stream = MemoryStream(child.getContent())
yield self.send(request)
request = SimpleStoreRequest(self, "REPORT", addressbook_uri, authPrincipal=self.authPrincipal)
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:nunb,项目名称:calendarserver,代码行数:58,代码来源:test_addressbookmultiget.py
示例18: test_missing_default_vtodo_calendar
def test_missing_default_vtodo_calendar(self):
"""
Test that readProperty will not create a missing default calendar.
"""
request = SimpleStoreRequest(self, "GET", "/calendars/users/wsanchez/")
home = yield request.locateResource("/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
# default property present
default = yield inbox.readProperty(customxml.ScheduleDefaultTasksURL, request)
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/tasks")
# Forcibly remove the one we need
yield home._newStoreHome.removeChildWithName("tasks")
names = [calendarName for calendarName in (yield home._newStoreHome.listCalendars())]
self.assertTrue("tasks" not in names)
# Property is empty now
default = yield inbox.readProperty(customxml.ScheduleDefaultTasksURL, request)
self.assertEqual(len(default.children), 0)
yield self.abort()
开发者ID:eventable,项目名称:CalendarServer,代码行数:23,代码来源:test_resource.py
示例19: test_wikiACL
def test_wikiACL(self):
"""
Ensure shareeAccessControlList( ) honors the access granted by the wiki
to the sharee, so that delegates of the sharee get the same level of
access.
"""
access = "read"
def stubWikiAccessMethod(userID, wikiID):
return access
self.patch(sharing, "getWikiAccess", stubWikiAccessMethod)
sharedName = yield self.wikiSetup()
request = SimpleStoreRequest(self, "GET", "/calendars/__uids__/user01/")
collection = yield request.locateResource("/calendars/__uids__/user01/" + sharedName)
# Simulate the wiki server granting Read access
acl = (yield collection.shareeAccessControlList(request))
self.assertFalse("<write/>" in acl.toxml())
# Simulate the wiki server granting Read-Write access
access = "write"
acl = (yield collection.shareeAccessControlList(request))
self.assertTrue("<write/>" in acl.toxml())
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:24,代码来源:test_sharing.py
示例20: test_pick_default_addressbook
def test_pick_default_addressbook(self):
"""
Get adbk
"""
request = SimpleStoreRequest(self, "GET", "/addressbooks/users/wsanchez/", authPrincipal=self.authPrincipal)
home = yield request.locateResource("/addressbooks/users/wsanchez")
# default property initially not present
try:
home.readDeadProperty(carddavxml.DefaultAddressBookURL)
except HTTPError:
pass
else:
self.fail("carddavxml.DefaultAddressBookURL is not empty")
yield home.pickNewDefaultAddressBook(request)
try:
default = home.readDeadProperty(carddavxml.DefaultAddressBookURL)
except HTTPError:
self.fail("carddavxml.DefaultAddressBookURL is not present")
else:
self.assertEqual(str(default.children[0]), "/addressbooks/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/addressbook/")
开发者ID:nunb,项目名称:calendarserver,代码行数:24,代码来源:test_resource.py
注:本文中的twistedcaldav.test.util.SimpleStoreRequest类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论