本文整理汇总了Python中txweb2.test.test_server.SimpleRequest.locateResource方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleRequest.locateResource方法的具体用法?Python SimpleRequest.locateResource怎么用?Python SimpleRequest.locateResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txweb2.test.test_server.SimpleRequest
的用法示例。
在下文中一共展示了SimpleRequest.locateResource方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_free_busy_set_tasks
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_free_busy_set_tasks(self):
"""
Test that calendar-free-busy-set ignores tasks calendar.
"""
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(
set([str(child) for child in prop.children]),
set((
"/calendars/__uids__/user01/calendar/",
))
)
newfbset = set()
newfbset.add("/calendars/users/user01/tasks/")
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(len(prop.children), 0)
yield request._newStoreTransaction.commit()
calendar = yield request.locateResource("/calendars/__uids__/user01/tasks/")
self.assertFalse(calendar._newStoreObject.isUsedForFreeBusy())
calendar = yield request.locateResource("/calendars/__uids__/user01/calendar/")
self.assertFalse(calendar._newStoreObject.isUsedForFreeBusy())
示例2: test_free_busy_set_same
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
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())
示例3: _checkPrivileges
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def _checkPrivileges(self, resource, url, principal, privilege, allowed):
request = SimpleRequest(self.site, "GET", "/")
def gotResource(resource):
d = resource.checkPrivileges(
request, (privilege,), principal=davxml.Principal(principal)
)
if allowed:
def onError(f):
f.trap(AccessDeniedError)
# print(resource.readDeadProperty(davxml.ACL))
self.fail(
"%s should have %s privilege on %r"
% (principal.sname(), privilege.sname(), resource)
)
d.addErrback(onError)
else:
def expectAccessDenied(f):
f.trap(AccessDeniedError)
def onSuccess(_):
# print(resource.readDeadProperty(davxml.ACL))
self.fail(
"%s should not have %s privilege on %r"
% (principal.sname(), privilege.sname(), resource)
)
d.addCallbacks(onSuccess, expectAccessDenied)
return d
d = request.locateResource(url)
d.addCallback(gotResource)
return d
示例4: test_renderPrivileges
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_renderPrivileges(self):
"""
Verify that a directory listing includes children which you
don't have access to.
"""
request = SimpleRequest(self.site, "GET", "/")
def setEmptyACL(resource):
resource.setAccessControlList(davxml.ACL()) # Empty ACL = no access
return resource
def renderRoot(_):
d = request.locateResource("/")
d.addCallback(lambda r: r.render(request))
return d
def assertListing(response):
data = []
d = readStream(response.stream, lambda s: data.append(str(s)))
d.addCallback(lambda _: self.failIf(
'dir2/' not in "".join(data),
"'dir2' expected in listing: %r" % (data,)
))
return d
d = request.locateResource("/dir2")
d.addCallback(setEmptyACL)
d.addCallback(renderRoot)
d.addCallback(assertListing)
return d
示例5: test_checkPrivileges
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_checkPrivileges(self):
"""
DAVResource.checkPrivileges()
"""
ds = []
authAllResource = AuthAllResource()
requested_access = (davxml.All(),)
site = Site(authAllResource)
def expectError(failure):
failure.trap(AccessDeniedError)
errors = failure.value.errors
self.failUnless(len(errors) == 1)
subpath, denials = errors[0]
self.failUnless(subpath is None)
self.failUnless(
tuple(denials) == requested_access,
"%r != %r" % (tuple(denials), requested_access)
)
def expectOK(result):
self.failUnlessEquals(result, None)
def _checkPrivileges(resource):
d = resource.checkPrivileges(request, requested_access)
return d
# No auth; should deny
request = SimpleRequest(site, "GET", "/")
d = request.locateResource("/").addCallback(_checkPrivileges).addErrback(expectError)
ds.append(d)
# Has auth; should allow
request = SimpleRequest(site, "GET", "/")
request.authnUser = davxml.Principal(davxml.HRef("/users/d00d"))
request.authzUser = davxml.Principal(davxml.HRef("/users/d00d"))
d = request.locateResource("/")
d.addCallback(_checkPrivileges)
d.addCallback(expectOK)
ds.append(d)
return DeferredList(ds)
示例6: test_free_busy_set_invalid_url
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_free_busy_set_invalid_url(self):
"""
Test that calendar-free-busy-set will generate an error if an invalid value is used.
"""
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)))
oldfbset = set(("/calendar",))
newfbset = set()
newfbset.update(oldfbset)
newfbset.add("/calendar-broken")
newset = caldavxml.CalendarFreeBusySet(*[davxml.HRef(url) for url in newfbset])
yield self.failUnlessFailure(inbox.writeProperty(newset, request), HTTPError)
示例7: test_findChildrenWithPrivileges
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_findChildrenWithPrivileges(self):
"""
This test revokes read privileges for the C{"/file2"} and C{"/dir2/"}
resource to verify that we can not find them giving our unauthenticated
privileges.
"""
expected_children = [
"/file1",
"/dir1/",
]
request = SimpleRequest(self.site, "GET", "/")
resource = waitForDeferred(request.locateResource("/"))
yield resource
resource = resource.getResult()
def checkChildren(resource, uri):
self.assertEquals(uri, resource.uri)
if uri not in expected_children:
unexpected_children.append(uri)
else:
found_children.append(uri)
found_children = []
unexpected_children = []
privileges = waitForDeferred(resource.currentPrivileges(request))
yield privileges
privileges = privileges.getResult()
fc = resource.findChildren("1", request, checkChildren, privileges)
completed = waitForDeferred(fc)
yield completed
completed.getResult()
self.assertEquals(
unexpected_children, [],
"Found unexpected children: %r" % (unexpected_children,)
)
expected_children.sort()
found_children.sort()
self.assertEquals(expected_children, found_children)
示例8: test_findChildrenCallbackRaises
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_findChildrenCallbackRaises(self):
"""
Verify that when the user callback raises an exception
the completion deferred returned by findChildren errbacks
TODO: Verify that the user callback doesn't get called subsequently
"""
def raiseOnChild(resource, uri):
raise Exception("Oh no!")
def findChildren(resource):
return self.assertFailure(
resource.findChildren("infinity", request, raiseOnChild),
Exception
)
request = SimpleRequest(self.site, "GET", "/")
d = request.locateResource("/").addCallback(findChildren)
return d
示例9: test_free_busy_set_different
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_free_busy_set_different(self):
"""
Test that calendar-free-busy-set has the correct value and can be reset to the same.
"""
txn = self.transactionUnderTest()
home = (yield txn.calendarHomeWithUID("user01", create=True))
yield home.createCalendarWithName("calendar_new")
yield self.commit()
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(
set([str(child) for child in prop.children]),
set((
"/calendars/__uids__/user01/calendar/",
"/calendars/__uids__/user01/calendar_new/",
))
)
calendar = yield request.locateResource("/calendars/__uids__/user01/calendar_new/")
self.assertTrue(calendar._newStoreObject.isUsedForFreeBusy())
calendar = yield request.locateResource("/calendars/__uids__/user01/calendar/")
self.assertTrue(calendar._newStoreObject.isUsedForFreeBusy())
newfbset = set()
newfbset.add("/calendars/users/user01/calendar_new/")
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_new/"))
yield request._newStoreTransaction.commit()
calendar = yield request.locateResource("/calendars/__uids__/user01/calendar_new/")
self.assertTrue(calendar._newStoreObject.isUsedForFreeBusy())
calendar = yield request.locateResource("/calendars/__uids__/user01/calendar/")
self.assertFalse(calendar._newStoreObject.isUsedForFreeBusy())
示例10: test_findChildren
# 需要导入模块: from txweb2.test.test_server import SimpleRequest [as 别名]
# 或者: from txweb2.test.test_server.SimpleRequest import locateResource [as 别名]
def test_findChildren(self):
"""
This test asserts that we have:
1) not found any unexpected children
2) found all expected children
It does this for all depths C{"0"}, C{"1"}, and C{"infintiy"}
"""
expected_children = {
"0": [],
"1": [
"/file1",
"/file2",
"/dir1/",
"/dir2/",
],
"infinity": [
"/file1",
"/file2",
"/dir1/",
"/dir1/subdir1/",
"/dir2/",
"/dir2/file1",
"/dir2/file2",
"/dir2/subdir1/",
"/dir2/subdir1/file1",
"/dir2/subdir1/file2",
],
}
request = SimpleRequest(self.site, "GET", "/")
resource = waitForDeferred(request.locateResource("/"))
yield resource
resource = resource.getResult()
def checkChildren(resource, uri):
self.assertEquals(uri, resource.uri)
if uri not in expected_children[depth]:
unexpected_children.append(uri)
else:
found_children.append(uri)
for depth in ["0", "1", "infinity"]:
found_children = []
unexpected_children = []
fc = resource.findChildren(depth, request, checkChildren)
completed = waitForDeferred(fc)
yield completed
completed.getResult()
self.assertEquals(
unexpected_children, [],
"Found unexpected children: %r" % (unexpected_children,)
)
expected_children[depth].sort()
found_children.sort()
self.assertEquals(expected_children[depth], found_children)