diff --git a/src/Test/TestSiteDownload.py b/src/Test/TestSiteDownload.py index d39d9699..ea9bf17a 100644 --- a/src/Test/TestSiteDownload.py +++ b/src/Test/TestSiteDownload.py @@ -107,6 +107,58 @@ class TestSiteDownload: assert site_temp.storage.deleteFiles() [connection.close() for connection in file_server.connections] + def testArchivedBeforeDownload(self, file_server, site, site_temp): + file_server.ip_incoming = {} # Reset flood protection + + # Init source server + site.connection_server = file_server + file_server.sites[site.address] = site + + # Init client server + client = FileServer("127.0.0.1", 1545) + client.sites[site_temp.address] = site_temp + site_temp.connection_server = client + + # Download normally + site_temp.addPeer("127.0.0.1", 1544) + site_temp.download(blind_includes=True).join(timeout=5) + bad_files = site_temp.storage.verifyFiles(quick_check=True)["bad_files"] + + assert not bad_files + assert "data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json" in site_temp.content_manager.contents + assert site_temp.storage.isFile("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json") + assert len(list(site_temp.storage.query("SELECT * FROM comment"))) == 2 + + # Add archived data + assert not "archived_before" in site.content_manager.contents["data/users/content.json"]["user_contents"] + assert not site.content_manager.isArchived("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", time.time()-1) + + content_modification_time = site.content_manager.contents["data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json"]["modified"] + site.content_manager.contents["data/users/content.json"]["user_contents"]["archived_before"] = content_modification_time + site.content_manager.sign("data/users/content.json", privatekey="5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv") + + date_archived = site.content_manager.contents["data/users/content.json"]["user_contents"]["archived_before"] + assert site.content_manager.isArchived("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", date_archived-1) + assert site.content_manager.isArchived("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", date_archived) + assert not site.content_manager.isArchived("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", date_archived+1) # Allow user to update archived data later + + # Push archived update + assert not "archived_before" in site_temp.content_manager.contents["data/users/content.json"]["user_contents"] + site.publish() + time.sleep(0.1) + site_temp.download(blind_includes=True).join(timeout=5) # Wait for download + + # The archived content should disappear from remote client + assert "archived_before" in site_temp.content_manager.contents["data/users/content.json"]["user_contents"] + assert "data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json" not in site_temp.content_manager.contents + assert not site_temp.storage.isDir("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q") + assert len(list(site_temp.storage.query("SELECT * FROM comment"))) == 1 + assert len(list(site_temp.storage.query("SELECT * FROM json WHERE directory LIKE '%1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q%'"))) == 0 + + assert site_temp.storage.deleteFiles() + [connection.close() for connection in file_server.connections] + + # Test when connected peer has the optional file def testOptionalDownload(self, file_server, site, site_temp): file_server.ip_incoming = {} # Reset flood protection