def test_pose(tmp_engine): url, engine = tmp_engine saver = Saver(url) data = { 'snapshot_id': 1, 'translation': [2, 3, 4], 'rotation': [5, 6, 7, 8] } expected = { 'snapshot_id': 1, 'translation_x': 2, 'translation_y': 3, 'translation_z': 4, 'rotation_x': 5, 'rotation_y': 6, 'rotation_z': 7, 'rotation_w': 8, } json_data = json.dumps(data) saver.save('pose', json_data) query = 'SELECT * FROM pose' with engine.connect() as conn: for row in conn.execute(query): assert dict(row) == expected
def test_feelings(tmp_engine): url, engine = tmp_engine saver = Saver(url) data = {'snapshot_id': 1, 'user_id': 5, 'datetime': 'hello'} json_data = json.dumps(data) saver.save('snapshot_meta', json_data) query = 'SELECT * FROM snapshots' with engine.connect() as conn: for row in conn.execute(query): assert dict(row) == data
def test_depth_image(tmp_engine): url, engine = tmp_engine saver = Saver(url) data = {'snapshot_id': 1, 'path': '/hello/world'} json_data = json.dumps(data) saver.save('depth_image', json_data) query = 'SELECT * FROM depth_image' with engine.connect() as conn: for row in conn.execute(query): assert dict(row) == data
def test_user(tmp_engine): url, engine = tmp_engine saver = Saver(url) data = { 'user_id': 1, 'username': '******', 'gender': 0, 'birthday': 12345678 } json_data = json.dumps(data) saver.save('user', json_data) query = 'SELECT * FROM users' with engine.connect() as conn: for row in conn.execute(query): assert dict(row) == data
def test_feelings(tmp_engine): url, engine = tmp_engine saver = Saver(url) data = { 'snapshot_id': 1, 'hunger': 5, 'thirst': 6, 'exhaustion': 7, 'happiness': 8 } json_data = json.dumps(data) saver.save('feelings', json_data) query = 'SELECT * FROM feelings' with engine.connect() as conn: for row in conn.execute(query): assert dict(row) == data
def consume_callback(context, ch, method, properties, body, *args, **kwargs): database = kwargs['database_url'] saver = Saver(database) topic = method.routing_key.split('.')[0] saver.save(topic, body)
def save(database, topic, path): with open(path) as f: data = f.read() saver = Saver(database) saver.save(topic, data)