lbry-sdk/tests/integration/other/test_cli.py

48 lines
2 KiB
Python
Raw Normal View History

import contextlib
import os
import tempfile
from io import StringIO
2019-12-31 21:30:13 +01:00
from lbry.testcase import AsyncioTestCase
from lbry.conf import Config
from lbry.extras import cli
from lbry.extras.daemon.components import (
2021-09-20 03:38:09 +02:00
DATABASE_COMPONENT, DISK_SPACE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT,
HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT,
2021-01-17 21:53:13 +01:00
UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT,
2021-10-15 09:14:35 +02:00
LIBTORRENT_COMPONENT, BACKGROUND_DOWNLOADER_COMPONENT
2019-01-24 00:04:16 +01:00
)
from lbry.extras.daemon.daemon import Daemon
2018-12-13 04:32:44 +01:00
class CLIIntegrationTest(AsyncioTestCase):
2018-12-13 04:32:44 +01:00
async def asyncSetUp(self):
2019-01-22 05:28:26 +01:00
conf = Config()
conf.data_dir = '/tmp'
conf.share_usage_data = False
conf.api = 'localhost:5299'
2019-01-24 00:04:16 +01:00
conf.components_to_skip = (
2021-09-20 03:38:09 +02:00
DATABASE_COMPONENT, DISK_SPACE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT,
HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT,
2021-01-17 21:53:13 +01:00
UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT,
2021-10-15 09:14:35 +02:00
LIBTORRENT_COMPONENT, BACKGROUND_DOWNLOADER_COMPONENT
2019-01-24 00:04:16 +01:00
)
Daemon.component_attributes = {}
2019-01-22 05:28:26 +01:00
self.daemon = Daemon(conf)
await self.daemon.start()
self.addCleanup(self.daemon.stop)
def test_cli_status_command_with_auth(self):
actual_output = StringIO()
with contextlib.redirect_stdout(actual_output):
cli.main(["--api", "localhost:5299", "status"])
actual_output = actual_output.getvalue()
2021-02-17 18:47:56 +01:00
self.assertIn("is_running", actual_output)
def test_when_download_dir_non_writable_on_start_then_daemon_dies_with_helpful_msg(self):
with tempfile.TemporaryDirectory() as download_dir:
os.chmod(download_dir, mode=0o555) # makes download dir non-writable, readable and executable
with self.assertRaisesRegex(PermissionError, f"The following directory is not writable: {download_dir}"):
cli.main(["start", "--download-dir", download_dir])