def setup(self): config_server = '{"host":"abc", "port":1234, "authkey":"xyz", "user_id": "pqr", "login": "******", "timeout":123, "keepalive":456, "retry":789}' with patch("builtins.open", new_callable=mock_open, read_data=config_server): self.__class__.config_server = config_server_obj() self.__class__.middleware = middleware_obj(self.config_server)
def test__check_config(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj("tmp_server_name_cfg") assert some_config._check_config() == None # Port is int test_json_error_port = '{"host":"abc", "port":"1234", "authkey":"xyz", "timeout":"123", "keepalive":"456", "retry":"789"}' with patch("builtins.open", new_callable=mock_open, read_data=test_json_error_port): with pytest.raises(AttributeError) as ctx: config_server_obj('tmp_server_name_cfg2') assert ctx.errisinstance( AttributeError) and 'port' in ctx.exconly().lower() # Timeout is int test_json_error_timeout = '{"host":"abc", "port":1234, "authkey":"xyz", "timeout":"123", "keepalive":456, "retry":789}' with patch("builtins.open", new_callable=mock_open, read_data=test_json_error_timeout): with pytest.raises(AttributeError) as ctx: config_server_obj('tmp_server_name_cfg3') assert ctx.errisinstance( AttributeError) and 'timeout' in ctx.exconly().lower() # Keepalive is int test_json_error_keepalive = '{"host":"abc", "port":1234, "authkey":"xyz", "timeout":123, "keepalive":"456", "retry":789}' with patch("builtins.open", new_callable=mock_open, read_data=test_json_error_keepalive): with pytest.raises(AttributeError) as ctx: config_server_obj('tmp_server_name_cfg4') assert ctx.errisinstance( AttributeError) and 'keepalive' in ctx.exconly().lower() # retry is int test_json_error_retry = '{"host":"abc", "port":1234, "authkey":"xyz", "timeout":123, "keepalive":456, "retry":"789"}' with patch("builtins.open", new_callable=mock_open, read_data=test_json_error_retry): with pytest.raises(AttributeError) as ctx: config_server_obj('tmp_server_name_cfg5') assert ctx.errisinstance( AttributeError) and 'retry' in ctx.exconly().lower()
def test_base(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj("tmp_server_name_base") assert some_config.config == self.EXPECTED assert some_config.get_config_dict() == self.EXPECTED assert some_config.host() == 'abc' assert some_config.port() == 1234 assert some_config.authkey() == 'xyz' assert some_config.timeout() == 123 assert some_config.keepalive() == 456 assert some_config.retry() == 789 assert some_config.server_name == 'tmp_server_name_base'
def setup(self): with patch("via_common.multiprocess.logger_manager.LoggerManager._check_or_create_directory"): LoggerManager().__del__() config_logger = config_logger_obj(config_logger='{"root":{"version":1}, "subprocess":{}}') LoggerManager.init_root_logger(config_logger) config_conn = {"host": "127.0.0.1", "port": 41567, "authkey": "abc"} # We need a proper config otherwise cannot be pickled self.__class__.config_internal_conn = ConfigServerPure(config_conn, 'test') config_server = '{"host":"127.0.0.1", "port":12346, "authkey":"xyz", "user_id": "pqr", "login": "******", "timeout":123, "keepalive":456, "retry":789}' with patch("builtins.open", new_callable=mock_open, read_data=config_server): self.__class__.config_server = config_server_obj() self.__class__.middleware = middleware_obj(self.config_server) self.__class__.queue_manager = QueueManager(self.config_internal_conn) self.__class__.backgroundthread = backgroundthread_obj(self.config_internal_conn, self.middleware) yield "teardown" LoggerManager().__del__()
def setup(self): with patch( "via_common.multiprocess.logger_manager.LoggerManager._check_or_create_directory" ): # with patch("via_common.multiprocess.logger_manager.LoggerManager.config_logger", lambda: '{"root":{"version":1}, "subprocess":{}}'): LoggerManager().__del__() config_logger = config_logger_obj( config_logger='{"root":{"version":1}, "subprocess":{}}') LoggerManager.init_root_logger(config_logger) # patching manually the LoggerManager to avoid some side effects that are NOT under the scope of what is tested here LoggerManager.logger_queue_listener = 'not none' config_server = '{"host":"abc", "port":1234, "authkey":"xyz", "user_id": "pqr", "login": "******", "timeout":123, "keepalive":456, "retry":789}' with patch("builtins.open", new_callable=mock_open, read_data=config_server): self.__class__.config_server = config_server_obj() config_logger = config_logger_obj( config_logger='{"root":{"version":1}, "subprocess":{}}') self.__class__.middleware = middleware_redis_obj( self.config_server, config_logger, 'queue') yield "teardown" LoggerManager().__del__()
def test_port(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj('tmp_server_name_cfg7') assert some_config.port() == 1234
def test_retry(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj('tmp_server_name_cfg13') assert some_config.retry() == 789
def test_keepalive(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj('tmp_server_name_cfg12') assert some_config.keepalive() == 456
def test_user_id(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj("tmp_server_name_cfg10") assert some_config.user_id() == 'pqr'
def test_authkey(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj("tmp_server_name_cfg9") assert some_config.authkey() == 'xyz'
def test_login(self): with patch("builtins.open", new_callable=mock_open, read_data=self.test_json): some_config = config_server_obj('tmp_server_name_cfg8') assert some_config.login() == 'uvw'