本文整理汇总了Python中resync.resource.Resource.timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.timestamp方法的具体用法?Python Resource.timestamp怎么用?Python Resource.timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resync.resource.Resource
的用法示例。
在下文中一共展示了Resource.timestamp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test19_delete_resource
# 需要导入模块: from resync.resource import Resource [as 别名]
# 或者: from resync.resource.Resource import timestamp [as 别名]
def test19_delete_resource(self):
c = Client()
resource = Resource(uri='http://example.org/1')
filename = os.path.join(self.tmpdir, 'resource1')
c.last_timestamp = 5
# no delete, no timestamp update
with LogCapture() as lc:
c.logger = logging.getLogger('resync.client')
n = c.delete_resource(resource, filename)
self.assertEqual(n, 0)
self.assertEqual(lc.records[-1].msg,
'nodelete: would delete http://example.org/1 (--delete to enable)')
self.assertEqual(c.last_timestamp, 5)
# no delete but timestamp update
resource.timestamp = 10
with LogCapture() as lc:
c.logger = logging.getLogger('resync.client')
n = c.delete_resource(resource, filename)
self.assertEqual(n, 0)
self.assertEqual(lc.records[-1].msg,
'nodelete: would delete http://example.org/1 (--delete to enable)')
self.assertEqual(c.last_timestamp, 10)
# allow delete but dryrun
with LogCapture() as lc:
c.dryrun = True
c.logger = logging.getLogger('resync.client')
n = c.delete_resource(resource, filename, allow_deletion=True)
self.assertEqual(n, 0)
self.assertTrue(
lc.records[-1].msg.startswith('dryrun: would delete http://example.org/1'))
c.dryrun = False
# allow delete but no resource present
with LogCapture() as lc:
c.logger = logging.getLogger('resync.client')
n = c.delete_resource(resource, filename, allow_deletion=True)
self.assertEqual(n, 0)
self.assertTrue(
lc.records[-1].msg.startswith('Failed to DELETE http://example.org/1'))
# successful deletion, first make file...
with open(filename, 'w') as fh:
fh.write('delete me')
fh.close()
with LogCapture() as lc:
c.logger = logging.getLogger('resync.client')
n = c.delete_resource(resource, filename, allow_deletion=True)
self.assertEqual(n, 1)
self.assertTrue(lc.records[-1].msg.startswith('Event: {'))
self.assertTrue(
lc.records[-2].msg.startswith('deleted: http://example.org/1 ->'))