'Test Foreign Key Representation in list:reference types'

def testListReference(self):

    r = S3Represent(lookup='org_organisation', multiple=True, show_link=True)
    a = current.request.application
    result = r(self.id1)
    self.assertTrue(isinstance(result, DIV))
    self.assertEqual(len(result), 1)
    self.assertTrue(isinstance(result[0], A))
    self.assertEqual(result[0].attributes['_href'], ('/%s/org/organisation/%s' % (a, self.id1)))
    self.assertEqual(result[0].components[0], 'Represent    Test    Organisation1')
    result = r(self.id1, show_link=False)
    self.assertEqual(result, self.name1)
    result = r([self.id1, self.id2], show_link=False).split(',    ')
    self.assertEqual(len(result), 2)
    self.assertTrue((self.name1 in result))
    self.assertTrue((self.name2 in result))
    values = [[self.id1, self.id2], [self.id2], [None, self.id1]]
    result = r.multiple(values, show_link=False).split(',    ')
    self.assertEqual(len(result), 3)
    self.assertTrue((self.name1 in result))
    self.assertTrue((self.name2 in result))
    self.assertTrue((current.messages.NONE in result))
    result = r.bulk(values, show_link=False)
    self.assertTrue(isinstance(result, dict))
    self.assertEqual(len(result), 3)
    self.assertEqual(result[self.id1], self.name1)
    self.assertEqual(result[self.id2], self.name2)
    self.assertTrue((None in result))
    repr1 = r.render_list(values[0], result, show_link=False)
    self.assertEqual(repr1, ',    '.join([self.name1, self.name2]))
    repr2 = r.render_list(values[1], result, show_link=False)
    self.assertEqual(repr2, self.name2)
    result = r.bulk(values)
    repr1 = r.render_list(values[0], result)
    self.assertTrue(isinstance(repr1, DIV))
    self.assertEqual(len(repr1), 3)
    self.assertTrue(isinstance(repr1[0], A))
    self.assertEqual(repr1[0].attributes['_href'], ('/%s/org/organisation/%s' % (a, self.id1)))
    self.assertEqual(repr1[0].components[0], 'Represent    Test    Organisation1')
    self.assertEqual(repr1[1], ',    ')
    self.assertTrue(isinstance(repr1[2], A))
    self.assertEqual(repr1[2].attributes['_href'], ('/%s/org/organisation/%s' % (a, self.id2)))
    self.assertEqual(repr1[2].components[0], 'Represent    Test    Organisation2')
    repr2 = r.render_list(values[2], result)
    self.assertTrue(isinstance(repr2, DIV))
    self.assertEqual(len(repr2), 3)
    self.assertEqual(str(repr2[0]), str(current.messages.NONE))
    self.assertEqual(r(None, show_link=False), str(current.messages.NONE))
    self.assertEqual(r([]), str(current.messages.NONE))
    self.assertEqual(r.multiple([None], show_link=False), str(current.messages.NONE))
    self.assertEqual(r.multiple([[]], show_link=False), str(current.messages.NONE))
    self.assertEqual(r.queries, 2)
