async def units_put(request: web.Request) -> web.Response: """ --- summary: Set base units tags: - Spark - Codec operationId: controller.spark.codec.units.put produces: - application/json parameters: - in: body name: body description: unit systme required: true schema: type: object properties: Temp: type: string example: degC Time: type: string example: second """ args = await request.json() return web.json_response( codec.get_codec(request.app).update_unit_config(args))
async def units_get(request: web.Request) -> web.Response: """ --- summary: Get current unit configuration tags: - Spark - Codec operationId: controller.spark.codec.units.get produces: - application/json """ return web.json_response(codec.get_codec(request.app).get_unit_config())
async def unit_alternatives_get(request: web.Request) -> web.Response: """ --- summary: Get alternative values for each unit type tags: - Spark - Codec operationId: controller.spark.codec.units_alternatives.get produces: - application/json """ return web.json_response( codec.get_codec(request.app).get_unit_alternatives())
async def test_transcoding(app, client, cmder, store, ctrl, mocker): c = codec.get_codec(app) obj_type, obj_data = generate_obj() enc_type, enc_data = await c.encode(obj_type, obj_data) object_args = { OBJECT_SID_KEY: 'alias', GROUP_LIST_KEY: [1], OBJECT_TYPE_KEY: obj_type, OBJECT_DATA_KEY: obj_data } store['alias', 300] = dict() encode_spy = mocker.spy(c, 'encode') decode_spy = mocker.spy(c, 'decode') retval = await ctrl.create_object(object_args) assert retval[OBJECT_DATA_KEY]['settings']['address'] == 'ff'.rjust( 16, '0') encode_spy.assert_any_call(obj_type, obj_data, None) decode_spy.assert_any_call(enc_type, enc_data, None)
def cdc(app) -> codec.Codec: return codec.get_codec(app)
def __init__(self, app: web.Application): self._app = app self._datastore = datastore.get_datastore(app) self._codec = codec.get_codec(app)