From ae76d369f28ff0a91d1a5b76176b4aa1093252ff Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 22 Jul 2019 11:06:19 +0300 Subject: [PATCH] A test for API command 'shutdown' --- src/tests/test_api.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 2bb6d0ce..dfe1b273 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -4,31 +4,48 @@ Tests using API. import base64 import json +import time import xmlrpclib # nosec -from time import sleep -from test_process import TestProcessProto +from test_process import TestProcessProto, TestProcessShutdown -class TestAPI(TestProcessProto): - """A test case for API""" +class TestAPIProto(TestProcessProto): + """Test case logic for testing API""" _process_cmd = ['pybitmessage', '-t'] - _seed = base64.encodestring( - 'TIGER, tiger, burning bright. In the forests of the night' - ) @classmethod def setUpClass(cls): """Setup XMLRPC proxy for pybitmessage API""" - super(TestAPI, cls).setUpClass() + super(TestAPIProto, cls).setUpClass() cls.addresses = [] cls.api = xmlrpclib.ServerProxy( "http://username:password@127.0.0.1:8442/") - for _ in range(0, 5): + for _ in range(5): if cls._get_readline('.api_started'): - print('API start detected!') return - sleep(1) + time.sleep(1) + + +class TestAPIShutdown(TestAPIProto, TestProcessShutdown): + """Separate test case for API command 'shutdown'""" + def test_shutdown(self): + """Shutdown the pybitmessage""" + self.assertEquals(self.api.shutdown(), 'done') + for _ in range(5): + if not self.process.is_running(): + break + time.sleep(2) + else: + self.fail( + '%s has not stopped in 10 sec' % ' '.join(self._process_cmd)) + + +class TestAPI(TestAPIProto): + """Main API test case""" + _seed = base64.encodestring( + 'TIGER, tiger, burning bright. In the forests of the night' + ) def _add_random_address(self, label): return self.api.createRandomAddress(base64.encodestring(label))