'Test deletion of link table entry'

def testLinkDeletion(self):

    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    db = current.db
    resource = current.s3db.resource('link_master')
    query = (FS('component.id') == self.component1)
    resource.add_filter(query)
    link = resource.links['link']
    rfield = link.resolve_selector('component.id')
    msg = 'Link    table    could    not    resolve    component    field    selector'
    assertNotEqual(rfield.field, None, msg=msg)
    assertEqual(rfield.colname, 'link_component.id', msg=msg)
    result = link.delete()
    assertEqual(result, 1)
    table = db.link_link
    row = db(((table.component_id == self.component1) & (table.deleted != True))).select(table.id, limitby=(0, 1)).first()
    assertEqual(row, None, msg='Link    not    deleted')
    row = db(((table.component_id == self.component2) & (table.deleted != True))).select(table.id, limitby=(0, 1)).first()
    assertNotEqual(row, None, msg='Unrelated    link    deleted')
    table = db.link_component
    row = db(((table.id == self.component1) & (table.deleted != True))).select(table.id, limitby=(0, 1)).first()
    assertNotEqual(row, None, msg='Component    record    deleted    instead    of    just    unlinking    it')
    row = db(((table.id == self.component2) & (table.deleted != True))).select(table.id, limitby=(0, 1)).first()
    assertNotEqual(row, None, msg='Unrelated    component    record    deleted')
