

def gen_fixture(user, indicator_set):
    '\n    Generate the fixture from the indicator data.\n\n    :param user: The user.\n    :param indicator_set: A subclass of SqlIndicatorSet\n    '
    '\n    Example output:\n\n    indicator_set.name = \'demo\'\n    indicator_set.get_data() = {\'user_case1\': {\'indicator_a\': 1, \'indicator_b\': 2}}\n\n    <fixture id="indicators:demo" user_id="...">\n        <indicators>\n            <case id="user_case1">\n                <indicator_a>1</indicator_a>\n                <indicator_b>2</indicator_2>\n            </case>\n        </indicators>\n    </fixture>\n    '
    name = indicator_set.name
    data = indicator_set.get_data()
    fixture = ElementTree.Element('fixture', attrib={
        'id': ':'.join((IndicatorsFixturesProvider.id, name)),
        'user_id': user.user_id,
        'date': indicator_set.reference_date.isoformat(),
    })
    indicators_node = ElementTree.SubElement(fixture, 'indicators')
    for (case_id, indicators) in data.iteritems():
        group = ElementTree.SubElement(indicators_node, 'case', attrib={
            'id': case_id,
        })
        for (name, value) in indicators.items():
            indicator = ElementTree.SubElement(group, name)
            indicator.text = str(value)
    return fixture

dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/callcenter/fixturegenerators.py gen_fixture/original