def test_update_components_several_components(self, table_with_several_components): tables.update_components('table1', [ {'component1': {'value1': 300}}, {'component2': {'value1': 300}}, {'component3': {'value1': 300}}, ]) assert tables.get('table1')['components']['component1'] == {'value1': 300, 'value2': 20} assert tables.get('table1')['components']['component2'] == {'value1': 300, 'value2': 120} assert tables.get('table1')['components']['component3'] == {'value1': 300, 'value2': 220}
def handle_come_by_table(json): if 'DEBUG_HANDLER_WAIT' in current_app.config: from time import sleep sleep(float(current_app.config['DEBUG_HANDLER_WAIT'])) current_app.logger.info(f'come by table') current_app.logger.debug(f'come by table: {json}') table = tables.get(json["tablename"]) if not table: table = tables.create(json["tablename"], None) join_room(json["tablename"]) table = tables.get(json["tablename"]) emit("load table", table)
def test_create_new_table(self): tables.create('table1', '0') table = tables.get('table1') assert table assert table['components'] == {} assert table['kits'] == [] assert table['players'] == {}
def test_update_components_only_specified_value(self, simple_table): tables.store('table1', { 'components': { 'component1': {'value1': 100, 'value2': 200}, }, 'kits': [], 'players': {}, }) tables.update_components('table1', [{'component1': {'value1': 11}}]) assert tables.get('table1')['components']['component1'] == {'value1': 11, 'value2': 200}
def handle_sync_with_me(json): current_app.logger.info(f'sync with me') current_app.logger.debug(f'sync with me: {json}') tables.store(json['tablename'], json['tableData']) table = tables.get(json["tablename"]) emit("refresh table", { "tablename": json["tablename"], "table": table }, broadcast=True, room=json["tablename"])
def handle_remove_kit(json): current_app.logger.info(f'remove kit') current_app.logger.debug(f'remove kit: {json}') table = tables.get(json["tablename"]) remove_kit(json, table) tables.update_table(json["tablename"], table) emit("refresh table", { "tablename": json["tablename"], "table": table }, broadcast=True, room=json["tablename"])
def test_store_to_create_new(self): table = { 'components': { 'component1': {'value1': 10, 'value2': 20}, }, 'kits': [], 'players': {}, } tables.store('table1', table) read = tables.get('table1') assert read['components']['component1'] == {'value1': 10, 'value2': 20}
def handle_set_player(json): current_app.logger.info(f'set player') current_app.logger.debug(f'set player: {json}') table = tables.get(json["tablename"]) if not table: current_app.logger.error(f"table {json['tablename']} on set player") raise RuntimeError('table does not exist') player_name = json['player']['name'] table["players"][player_name] = { "name": player_name, "isHost": json['player']['isHost'], } tables.store(json["tablename"], table) emit("confirmed player name", {"player": {"name": player_name}})
def handle_add_component(json): current_app.logger.info( f'add component: {json["component"]["componentId"]} {json["component"]["name"]}' ) current_app.logger.debug(f'add component: {json}') table = tables.get(json["tablename"]) add_component(json, table) tables.update_table(json["tablename"], table) emit("add component", { "tablename": json["tablename"], "component": json["component"] }, broadcast=True, room=json["tablename"]) current_app.logger.info(f'add component end')
def handle_update_single_component(json): trace = debug_tools.resume_trace(json) trace.trace_point('handle update single component') current_app.logger.debug(f'update single component: {json}') current_app.logger.info(f'update single component') table = tables.get(json["tablename"]) update_single_component(json, table) trace.trace_point('before update_table') tables.update_table(json["tablename"], table) trace.trace_point('after update_table') emit("update single component", json, broadcast=True, room=json["tablename"]) trace.trace_point('emitted response') trace.end() current_app.logger.info(f'update single component end')
def export_table(): tablename = request.args.get("tablename") app.logger.info(f"exporting table <{tablename}>") table = tables.get(tablename) return jsonify(table)
def test_update_components_basic(self, simple_table): tables.update_components('table1', [{'component1': {'value1': 100}}]) assert tables.get('table1')['components']['component1'] == {'value1': 100, 'value2': 20}
def test_update(self, simple_table): simple_table['components']['component1']['value1'] = 100 tables.update_table('table1', simple_table) assert tables.get('table1')['components']['component1'] == {'value1': 100, 'value2': 20}