def test_url_attribute_default(self): """ Test of the default case for "__main__.py" target server (without "--url" positional attribute). Might be just like the value in environment variable "MEATADISKSERVER" """ host, port = 'localhost', 5467 os.putenv('MEATADISKSERVER', 'http://{}:{}'.format(host, port)) server = ThreadedTCPServer((host, port), MyRequestHandler) server_thread = threading.Thread(target=server.serve_forever) server_thread.daemon = True server_thread.start() # Hiding of the server running logging. Excise next string if test is # failing to look at the errors of local server. sys.stderr = StringIO() with os.popen( '{} __main__.py info --url http://{}:{}'.format( self.metadisk_python_interpreter, host, port) ) as file_: info_response_status = file_.read()[:3] sys.stderr.close() sys.stderr = sys.__stderr__ # Turn back the error stream output. self.assertEqual( info_response_status, '200', 'the "response status" must be 200, like in this test-case' 'local server specified at the "MEATADISKSERVER" env. variable!' ) server.shutdown() server.server_close()
def test_url_attribute_use(self): """ Test of the "--url" optional argument. The "__main__.py" must use this value like url of all responses. """ host, port = 'localhost', 5467 server = ThreadedTCPServer((host, port), MyRequestHandler) server_thread = threading.Thread(target=server.serve_forever) server_thread.daemon = True server_thread.start() # Hiding of the server running logging. Excise next string if test is # failing to look at the errors of local server. sys.stderr = StringIO() with os.popen( '{} __main__.py info --url http://{}:{}'.format( self.metadisk_python_interpreter, host, port) ) as file_: info_response_status = file_.read()[:3] sys.stderr.close() sys.stderr = sys.__stderr__ # Turn back the error stream output. self.assertEqual( info_response_status, '200', 'the "response status" must be 200, like from this test-case local' ' server specified after "--url" optional argument!' ) server.shutdown() server.server_close()