def test_transform_fun(site): results = list(site.view('things', { 'doubleid': func.addition('id', 'id'), 'id_plus_one': func.addition('id', func.constant(1)), 'squaredid': func.product('id', 'id'), 'one': func.division('id', 'id'), 'one_alternative': func.constant(1), 'test': func.constant('test'), 'zero': func.substraction('id', 'id'), 'name': 'name', 'UPPER': func.upper('name'), 'lower': func.lower('name'), 'split': func.split('name', 'a'), 'id': 'id' })) eq_(len(results), 3) assert all([x['doubleid'] == 2 * x['id'] for x in results]) assert all([x['squaredid'] == x['id'] * x['id'] for x in results]) assert all([x['one'] == 1 for x in results]) assert all([x['one_alternative'] == 1 for x in results]) assert all([x['zero'] == 0 for x in results]) assert all([x['UPPER'] == x['name'].upper() for x in results]) assert all([x['lower'] == x['name'].lower() for x in results]) assert all([x['test'] == 'test' for x in results]) assert all([x['id_plus_one'] == x['id'] + 1 for x in results]) assert all([x['split'] == x['name'].split('a') for x in results])
def test_transform(site): """Test that simple transform function work""" mapping = {"fname": func.slice("first_aps.name", [2,4])} results = list(site.view("second_ap", aliases=mapping)) eq_(len(results), 4) assert all((len(res['fname']) == 2 for res in results)) results = list(site.view("first_ap", request={"id": 4}, aliases={"second_ap_name": func.coalesce("second_ap.name", "(Empty)"), 'round': func.round(func.constant(0.9))})) eq_(len(results), 1) eq_(results[0]['second_ap_name'], '(Empty)') eq_(results[0]['round'], 1)