'Test export of last option, JSON'

def testExportOptionsLastOptJSON(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    options = dict(self.records)
    db = current.db
    table = db.fotest_lookup_table
    last = db((table.id > 0)).select(limitby=(0, 1), orderby=(~ table.id)).first()
    self.assertNotEqual(last, None)
    resource = current.s3db.resource('fotest_table')
    result = resource.export_options(fields=['lookup'], only_last=True, as_json=True)
    fo = json.loads(result)
    assertTrue(isinstance(fo, dict))
    assertTrue(('option' in fo))
    assertTrue(isinstance(fo['option'], list))
    assertEqual(len(fo['option']), 1)
    opt = fo['option'][0]
    value = opt['@value']
    assertEqual(options[value]['uuid'], last.uuid)
    assertEqual(opt['$'], options[value]['name'])
