From f69d47587f7ea552e12cc47b1f7001397eeb05db Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sun, 19 Sep 2021 21:38:09 -0400 Subject: [PATCH] tests --- lbry/blob/blob_info.py | 2 +- tests/integration/other/test_cli.py | 4 +-- tests/unit/blob/test_disk_space_manager.py | 30 ------------------- .../unit/components/test_component_manager.py | 6 ++-- tests/unit/database/test_SQLiteStorage.py | 2 +- .../lbrynet_daemon/test_allowed_origin.py | 4 +-- 6 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 tests/unit/blob/test_disk_space_manager.py diff --git a/lbry/blob/blob_info.py b/lbry/blob/blob_info.py index 408b6047b..7d4bc71dd 100644 --- a/lbry/blob/blob_info.py +++ b/lbry/blob/blob_info.py @@ -13,7 +13,7 @@ class BlobInfo: def __init__( self, blob_num: int, length: int, iv: str, - blob_hash: typing.Optional[str] = None, added_on=None, is_mine=None): + blob_hash: typing.Optional[str] = None, added_on=0, is_mine=False): self.blob_hash = blob_hash self.blob_num = blob_num self.length = length diff --git a/tests/integration/other/test_cli.py b/tests/integration/other/test_cli.py index 1d733899f..7de635fc6 100644 --- a/tests/integration/other/test_cli.py +++ b/tests/integration/other/test_cli.py @@ -5,7 +5,7 @@ from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras import cli from lbry.extras.daemon.components import ( - DATABASE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, + DATABASE_COMPONENT, DISK_SPACE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT, LIBTORRENT_COMPONENT @@ -21,7 +21,7 @@ class CLIIntegrationTest(AsyncioTestCase): conf.share_usage_data = False conf.api = 'localhost:5299' conf.components_to_skip = ( - DATABASE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, + DATABASE_COMPONENT, DISK_SPACE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT, LIBTORRENT_COMPONENT diff --git a/tests/unit/blob/test_disk_space_manager.py b/tests/unit/blob/test_disk_space_manager.py deleted file mode 100644 index 54871f092..000000000 --- a/tests/unit/blob/test_disk_space_manager.py +++ /dev/null @@ -1,30 +0,0 @@ -import os -import unittest -import tempfile - -import lbry.wallet -from lbry.conf import Config -from lbry.blob.disk_space_manager import DiskSpaceManager - - -class ConfigurationTests(unittest.TestCase): - - def test_space_management(self): - with tempfile.TemporaryDirectory() as temp_dir: - os.mkdir(os.path.join(temp_dir, 'blobfiles')) - config = Config( - blob_storage_limit=5, - data_dir=temp_dir, - wallet_dir=temp_dir, - config=os.path.join(temp_dir, 'settings.yml'), - ) - dsm = DiskSpaceManager(config) - self.assertEqual(0, dsm.space_used_mb) - for file_no in range(10): - with open(os.path.join(config.data_dir, 'blobfiles', f'3mb-{file_no}'), 'w') as blob: - blob.write('0' * 1 * 1024 * 1024) - self.assertEqual(10, dsm.space_used_mb) - self.assertTrue(dsm.clean()) - self.assertEqual(5, dsm.space_used_mb) - self.assertFalse(dsm.clean()) - diff --git a/tests/unit/components/test_component_manager.py b/tests/unit/components/test_component_manager.py index f539f033e..af7f19c33 100644 --- a/tests/unit/components/test_component_manager.py +++ b/tests/unit/components/test_component_manager.py @@ -3,7 +3,7 @@ from lbry.testcase import AsyncioTestCase, AdvanceTimeTestCase from lbry.conf import Config from lbry.extras.daemon.componentmanager import ComponentManager -from lbry.extras.daemon.components import DATABASE_COMPONENT, DHT_COMPONENT +from lbry.extras.daemon.components import DATABASE_COMPONENT, DISK_SPACE_COMPONENT, DHT_COMPONENT from lbry.extras.daemon.components import HASH_ANNOUNCER_COMPONENT, UPNP_COMPONENT from lbry.extras.daemon.components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT from lbry.extras.daemon import components @@ -15,7 +15,6 @@ class TestComponentManager(AsyncioTestCase): self.default_components_sort = [ [ components.DatabaseComponent, - components.DiskSpaceComponent, components.ExchangeRateManagerComponent, components.TorrentComponent, components.UPnPComponent @@ -26,6 +25,7 @@ class TestComponentManager(AsyncioTestCase): components.WalletComponent ], [ + components.DiskSpaceComponent, components.FileManagerComponent, components.HashAnnouncerComponent, components.PeerProtocolServerComponent, @@ -153,7 +153,7 @@ class TestComponentManagerProperStart(AdvanceTimeTestCase): self.component_manager = ComponentManager( Config(), skip_components=[ - DATABASE_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, + DATABASE_COMPONENT, DISK_SPACE_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT], wallet=FakeDelayedWallet, diff --git a/tests/unit/database/test_SQLiteStorage.py b/tests/unit/database/test_SQLiteStorage.py index 07063aa7f..8f4d42703 100644 --- a/tests/unit/database/test_SQLiteStorage.py +++ b/tests/unit/database/test_SQLiteStorage.py @@ -81,7 +81,7 @@ class StorageTest(AsyncioTestCase): await self.storage.close() async def store_fake_blob(self, blob_hash, length=100): - await self.storage.add_blobs((blob_hash, length), finished=True) + await self.storage.add_blobs((blob_hash, length, 0, 0), finished=True) async def store_fake_stream(self, stream_hash, blobs=None, file_name="fake_file", key="DEADBEEF"): blobs = blobs or [BlobInfo(1, 100, "DEADBEEF", random_lbry_hash())] diff --git a/tests/unit/lbrynet_daemon/test_allowed_origin.py b/tests/unit/lbrynet_daemon/test_allowed_origin.py index e9fc7c247..6316db0a0 100644 --- a/tests/unit/lbrynet_daemon/test_allowed_origin.py +++ b/tests/unit/lbrynet_daemon/test_allowed_origin.py @@ -8,7 +8,7 @@ from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras.daemon.security import is_request_allowed as allowed, ensure_request_allowed as ensure from lbry.extras.daemon.components import ( - DATABASE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, + DATABASE_COMPONENT, DISK_SPACE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT, LIBTORRENT_COMPONENT @@ -69,7 +69,7 @@ class TestAccessHeaders(AsyncioTestCase): conf.share_usage_data = False conf.api = 'localhost:5299' conf.components_to_skip = ( - DATABASE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, + DATABASE_COMPONENT, DISK_SPACE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT, LIBTORRENT_COMPONENT