本文整理汇总了Python中twext.web2.test.test_server.SimpleRequest类的典型用法代码示例。如果您正苦于以下问题:Python SimpleRequest类的具体用法?Python SimpleRequest怎么用?Python SimpleRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mkcalendar_cb
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
if not calPath.isdir():
self.fail("MKCALENDAR did not create a collection")
ds = []
c = 0
for stream, response_code in work:
def put_cb(response, stream=stream, response_code=response_code):
response = IResponse(response)
if response.code != response_code:
self.fail("Incorrect response to %s: %s (!= %s)" % (what, response.code, response_code))
dst_uri = "/".join([calendar_uri, "dst%d.ics" % (c,)])
request = SimpleRequest(self.site, "PUT", dst_uri)
request.headers.setHeader("if-none-match", "*")
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = stream
ds.append(self.send(request, put_cb))
c += 1
return DeferredList(ds)
示例2: mkcalendar_cb
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
def propfind_cb(response):
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("Incorrect response to PROPFIND: %s" % (response.code,))
def got_xml(doc):
if not isinstance(doc.root_element, davxml.MultiStatus):
self.fail("PROPFIND response XML root element is not multistatus: %r" % (doc.root_element,))
response = doc.root_element.childOfType(davxml.Response)
href = response.childOfType(davxml.HRef)
self.failUnless(str(href) == calendar_uri)
container = response.childOfType(davxml.PropertyStatus).childOfType(davxml.PropertyContainer)
#
# Check CalDAV:supported-calendar-component-set
#
supported_components = container.childOfType(caldavxml.SupportedCalendarComponentSet)
if supported_components:
self.fail("CalDAV:supported-calendar-component-set element was returned; but should be hidden.")
#
# Check CalDAV:supported-calendar-data
#
supported_calendar = container.childOfType(caldavxml.SupportedCalendarData)
if supported_calendar:
self.fail("CalDAV:supported-calendar-data elementwas returned; but should be hidden.")
#
# Check DAV:supported-report-set
#
supported_reports = container.childOfType(davxml.SupportedReportSet)
if supported_reports:
self.fail("DAV:supported-report-set element was returned; but should be hidden..")
return davXMLFromStream(response.stream).addCallback(got_xml)
query = davxml.PropertyFind(
davxml.AllProperties(),
)
request = SimpleRequest(
self.site,
"PROPFIND",
calendar_uri,
headers=http_headers.Headers({"Depth":"0"}),
)
request.stream = MemoryStream(query.toxml())
return self.send(request, propfind_cb)
示例3: work
def work():
for method in ("GET", "REPORT"):
if method == "GET":
ok = responsecode.OK
elif method == "REPORT":
ok = responsecode.MULTI_STATUS
else:
raise AssertionError("We shouldn't be here. (method = %r)" % (method,))
for name, code in (
("none" , responsecode.FORBIDDEN),
("read" , ok),
("read-write" , ok),
("unlock" , responsecode.FORBIDDEN),
("all" , ok),
):
path = os.path.join(self.docroot, name)
request = SimpleRequest(self.site, method, "/" + name)
if method == "REPORT":
request.stream = MemoryStream(element.PrincipalPropertySearch().toxml())
_add_auth_header(request)
def test(response, code=code, path=path):
if response.code != code:
return self.oops(request, response, code, method, name)
yield (request, test)
示例4: work
def work():
for code in (
responsecode.CREATED,
responsecode.PRECONDITION_FAILED,
responsecode.NO_CONTENT,
responsecode.PRECONDITION_FAILED,
responsecode.NO_CONTENT,
responsecode.CREATED,
):
def checkResult(response, code=code):
response = IResponse(response)
if response.code != code:
self.fail("Incorrect response code for PUT (%s != %s)"
% (response.code, code))
def onError(f):
f.trap(HTTPError)
return checkResult(f.value.response)
request = SimpleRequest(self.site, "PUT", dst_uri)
request.stream = FileStream(file(__file__, "rb"))
if code == responsecode.CREATED:
if os.path.isfile(dst_path):
os.remove(dst_path)
request.headers.setHeader("if-none-match", ("*",))
elif code == responsecode.PRECONDITION_FAILED:
request.headers.setHeader("if-none-match", ("*",))
yield (request, (checkResult, onError))
示例5: test_pick_default_addressbook
def test_pick_default_addressbook(self):
"""
Make calendar
"""
request = SimpleRequest(self.site, "GET", "/addressbooks/users/wsanchez/")
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/")
request._newStoreTransaction.abort()
示例6: test_fix_shared_default
def test_fix_shared_default(self):
"""
Make calendar
"""
request = SimpleRequest(self.site, "GET", "/addressbooks/users/wsanchez/")
home = yield request.locateResource("/addressbooks/users/wsanchez")
# Create a new default adbk
newadbk = yield request.locateResource("/addressbooks/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newadbk/")
yield newadbk.createAddressBookCollection()
home.writeDeadProperty(carddavxml.DefaultAddressBookURL(
HRef("/addressbooks/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newadbk/")
))
try:
default = yield home.readProperty(carddavxml.DefaultAddressBookURL, request)
except HTTPError:
self.fail("carddavxml.DefaultAddressBookURL is not present")
else:
self.assertEqual(str(default.children[0]), "/addressbooks/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newadbk/")
# Force the new calendar to think it is a sharee collection
newadbk._isShareeCollection = True
try:
default = yield home.readProperty(carddavxml.DefaultAddressBookURL, request)
except HTTPError:
self.fail("carddavxml.DefaultAddressBookURL is not present")
else:
self.assertEqual(str(default.children[0]), "/addressbooks/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/addressbook/")
request._newStoreTransaction.abort()
示例7: do_report
def do_report(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
# Add holiday events to calendar
# We're cheating by simply copying the files in
for filename in os.listdir(self.holidays_dir):
if os.path.splitext(filename)[1] != ".ics": continue
path = os.path.join(self.holidays_dir, filename)
shutil.copy(path, calendar_path)
# Delete the index because we cheated
index_path = os.path.join(calendar_path, db_basename)
if os.path.isfile(index_path): os.remove(index_path)
request = SimpleRequest(self.site, "REPORT", calendar_uri)
request.stream = MemoryStream(query.toxml())
def do_test(response):
response = IResponse(response)
if response.code != responsecode.OK:
self.fail("REPORT failed: %s" % (response.code,))
return Component.fromIStream(response.stream).addCallback(got_calendar)
return self.send(request, do_test, calendar_path)
示例8: test_free_busy_set_same
def test_free_busy_set_same(self):
"""
Test that calendar-free-busy-set has the correct value and can be reset to the same.
"""
request = SimpleRequest(self.site, "GET", "/calendars/users/user01/inbox/")
inbox = yield request.locateResource("/calendars/users/user01/inbox/")
self.assertTrue((yield inbox.hasProperty(caldavxml.CalendarFreeBusySet, request)))
prop = (yield inbox.readProperty(caldavxml.CalendarFreeBusySet, request))
self.assertEqual(prop.children[0], davxml.HRef("/calendars/__uids__/user01/calendar/"))
newfbset = set()
newfbset.add("/calendars/users/user01/calendar/")
newset = caldavxml.CalendarFreeBusySet(*[davxml.HRef(url) for url in newfbset])
yield inbox.writeProperty(newset, request)
yield request._newStoreTransaction.commit()
request = SimpleRequest(self.site, "GET", "/calendars/users/user01/inbox/")
inbox = yield request.locateResource("/calendars/users/user01/inbox/")
prop = (yield inbox.readProperty(caldavxml.CalendarFreeBusySet, request))
self.assertEqual(prop.children[0], davxml.HRef("/calendars/__uids__/user01/calendar/"))
yield request._newStoreTransaction.commit()
calendar = yield request.locateResource("/calendars/__uids__/user01/calendar/")
self.assertTrue(calendar._newStoreObject.isUsedForFreeBusy())
示例9: test_missing_default_vtodo_calendar
def test_missing_default_vtodo_calendar(self):
"""
Test that pickNewDefaultCalendar will create a missing default tasks calendar.
"""
request = SimpleRequest(self.site, "GET", "/calendars/users/wsanchez/")
home = yield request.locateResource("/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
# default property initially not present
try:
inbox.readDeadProperty(customxml.ScheduleDefaultTasksURL)
except HTTPError:
pass
else:
self.fail("caldavxml.ScheduleDefaultTasksURL is not empty")
# 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)
yield inbox.pickNewDefaultCalendar(request, tasks=True)
try:
default = inbox.readDeadProperty(customxml.ScheduleDefaultTasksURL)
except HTTPError:
self.fail("caldavxml.ScheduleDefaultTasksURL is not present")
else:
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/tasks")
request._newStoreTransaction.abort()
示例10: test_Quota_DELETE
def test_Quota_DELETE(self):
"""
Quota change on DELETE
"""
dst_uri = "/dst"
def checkPUTResult(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("Incorrect response code for PUT (%s != %s)"
% (response.code, responsecode.CREATED))
def doDelete(_ignore):
def checkDELETEResult(response):
response = IResponse(response)
if response.code != responsecode.NO_CONTENT:
self.fail("Incorrect response code for PUT (%s != %s)"
% (response.code, responsecode.NO_CONTENT))
return self.checkQuota(0)
request = SimpleRequest(self.site, "DELETE", dst_uri)
return self.send(request, checkDELETEResult)
d = self.checkQuota(100)
d.addCallback(doDelete)
return d
request = SimpleRequest(self.site, "PUT", dst_uri)
request.stream = FileStream(file(os.path.join(os.path.dirname(__file__), "data", "quota_100.txt"), "rb"))
return self.send(request, checkPUTResult)
示例11: addEventsDir
def addEventsDir(testCase, eventsDir, uri):
"""
Add events to a L{HomeTestCase} from a directory.
@param testCase: The test case to add events to.
@type testCase: L{HomeTestCase}
@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 = SimpleRequest(testCase.site, "PUT",
uri + "/" + child.basename())
request.stream = MemoryStream(child.getContent())
yield testCase.send(request)
returnValue(count)
示例12: 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 = SimpleRequest(self.site, "PUT", event_uri)
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = MemoryStream(calendar)
return self.send(request, put_cb)
示例13: test_Quota_Bad_Adjustment
def test_Quota_Bad_Adjustment(self):
"""
Quota adjustment too much
"""
dst_uri = "/dst"
def checkPUTResult(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("Incorrect response code for PUT (%s != %s)"
% (response.code, responsecode.CREATED))
def doBadAdjustment(_ignore):
def checkAdjustmentResult(_ignore):
return self.checkQuota(100)
d = self.site.resource.quotaSizeAdjust(None, -200)
d.addCallback(checkAdjustmentResult)
return d
d = self.checkQuota(100)
d.addCallback(doBadAdjustment)
return d
request = SimpleRequest(self.site, "PUT", dst_uri)
request.stream = FileStream(file(os.path.join(os.path.dirname(__file__), "data", "quota_100.txt"), "rb"))
return self.send(request, checkPUTResult)
示例14: 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 = SimpleRequest(self.site, "GET", "/calendars/users/wsanchez/")
inbox = yield request.locateResource("/calendars/users/wsanchez/inbox")
# default property not present
try:
inbox.readDeadProperty(caldavxml.ScheduleDefaultCalendarURL)
except HTTPError:
pass
else:
self.fail("caldavxml.ScheduleDefaultCalendarURL is not empty")
# Create a new default calendar
newcalendar = yield request.locateResource("/calendars/users/wsanchez/newcalendar")
yield newcalendar.createCalendarCollection()
yield newcalendar.setSupportedComponents(("VEVENT",))
request._newStoreTransaction.commit()
request = SimpleRequest(self.site, "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)
try:
default = inbox.readDeadProperty(caldavxml.ScheduleDefaultCalendarURL)
except HTTPError:
self.fail("caldavxml.ScheduleDefaultCalendarURL is not present")
else:
self.assertEqual(str(default.children[0]), "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/newcalendar")
request._newStoreTransaction.commit()
示例15: do_report
def do_report(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCOL failed: %s" % (response.code,))
# Add vCards to addressbook
# We're cheating by simply copying the files in
for filename in os.listdir(self.vcards_dir):
if os.path.splitext(filename)[1] != ".vcf": continue
path = os.path.join(self.vcards_dir, filename)
shutil.copy(path, addressbook_path)
# Delete the index because we cheated
index_path = os.path.join(addressbook_path, db_basename)
if os.path.isfile(index_path): os.remove(index_path)
request = SimpleRequest(self.site, "REPORT", addressbook_uri)
request.stream = MemoryStream(query.toxml())
def do_test(response):
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
return davXMLFromStream(response.stream).addCallback(got_xml)
return self.send(request, do_test)