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

Method testUpdate

src/Test/TestSiteDownload.py:336–413  ·  view source on GitHub ↗
(self, file_server, site, site_temp)

Source from the content-addressed store, hash-verified

334 site_full.content_manager.contents.db.close()
335
336 def testUpdate(self, file_server, site, site_temp):
337 assert site.storage.directory == config.data_dir + "/" + site.address
338 assert site_temp.storage.directory == config.data_dir + "-temp/" + site.address
339
340 # Init source server
341 site.connection_server = file_server
342 file_server.sites[site.address] = site
343
344 # Init client server
345 client = FileServer(file_server.ip, 1545)
346 client.sites[site_temp.address] = site_temp
347 site_temp.connection_server = client
348
349 # Don't try to find peers from the net
350 site.announce = mock.MagicMock(return_value=True)
351 site_temp.announce = mock.MagicMock(return_value=True)
352
353 # Connect peers
354 site_temp.addPeer(file_server.ip, 1544)
355
356 # Download site from site to site_temp
357 site_temp.download(blind_includes=True).join(timeout=5)
358
359 # Update file
360 data_original = site.storage.open("data/data.json").read()
361 data_new = data_original.replace(b'"ZeroBlog"', b'"UpdatedZeroBlog"')
362 assert data_original != data_new
363
364 site.storage.open("data/data.json", "wb").write(data_new)
365
366 assert site.storage.open("data/data.json").read() == data_new
367 assert site_temp.storage.open("data/data.json").read() == data_original
368
369 site.log.info("Publish new data.json without patch")
370 # Publish without patch
371 with Spy.Spy(FileRequest, "route") as requests:
372 site.content_manager.sign("content.json", privatekey="5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv")
373 site.publish()
374 time.sleep(0.1)
375 site_temp.download(blind_includes=True).join(timeout=5)
376 assert len([request for request in requests if request[1] in ("getFile", "streamFile")]) == 1
377
378 assert site_temp.storage.open("data/data.json").read() == data_new
379
380 # Close connection to avoid update spam limit
381 list(site.peers.values())[0].remove()
382 site.addPeer(file_server.ip, 1545)
383 list(site_temp.peers.values())[0].ping() # Connect back
384 time.sleep(0.1)
385
386 # Update with patch
387 data_new = data_original.replace(b'"ZeroBlog"', b'"PatchedZeroBlog"')
388 assert data_original != data_new
389
390 site.storage.open("data/data.json-new", "wb").write(data_new)
391
392 assert site.storage.open("data/data.json-new").read() == data_new
393 assert site_temp.storage.open("data/data.json").read() != data_new

Callers

nothing calls this directly

Calls 15

FileServerClass · 0.90
addPeerMethod · 0.80
downloadMethod · 0.80
openMethod · 0.80
removeMethod · 0.80
valuesMethod · 0.80
getDiffsMethod · 0.80
deleteFilesMethod · 0.80
readMethod · 0.45
writeMethod · 0.45
signMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected