2018-08-10 12:36:05 +02:00
|
|
|
import contextlib
|
|
|
|
from io import StringIO
|
2018-12-15 21:31:36 +01:00
|
|
|
from unittest import skip
|
2018-12-13 04:32:44 +01:00
|
|
|
from torba.testcase import AsyncioTestCase
|
2018-08-10 12:36:05 +02:00
|
|
|
|
2018-10-30 18:41:38 +01:00
|
|
|
from lbrynet import conf
|
2018-11-07 21:15:05 +01:00
|
|
|
from lbrynet.extras import cli
|
2018-11-04 19:44:17 +01:00
|
|
|
from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, \
|
2018-10-30 18:41:38 +01:00
|
|
|
DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, \
|
2018-08-10 12:36:05 +02:00
|
|
|
PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, \
|
|
|
|
RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT
|
2018-11-04 19:44:17 +01:00
|
|
|
from lbrynet.extras.daemon.Daemon import Daemon
|
2018-08-10 12:36:05 +02:00
|
|
|
|
|
|
|
|
2018-08-17 22:07:57 +02:00
|
|
|
class FakeAnalytics:
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_started(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def send_server_startup_success(self):
|
|
|
|
pass
|
|
|
|
|
2018-09-21 22:32:02 +02:00
|
|
|
def send_server_startup(self):
|
|
|
|
pass
|
|
|
|
|
2018-08-17 22:07:57 +02:00
|
|
|
def shutdown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2018-12-13 04:32:44 +01:00
|
|
|
class CLIIntegrationTest(AsyncioTestCase):
|
2018-08-16 18:13:54 +02:00
|
|
|
USE_AUTH = False
|
|
|
|
|
2018-12-13 04:32:44 +01:00
|
|
|
async def asyncSetUp(self):
|
2018-08-10 12:36:05 +02:00
|
|
|
skip = [
|
|
|
|
DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT,
|
2018-10-30 18:41:38 +01:00
|
|
|
DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT,
|
2018-08-10 12:36:05 +02:00
|
|
|
PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT,
|
|
|
|
RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT
|
|
|
|
]
|
|
|
|
conf.initialize_settings(load_conf_file=False)
|
2018-10-17 03:28:47 +02:00
|
|
|
conf.settings['api_port'] = 5299
|
2018-08-16 18:13:54 +02:00
|
|
|
conf.settings['use_auth_http'] = self.USE_AUTH
|
2018-10-17 03:28:47 +02:00
|
|
|
conf.settings['components_to_skip'] = skip
|
2018-08-10 12:36:05 +02:00
|
|
|
conf.settings.initialize_post_conf_load()
|
|
|
|
Daemon.component_attributes = {}
|
2018-08-17 22:07:57 +02:00
|
|
|
self.daemon = Daemon(analytics_manager=FakeAnalytics())
|
2018-12-13 04:32:44 +01:00
|
|
|
await self.daemon.start_listening()
|
2018-08-04 23:19:10 +02:00
|
|
|
|
2018-12-13 04:32:44 +01:00
|
|
|
async def asyncTearDown(self):
|
|
|
|
await self.daemon.shutdown()
|
2018-08-16 18:13:54 +02:00
|
|
|
|
|
|
|
|
2018-12-15 21:31:36 +01:00
|
|
|
@skip
|
2018-08-16 18:13:54 +02:00
|
|
|
class AuthenticatedCLITest(CLIIntegrationTest):
|
|
|
|
USE_AUTH = True
|
|
|
|
|
2018-08-10 12:36:05 +02:00
|
|
|
def test_cli_status_command_with_auth(self):
|
2018-08-15 03:58:18 +02:00
|
|
|
self.assertTrue(self.daemon._use_authentication)
|
2018-08-10 12:36:05 +02:00
|
|
|
actual_output = StringIO()
|
|
|
|
with contextlib.redirect_stdout(actual_output):
|
|
|
|
cli.main(["status"])
|
|
|
|
actual_output = actual_output.getvalue()
|
|
|
|
self.assertIn("connection_status", actual_output)
|
2018-08-04 23:19:10 +02:00
|
|
|
|
2018-08-15 10:26:07 +02:00
|
|
|
|
2018-08-16 18:13:54 +02:00
|
|
|
class UnauthenticatedCLITest(CLIIntegrationTest):
|
|
|
|
USE_AUTH = False
|
2018-08-15 10:26:07 +02:00
|
|
|
|
|
|
|
def test_cli_status_command_with_auth(self):
|
2018-08-15 14:54:44 +02:00
|
|
|
self.assertFalse(self.daemon._use_authentication)
|
2018-08-15 10:26:07 +02:00
|
|
|
actual_output = StringIO()
|
|
|
|
with contextlib.redirect_stdout(actual_output):
|
|
|
|
cli.main(["status"])
|
|
|
|
actual_output = actual_output.getvalue()
|
|
|
|
self.assertIn("connection_status", actual_output)
|