'Verify correct resolution of link table selectors'

def testLinkTableSelectorResolution(self):

    s3db = current.s3db
    resource = s3db.resource('test_master')
    assertIn = self.assertIn
    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    rfield = resource.resolve_selector('parent__link.parent')
    assertEqual(rfield.tname, 'test_link')
    assertEqual(rfield.fname, 'parent')
    joins = rfield.left.get('test_link')
    assertNotEqual(joins, None)
    actual = [str(j) for j in joins]
    expected = ('test_link    ON    (test_master.id    =    test_link.child)', 'test_master    AS    test_parent_master    ON    (test_link.parent    =    test_parent_master.id)')
    for expression in expected:
        assertIn(expression, actual)
    rfield = resource.resolve_selector('child__link.child')
    assertEqual(rfield.tname, 'test_link')
    assertEqual(rfield.fname, 'child')
    joins = rfield.left.get('test_link')
    assertNotEqual(joins, None)
    actual = [str(j) for j in joins]
    expected = ('test_link    ON    (test_master.id    =    test_link.parent)', 'test_master    AS    test_child_master    ON    (test_link.child    =    test_child_master.id)')
    for expression in expected:
        assertIn(expression, actual)
    rfield = resource.resolve_selector('link.parent')
    assertEqual(rfield.tname, 'test_link')
    assertEqual(rfield.fname, 'parent')
