'Test setting dynamic defaults with xml_post_parse'

def testDynamicDefaults(self):

    xmlstr = '\n<s3xml>\n                <resource    name="pr_person">\n                                <data    field="first_name">Test</data>\n                                <data    field="last_name">PostParseAdd1</data>\n                </resource>\n                <resource    name="pr_person">\n                                <data    field="first_name">Test</data>\n                                <data    field="last_name">PostParseAdd2</data>\n                                <data    field="gender"    value="3"/>\n                </resource>\n</s3xml>'
    from lxml import etree
    tree = etree.ElementTree(etree.fromstring(xmlstr))
    resource = current.s3db.resource('pr_person')
    def xml_post_parse(elem, record):
        record['_gender'] = 2
    resource.configure(xml_post_parse=xml_post_parse)
    resource.import_xml(tree)
    db = current.db
    table = resource.table
    query = ((table.first_name == 'Test') & (table.last_name == 'PostParseAdd1'))
    row = db(query).select(table.id, table.gender).first()
    self.assertNotEqual(row, None)
    self.assertEqual(row.gender, 2)
    query = ((table.first_name == 'Test') & (table.last_name == 'PostParseAdd2'))
    row = db(query).select(table.id, table.gender).first()
    self.assertNotEqual(row, None)
    self.assertEqual(row.gender, 3)
