本文整理汇总了Python中Site.Site.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Site.clone方法的具体用法?Python Site.clone怎么用?Python Site.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Site.Site
的用法示例。
在下文中一共展示了Site.clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testClone
# 需要导入模块: from Site import Site [as 别名]
# 或者: from Site.Site import clone [as 别名]
def testClone(self):
from Site import Site
import shutil
site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT") # Privatekey: 5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv
self.assertEqual(site.storage.directory, "src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
# Remove old files
if os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
shutil.rmtree("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
self.assertFalse(os.path.isfile("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL/content.json"))
# Clone 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT to 15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc
new_site = site.clone("159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL", "5JU2p5h3R7B1WrbaEdEDNZR7YHqRLGcjNcqwqVQzX2H4SuNe2ee", address_index=1)
# Check if clone was successful
self.assertEqual(new_site.address, "159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
self.assertTrue(new_site.storage.isFile("content.json"))
self.assertTrue(new_site.storage.isFile("index.html"))
self.assertTrue(new_site.storage.isFile("data/users/content.json"))
self.assertTrue(new_site.storage.isFile("data/zeroblog.db"))
# Test re-cloning (updating)
# Changes in non-data files should be overwritten
new_site.storage.write("index.html", "this will be overwritten")
self.assertEqual(new_site.storage.read("index.html"), "this will be overwritten")
# Changes in data file should be kept after re-cloning
changed_contentjson = new_site.storage.loadJson("content.json")
changed_contentjson["description"] = "Update Description Test"
new_site.storage.writeJson("content.json", changed_contentjson)
changed_data = new_site.storage.loadJson("data/data.json")
changed_data["title"] = "UpdateTest"
new_site.storage.writeJson("data/data.json", changed_data)
# Re-clone the site
site.clone("159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
self.assertEqual(new_site.storage.loadJson("data/data.json")["title"], "UpdateTest")
self.assertEqual(new_site.storage.loadJson("content.json")["description"], "Update Description Test")
self.assertNotEqual(new_site.storage.read("index.html"), "this will be overwritten")
# Delete created files
if os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
new_site.storage.closeDb()
shutil.rmtree("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")