From 8c6c442fdd52c8e6f49a30522ade9a85ff473732 Mon Sep 17 00:00:00 2001 From: hackrush Date: Wed, 15 Aug 2018 13:56:07 +0530 Subject: [PATCH] Fixed regression in unauthenticated API client w/ integration tests --- lbrynet/cli.py | 4 +++- tests/integration/cli/test_cli.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lbrynet/cli.py b/lbrynet/cli.py index 86afe55f6..2a7feabe7 100644 --- a/lbrynet/cli.py +++ b/lbrynet/cli.py @@ -25,8 +25,10 @@ async def execute_command(method, params, conf_path=None): # this actually executes the method try: resp = await api.call(method, params) - if not api.session.closed: + try: await api.session.close() + except AttributeError: + pass print(json.dumps(resp["result"], indent=2)) except KeyError: if resp["error"]["code"] == -32500: diff --git a/tests/integration/cli/test_cli.py b/tests/integration/cli/test_cli.py index c2e7e1e0b..f9ffd107f 100644 --- a/tests/integration/cli/test_cli.py +++ b/tests/integration/cli/test_cli.py @@ -40,3 +40,32 @@ class AuthCLIIntegrationTest(unittest.TestCase): @defer.inlineCallbacks def tearDown(self): yield self.daemon._shutdown() + + +class UnAuthCLIIntegrationTest(unittest.TestCase): + @defer.inlineCallbacks + def setUp(self): + skip = [ + DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, + DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, STREAM_IDENTIFIER_COMPONENT, FILE_MANAGER_COMPONENT, + 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) + conf.settings["components_to_skip"] = skip + conf.settings.initialize_post_conf_load() + Daemon.component_attributes = {} + self.daemon = Daemon() + yield self.daemon.start_listening() + + def test_cli_status_command_with_auth(self): + self.assertTrue(self.daemon._use_authentication) + actual_output = StringIO() + with contextlib.redirect_stdout(actual_output): + cli.main(["status"]) + actual_output = actual_output.getvalue() + self.assertIn("connection_status", actual_output) + + @defer.inlineCallbacks + def tearDown(self): + yield self.daemon._shutdown()