예제 #1
0
 def test_L_wrong_file01(self, tmpdir: py.path.local) -> None:
     "A loggingconfig file containing a list should raise an error"
     fname = str(tmpdir.join('/bla.yaml'))
     data = [1, 2, 3, 4]
     yamlutil.writeyamlfile(data, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_logging_config(fname)
예제 #2
0
 def test_L_wrong_file03(self, tmpdir: py.path.local) -> None:
     "A loggingconfig file containing a single dict should pass."
     fname = str(tmpdir.join('/bla.yaml'))
     data = dict(a=1, b=2, gg=77)
     yamlutil.writeyamlfile(data, fname)
     retval = serverconfig.read_logging_config(fname)
     assert retval == data, "failed to read back data"
예제 #3
0
파일: stocky.py 프로젝트: cfe-lab/stocky
    def __init__(self):
        super().__init__(__name__.split('.')[0])

    def app_protocol(self, unused) -> str:
        """This method is called by geventwebsocket (handler.py) in order to set the
        websocket protocol.
        The name of the method is significant (it must be called exactly this)
        The websocket protocol must be defined, or the server will not respond correctly
        (missing Sec-WebSocket-Protocol entry in the response header)
        and this will crash the stocky webclient when it is run under chrome.
        NOTE: the websocket protocol is hardcoded to be 'json' on the webclient side.
        """
        return 'json'


logging.config.dictConfig(serverconfig.read_logging_config('logging.yaml'))
app: typing.Optional[StockyApp] = StockyApp()
socky: typing.Optional[Sockets] = Sockets(app)
THE_MAIN: typing.Optional[stockyserver.CommonStockyServer] = None


def init_db_server(cfgname: str) -> flask.Flask:
    """This routine is used as a helper in order to launch the StockyServer class with the
    name of a configuration file, e.g. in a launching shell script, such as runserver.sh,
    we would write something like:
    gunicorn -k flask_sockets.worker "stocky:init_db_server('scoconfig.yaml')" --bind 0.0.0.0:5000
    """
    print("hello from init_DBserver")
    global THE_MAIN
    # test_logging(app.logger)
    THE_MAIN = stockyserver.StockyDBServer(app.logger, cfgname)
예제 #4
0
 def test_L_missing_file(self) -> None:
     "A missing loggingconfig file should raise an error"
     with pytest.raises(RuntimeError):
         serverconfig.read_logging_config(
             get_testfilename('test0.not_there.yaml'))