MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / testClone

Method testClone

src/Test/TestSite.py:11–70  ·  view source on GitHub ↗
(self, site)

Source from the content-addressed store, hash-verified

9@pytest.mark.usefixtures("resetSettings")
10class TestSite:
11 def testClone(self, site):
12 assert site.storage.directory == TEST_DATA_PATH + "/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
13
14 # Remove old files
15 if os.path.isdir(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
16 shutil.rmtree(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
17 assert not os.path.isfile(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL/content.json")
18
19 # Clone 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT to 15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc
20 new_site = site.clone(
21 "159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL", "5JU2p5h3R7B1WrbaEdEDNZR7YHqRLGcjNcqwqVQzX2H4SuNe2ee", address_index=1
22 )
23
24 # Check if clone was successful
25 assert new_site.address == "159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"
26 assert new_site.storage.isFile("content.json")
27 assert new_site.storage.isFile("index.html")
28 assert new_site.storage.isFile("data/users/content.json")
29 assert new_site.storage.isFile("data/zeroblog.db")
30 assert new_site.storage.verifyFiles()["bad_files"] == [] # No bad files allowed
31 assert new_site.storage.query("SELECT * FROM keyvalue WHERE key = 'title'").fetchone()["value"] == "MyZeroBlog"
32
33 # Optional files should be removed
34
35 assert len(new_site.storage.loadJson("content.json").get("files_optional", {})) == 0
36
37 # Test re-cloning (updating)
38
39 # Changes in non-data files should be overwritten
40 new_site.storage.write("index.html", b"this will be overwritten")
41 assert new_site.storage.read("index.html") == b"this will be overwritten"
42
43 # Changes in data file should be kept after re-cloning
44 changed_contentjson = new_site.storage.loadJson("content.json")
45 changed_contentjson["description"] = "Update Description Test"
46 new_site.storage.writeJson("content.json", changed_contentjson)
47
48 changed_data = new_site.storage.loadJson("data/data.json")
49 changed_data["title"] = "UpdateTest"
50 new_site.storage.writeJson("data/data.json", changed_data)
51
52 # The update should be reflected to database
53 assert new_site.storage.query("SELECT * FROM keyvalue WHERE key = 'title'").fetchone()["value"] == "UpdateTest"
54
55 # Re-clone the site
56 site.log.debug("Re-cloning")
57 site.clone("159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
58
59 assert new_site.storage.loadJson("data/data.json")["title"] == "UpdateTest"
60 assert new_site.storage.loadJson("content.json")["description"] == "Update Description Test"
61 assert new_site.storage.read("index.html") != "this will be overwritten"
62
63 # Delete created files
64 new_site.storage.deleteFiles()
65 assert not os.path.isdir(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
66
67 # Delete from site registry
68 assert new_site.address in SiteManager.site_manager.sites

Callers

nothing calls this directly

Calls 11

cloneMethod · 0.80
verifyFilesMethod · 0.80
queryMethod · 0.80
loadJsonMethod · 0.80
writeJsonMethod · 0.80
deleteFilesMethod · 0.80
isFileMethod · 0.45
getMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected